English 中文(简体)
Accessing Related Model s not yet mentioned
原标题:

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 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

问题回答

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/





相关问题
Question about Cucumber/Pickle

I m trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests. I have the following Feature: ...

Efficient method to store Python dictionary on disk?

What is the most efficient method to store a Python dictionary on the disk? The only methods I know of right now are plain-text and the pickle module. Edit: Sorry for not being very clear. By ...

how to use pickle

my code(i was unable to use pickle ): class A(object): def __getstate__(self): print www return sss def __setstate__(self,d): print aaaa import pickle a = A() ...

Is pickle file of python cross-platform?

I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is ...

ValueError: insecure string pickle

When I am trying to load something I dumped using cPickle, I get the error message: ValueError: insecure string pickle Both the dumping and loading work are done on the same computer, thus same OS: ...

热门标签