Ember モデルをテストするために Qunit テストを書いていますが、リレーションの依存関係 (計算されたプロパティが別のモデルの計算されたプロパティをトリガーする) を持つ計算されたプロパティをテストするのに苦労しています。
テスト中のモデル (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')
会議モデル:
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')
今、テストcustomerPhones
しfirstCustomerFullName
ていて、本当に苦労しています...
私のテストは次のようになります。
`import { test, moduleForModel } from 'ember-qunit';`
moduleForModel('meeting', 'App.Meeting',{
needs: ['model:customer']
setup: ->
Ember.run do (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 a DS.Model", -> ok(@subject())
test "attributes: can be created with 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')
ここで、このテストでいくつかの手法を使用しました。これは、Stack Overflow の回答で見つけましたが、今は見つけられないようです。
数日前は完全に機能していましたが、今では(私が知っているのはナンセンスに思えます)テストを実行するたびにエラーになります:
アサーションに失敗しました: この関係に「ミーティング」レコードを追加することはできません (「ミーティング」のみが許可されます)
エラーの場所も、修正方法もわかりません。一日中遊んでいて、結果はありません。
どうすればこれを解決できますか?