Factory Girl Association
Posted
by David Lyod
on Stack Overflow
See other posts from Stack Overflow
or by David Lyod
Published on 2010-06-04T11:12:55Z
Indexed on
2010/06/06
8:42 UTC
Read the original article
Hit count: 336
ruby-on-rails
|factorygirl
I have an association of a Admin -> Account in factory girl
I now wish to associate a second user with the same account but am unable to do so.
I build my Admin->Account association like this
u.account { |account| account.association(:account)}
This works fine and creates the Account and Admin association. Im looking for a way to setup a second user who's account also points to the record created in the Admin factory association.
I currently just build the second user as such
@user = Factory.build(:seconduser)
@user.account = Account.first
@user.save!
Which works but seems somewhat hacky .
© Stack Overflow or respective owner