FactoryGirl:生成一组关联记录
拥有下一个工厂:
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
因此,每个捆绑包都有一些卡,fi捆绑包2-5有卡2、3、4、5,start_number = 2和cards_amount = 4
我想生成一个包含10张卡的捆绑包 Factory(:包,:cards_amount => 10)
,但数字相同并且未填充所需的范围。
如何使用正确的卡号进行捆绑?
Having the next factories:
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
So, each bundle has some cards, f.i. bundle 2-5 has cards 2, 3, 4, 5, start_number = 2 and cards_amount = 4
I want to generate a bundle with 10 cards Factory(:bundle, :cards_amount => 10)
, but the numbers are the same and don't fill the desired range.
How can I make a bundle with correct card numbers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论