开发者

Accessing Related Model's not yet mentioned

开发者 https://www.devze.com 2022-12-18 00:57 出处:网络
I have a User factory that references a Company Factory.define :user do |f| f.first_name \"John\" f.last_name \"Smith\"

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 "john.smith@example.com"
  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 "john.sm...@example.com",
"test01"
    And I login with "john.smith@example.com", "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 cli开发者_JAVA技巧ent 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


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消