Factory Girlオブジェクトでto_jsonを呼び出すと、nil。[]エラーが発生します。
Rails 3でDataMapperを使用していますが、実際のDataMapperオブジェクトでto_jsonを呼び出すと、問題なく機能します。Factory Girlオブジェクトが失敗する理由はありますか?
Factory.define :something do |b|
b.date_foo { 3.days.ago - 4.hours }
b.date_bar { 3.days.ago - 4.hours }
b.somestring '11'
b.anotherstring 'ASTRINGYAY'
b.thirdstring 'STRINGG'
b.fourthstring 'STRING'
b.otherstring 'thestring'
b.longerstring 'The string that is longer'
b.somenumber 3
b.someothernumber 2
b.an_id 5593
b.a_version '1.2.2.2'
b.a_string '1.2.2.2'
b.something '1.2.2.2'
b.code 'SOME CODE'
b.other_code 'API'
b.something_id 49
b.something_version 'OMG'
b.otherthing 'N/A'
b.lastthing 'A'
end
また、私は次のことを発見しました。
factory_girl_object.to_json
正常に動作します。
[factory_girl_object].to_json
失敗します。
DataMapperは、配列の代わりにDataMapper :: Collectionオブジェクトを使用しているようです。このオブジェクトは、配列とは内容が少し異なるto_jsonを処理します。ただし、Factory_Girlオブジェクトを保持するDataMapper::Collectionオブジェクトを作成する方法がわからないようです。
考え?