2012-06-23 4 views
0

Использование:Factory Girl Почему он создает две записи для каждого запрошенного?

factory_girl-2.6.4 
cucumber-1.2.1 
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux] 
Rails 3.0.15 

FactoryGirl.define do 

    factory :user do 
    email {Factory.next(:email)} 
    password 'test123' 
    end 

    factory :participant do 

    factory :person do 
     sequence(:name) {|n| Faker::Name.last_name + " #{n}" } 
     sequence(:other_names) { |n| Faker::Name.first_name } 
     type Participant::PERSON_TYPE 
    end 

    factory :organisation do 
     sequence(:name) {|n| Faker::Company.name + " #{n} Pty Ltd" } 
     type Participant::ORGANISATION_TYPE 
     sequence(:abn) {|n| "56 122 456 78#{n}" } 
    end 
    end 

    factory :client do 
    association :participant, :factory=>:organisation #, :name=> Faker::Name.name + ' Client' 
    role_type  { RoleType.where(:id => RoleType::CLIENT_ID).first } 
    type   Role::CLIENT_TYPE 
    sequence(:email) {|n| Faker::Internet::user_name + ".client#{n}@mailinator.com" } 
    std_account { Faker::PhoneNumber.phone_number[0,20] } 
    commenced_on { rand(60).days.ago } 
    end 

В огурце

Feature: test the construction of a factories 

    Background: Because factories also need to be tested 

    Given a client exists        # factory_girl-2.6.4/lib/factory_girl/step_definitions.rb:107 
    And Show Roles          # features/step_definitions/sign_in.rb:19 

Это производит 2 организации (которая является участником) & 2 клиентов следующим образом:

"-------- Roles & Organisations -------" 
[#<Client id: 2, participant_id: 2, user_id: nil, role_type_id: 5, type: "Client", std_account: "(989)416-2268", email: "[email protected]", url: nil, phone: nil, mobile: nil, fax: nil, commenced_on: "2012-05-14", expired_on: nil, created_at: "2012-06-23 03:27:43", updated_at: "2012-06-23 03:27:43", lock_version: 0>, 
#<Client id: 3, participant_id: 3, user_id: nil, role_type_id: 5, type: "Client", std_account: "301.424.0762 x123", email: "[email protected]", url: nil, phone: nil, mobile: nil, fax: nil, commenced_on: "2012-05-28", expired_on: nil, created_at: "2012-06-23 03:27:43", updated_at: "2012-06-23 03:27:43", lock_version: 0>] 
[#<Organisation id: 2, name: "Lowe, Lesch and Swift 1 Pty Ltd", type: "Organisation", other_names: nil, preferred_name: nil, salutation_id: nil, abn: "56 122 456 781", expired_on: nil, created_at: "2012-06-23 03:27:42", updated_at: "2012-06-23 03:27:42", lock_version: 0>, 
#<Organisation id: 3, name: "Deckow, Strosin and Schiller 2 Pty Ltd", type: "Organisation", other_names: nil, preferred_name: nil, salutation_id: nil, abn: "56 122 456 782", expired_on: nil, created_at: "2012-06-23 03:27:43", updated_at: "2012-06-23 03:27:43", lock_version: 0>] 

Может ли пролить некоторый свет на этом для меня пожалуйста - должен быть ровно один из каждого, насколько я понимаю.

Росс

ответ

0

Обновлено factory_girl до последней version.Problem ушел.

Смежные вопросы