views:

21

answers:

1

I have a User factory that references a Company

Factory.define :user do |f|
  f.first_name "John"
  f.last_name "Smith"
  f.password "test01"
  f.password_confirmation {|u| u.password}
  f.email "[email protected]"
  f.association :company, :factory => :company
end

Factory.define :company do |f|
  f.name "My Company"
end

The Company has many Users. Now I want Company to have many Clients. There is no need to mention the company, other than to check that once the client is created, then it belongs to the company.

Scenario: Creating a client adds them to a user's company Given a user "John" has registered with "[email protected]", "test01" And I login with "[email protected]", "test01" And I am on the list of clients When I follow "Add New Client" When I fill in "Name" with "My Fav Client" And I press "Create" Then a client should exist with name: "My Fav Client" And that client should be in my company's clients # needs the right syntax

The last sentence is my concern. How do I tell Pickle that the user I am logged in with had a company model associated with it from the factory, so check that company to see if there is now a client associated with it.

Thanks

A: 

Associations in factory_girl are little tricky, maybe callbacks (a brand new feature) will help you? Have a look on http://codeulate.com/2009/11/factory_girl-callbacks/

luacassus