4
,我們沒有一個工廠,我們正在開發的嵌套關係如何在工廠女孩更新嵌套屬性值
FactoryGirl.define do
factory : user do
name "Arvind"
association :campaign
factory :user_with_photos do
after(:build) do |user|
user.photos.build name: 'user 1',
user.photos.build name: 'user 2', position: 2
end
end
factory :user_with_mandatory_photos do
after(:build) do |user|
user.photos.build name: 'user 3', mandatory: true
user.photos.build name: 'user 4', mandatory: true
end
end
factory :user_with_mandatory_photos do
after(:build) do |user|
user.photos.build name: 'user 5', mandatory: false
user.photos.build name: 'user 6', mandatory: false
end
end
end
end
我們就像
users = FactoryGirl.create(:user_without_mandatory_fields, campaign: @campaign)
users = FactoryGirl.create(:user_with_mandatory_fields, campaign: @campaign)
我們正在創建的屬性,以減少這和使用只有
factory : user do
name "Arvind"
association :campaign
factory :user_with_photos do
after(:build) do |user|
user.photos.build name: 'user 1',
user.photos.build name: 'user 2', position: 2
end
end
end
但我們沒有得到如何創建用戶照片與必填字段我在這種情況下。任何人都可以請建議?
Looking something like users = FactoryGirl.create(:user_with_photos,[update user photo attribute make mandatory true ] campaign: @campaign)