访问相关模型尚未提及

时间:2010-01-22 20:42:10

标签: cucumber pickle factory-bot

我有一个引用公司的用户工厂

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

公司拥有众多用户。现在我希望公司有很多客户。 没有必要提到公司,除了检查一次 创建客户端,然后它属于公司。

  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 client should be in my company's clients # needs the
right syntax

最后一句是我的担忧。我怎么告诉Pickle用户我 我登录时有一个与之关联的公司模型 工厂,所以检查该公司,看看现在是否有客户 与之相关。

由于

1 个答案:

答案 0 :(得分:1)

factory_girl中的协会有点棘手,也许回调(一个全新的功能)会对你有帮助吗?看看http://codeulate.com/2009/11/factory_girl-callbacks/