当我在 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 的内容与数组的处理方式略有不同。但是,我似乎无法弄清楚如何创建一个 DataMapper::Collection 对象来保存我的 Factory_Girl 对象。
想法?