我正在使用user.rb
:
has_many :family, -> { where ["user_type = 'family'"] }
has_one :friend, -> { where ["user_type = 'friend'"] }
我想在has_many
下的用户工厂中使用traits
条件行。我怎么能这样做?
我的工厂是:
FactoryGirl.define do
factory :user do
trait :with_family_photo do
after(:create) do |photo|
photo.portrait_type 'portrait_type'
photo.family_photos << FactoryGirl.create(:with_family_photo, photo_id: photo.id)
end
end
trait :with_friends_photo do
after(:create) do |photo|
photo.portrait_type 'portrait_photo'
end
end
end