在rails中使用内部数组设置factory_girl
我有以下应该设置,我想使用factory_girl在其他规格中提供假模型。
到目前为止,
context "on POST to parse" do
setup do
@fuzzy_lead = LeadCapturer::FuzzyLead.new
parts = LeadCapturer::LeadPartArray.new
parts << LeadCapturer::LeadPart.new('Mc Burney & Cowan', LeadCapturer::TextTag.new, 0)
parts << LeadCapturer::LeadPart.new('2 Lena Street', LeadCapturer::TextTag.new, 1)
parts << LeadCapturer::LeadPart.new('Belfast', LeadCapturer::TextTag.new, 2)
parts << LeadCapturer::LeadPart.new('Down', LeadCapturer::TextTag.new, 3)
parts << LeadCapturer::LeadPart.new('BT5 5BJ', LeadCapturer::PostCodeTag.new, 4)
parts << LeadCapturer::LeadPart.new('Tel: 028 9047 1054', LeadCapturer::PhoneTag.new, 5)
parts << LeadCapturer::LeadPart.new('Fax: 028 9047 1054', LeadCapturer::FaxTag.new, 6)
parts << LeadCapturer::LeadPart.new('[email protected]', LeadCapturer::EmailTag.new, 7)
parts << LeadCapturer::LeadPart.new('http://www.mcburneyandcowan.com/', LeadCapturer::WebSiteTag.new, 8)
parts << LeadCapturer::LeadPart.new('General Manager: Mike Halliday', LeadCapturer::ContactTag.new, 9)
@fuzzy_lead.instance_eval do
@parts = parts
end
end
我知道如何在factory_girl中设置关联,但我不确定如何在factory_girl中设置上述内容。
也许它不太适合这种情况。
有人可以帮我吗?
I have the following shoulda set up which I would like to use factory_girl to have the fake model available in other specs.
So far I have this:
context "on POST to parse" do
setup do
@fuzzy_lead = LeadCapturer::FuzzyLead.new
parts = LeadCapturer::LeadPartArray.new
parts << LeadCapturer::LeadPart.new('Mc Burney & Cowan', LeadCapturer::TextTag.new, 0)
parts << LeadCapturer::LeadPart.new('2 Lena Street', LeadCapturer::TextTag.new, 1)
parts << LeadCapturer::LeadPart.new('Belfast', LeadCapturer::TextTag.new, 2)
parts << LeadCapturer::LeadPart.new('Down', LeadCapturer::TextTag.new, 3)
parts << LeadCapturer::LeadPart.new('BT5 5BJ', LeadCapturer::PostCodeTag.new, 4)
parts << LeadCapturer::LeadPart.new('Tel: 028 9047 1054', LeadCapturer::PhoneTag.new, 5)
parts << LeadCapturer::LeadPart.new('Fax: 028 9047 1054', LeadCapturer::FaxTag.new, 6)
parts << LeadCapturer::LeadPart.new('[email protected]', LeadCapturer::EmailTag.new, 7)
parts << LeadCapturer::LeadPart.new('http://www.mcburneyandcowan.com/', LeadCapturer::WebSiteTag.new, 8)
parts << LeadCapturer::LeadPart.new('General Manager: Mike Halliday', LeadCapturer::ContactTag.new, 9)
@fuzzy_lead.instance_eval do
@parts = parts
end
end
I know how to set up associations in factory_girl but I am not sure how I would set up the above in factory_girl.
Maybe it is not a good fit for this situation.
Can anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论