在rails中使用内部数组设置factory_girl

发布于 2024-09-16 01:11:31 字数 1536 浏览 2 评论 0原文

我有以下应该设置,我想使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文