我有这个设置:
factory :agency do |a|
a.agents_attributes { [FactoryGirl.attributes_for(:agent)] }
a.subdomain 'clear'
a.name 'ClearProperty'
end
factory :agent do |a|
agency
a.email 'user@test.com'
a.password 'please'
end
代理商has_many代理商和代理商必须在场。如何解决这个鸡蛋?我想做工厂(代理商),但这会叫工厂(代理商),然后再尝试建立另一个代理商。
答案 0 :(得分:1)
以下是我提出的建议:
factory :agency do |a|
a.agents_attributes { [FactoryGirl.attributes_for(:agent)] }
a.subdomain 'clear'
a.name 'ClearProperty'
end
factory :agent do |a|
a.email 'user@test.com'
a.password 'please'
a.after_create { |a| FactoryGirl.create(:agency, agent_ids: [a.id], agents_attributes: {}) }
end