FactoryGirl:生成一组相关记录

时间:2012-02-14 13:28:00

标签: ruby-on-rails-3 associations sequence factory-bot has-many

拥有下一个工厂:

FactoryGirl.define do
  factory :card do
    bundle
    number 4567
  end

  factory :bundle do
    start_number 12345
    cards_amount 10
    after_create { |bundle| Factory(:card, :number => start_number, :bundle => bundle) }
  end
end

所以,每个包都有一些卡片,f.i。捆绑2-5具有卡2,3,4,5,start_number = 2和cards_amount = 4

我想生成一个包含10张卡Factory(:bundle, :cards_amount => 10)的捆绑包,但数字相同且未填写所需范围。

如何制作包含正确卡号的捆绑包?

0 个答案:

没有答案