0

使用:

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: "amani.aufderhar.client1@mailinator.com", 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: "brennan.client2@mailinator.com", 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>]

任何人都可以为我阐明这一点 - 据我所知,每个人都应该有一个。

罗斯

4

1 回答 1

0

将 factory_girl 更新到最新版本。问题消失了。

于 2012-08-11T05:16:01.997 回答