我有三個工廠,我想幹起來。他們看起來像這樣:FactoryGirl:使用參數創建動態工廠?
factory :sequenced_stamps_by_years, class: Stamp do
...
sequence(:day_date) { |n| n.years.ago }
end
factory :sequenced_stamps_by_months, class: Stamp do
...
sequence(:day_date) { |n| n.months.ago }
end
factory :sequenced_stamps_by_weeks, class: Stamp do
...
sequence(:day_date) { |n| n.weeks.ago }
end
我該如何幹燥呢?我想要能夠創建他們這樣的事情:
FactoryGirl.create_list(:sequenced_stamps_by_x, 4, x: "weeks") ## <- So that i can decide whether I want weeks, days, years, or months ago.
這可能嗎?
你能描述你想要的輸出嗎? – 2013-05-05 13:47:12
我想要x數量的印記對象,以及:day_date的日期應該是x週數,數年或數月。 – 2013-05-05 13:56:32