lundi 27 novembre 2017

How can I use rails has_many with where condition using in factory?

I am using in user.rb has_many :family, -> { where ["user_type = 'family'"] } and has_one :friend, -> { where ["user_type = 'friend'"] } I want to use has_many conditions row in my user factory in traits. How can I made it ? My factory is that

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
end

I hope help to me! Thanks in advance

Aucun commentaire:

Enregistrer un commentaire