simple has_one and belongs_to association problem

23 views
Skip to first unread message

Anton

unread,
Dec 3, 2009, 11:40:55 AM12/3/09
to factory_girl
Hi!

I have a User (has_one :company) and a Company (belongs_to :user).

I have two factories for the users:

Factory.define :employee_without_company, :class => User do |f|
f.company nil
Factory.define :employee, :class => User do |f|
# HERE is the problem

and one for the company:

Factory.define :company do |f|
f.association :user, :factory => :employee_without_company

The problem is: If I call Factory(:employee) the .company is always
nil.

I tried (at HERE):
1) f.association :company
2) f.company {|comp| comp.association :company }
3) f.after_create {|usr| usr.company = Factory(:company, :user =>
usr)}
4) removed the association command from the company factory
5) set the association in the company to the employee_without_company
6) ... some other stuff

but I cant get a user with a valid association to a company.

The results are: stack level too deep or company is nil.

Can anybody help me out?

Thank you very much in advance!

Regards,
Anton
Reply all
Reply to author
Forward
0 new messages