我正在使用Factory Girl,我想指定一个使用特征的belongs_to关联。此代码(没有特征)有效:
FactoryGirl.define do
factory :challenge_participation do
user
challenge
program
end
end
但是我如何将with_days
特征添加到我的程序中? (with_days
特征设置了一些has_many关联。)
我想它会是这样的,但我找不到合适的语法:
FactoryGirl.define do
factory :challenge_participation do
user
challenge
program :with_days # THIS DOESN'T WORK
end
end
答案 0 :(得分:1)
program
方法接受一个块。所以,你这样做:
FactoryGirl.define do
factory :challenge_participation do
user
challenge
program { FactoryGirl.create(:program, :with_days) }
end
end