javascript - How to test an Ember model's computed property that has relations dependencies? -


i'm writing qunit tests test ember model, having hard time testing computed properties have relation dependency (the computed property triggers model's computed property).

the model testing (coffeescript):

customer = ds.model.extend   firstname:      ds.attr('string')   lastname:       ds.attr('string')   phones:         ds.attr('embedded-list') phone: (->     @get('phones.firstobject.number')   ).property('phones.firstobject.number')  fullname: (->     [@get('lastname'), @get('firstname')].join(' ') )   ).property('firstname','lastname') 

the meeting model:

meeting = ds.model.extend   customers: ds.hasmany('customer')    startat:   ds.attr('isodate')   status:    ds.attr()   objective: ds.attr()   customerphones: (->     phones = []     @get('customers').foreach (c) ->       c.get('phones').foreach (ph) ->         phones.push(ph.number)     phones   ).property('customers.@each.phones')     firstcustomer: (->     @get('customers.firstobject')   ).property('customers.firstobject')   firstcustomerfullname: (->     @get('firstcustomer.fullname')   ).property('firstcustomer.fullname') 

now, testing customerphones, , firstcustomerfullname giving me real hard time...

my test looks follows:

`import { test, moduleformodel } 'ember-qunit';`  moduleformodel('meeting', 'app.meeting',{    needs: ['model:customer']    setup: ->      ember.run (t = @)->        ->         customer = t.store().createrecord 'customer', firstname: 'john', lastname: 'smith', phones:[]         customer.get('phones').addobject(ember.object.create({tag: 'home', number: '111222333'}))         customer.get('phones').addobject(ember.object.create({tag: 'work', number: '444555666'}))          t.subject().set('customers.content', ember.arrayproxy.create({content: []}));         t.subject().get('customers.content').pushobject(customer)      teardown: ->   },(container, context) ->       container.register 'store:main', ds.store       container.register 'adapter:application', ds.fixtureadapter       context.__setup_properties__.store = -> container.lookup('store:main') )  test "it's ds.model", -> ok(@subject())  test "attributes: can created valid values", ->   meeting = @subject({objective: 'follow up'})   ember.run ->     equal(meeting.get('objective', 'follow up'))   test "properties: firstcustomer & firstcustomerfullname & firstcustomerphone", ->   meeting = @subject()   ember.run ->     equal(meeting.get('firstcustomer.fullname'),  'smith john')     equal(meeting.get('firstcustomer.phone'),     '111222333') 

now, used techniques in test, found in answer here on stack overflow, can't seem find now.

that worked few days ago, (it seems nonsense know) whenever run test, errors:

assertion failed: cannot add 'meeting' records relationship (only 'meeting' allowed)

i don't know error is, nor how fix it. spent day monkeying around, no outcome.

how can resolve this?

okay, have far comment, i'm going wip answer.

  • i removed of run loops, necessary async processes.

  • i changed of computed properties computed.alias properties

i.e.

phone: (->   @get('phones.firstobject.number') ).property('phones.firstobject.number') 

to

phone: ember.computed.alias('phones.firstobject.number') 
  • i ripped out of setup, ember data eagerly loads store on own , use fixture ids etc without specifying it. (this part can put it, isn't necessary in context).

i.e.

  },(container, context) ->   container.register 'store:main', ds.store   container.register 'adapter:application', ds.fixtureadapter   context.__setup_properties__.store = -> container.lookup('store:main') 
  • and apologize in advance, i'm not fan of coffeescript, put in js. question is, if you're still seeing issues may need find out versions of ember, ed, , ember qunit using.

http://emberjs.jsbin.com/oxidivu/625/edit


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -