ruby on rails - Has Many associations with Factory Girl -


factory :account end  factory :user    account end  factory :user2    account end   factory :location   // how add users has_many collection? end 

my location model has has_many :users association, how can add user , user2 collection in factories?

also when building object graph, should factory_girl used create account, user not build relation between two? should doing myself in tests or kind of helper? because want create account1 , account2, , each account has location. have build object graph myself within tests right?

you have use after callback:

factory :location   after(:create) |location, evaluator|     create(:user, location: location)     create(:user2, location: location)   end end 

see documentation


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -