我怎么能破坏工厂女孩协会?

时间:2015-09-30 01:31:20

标签: ruby-on-rails factory-bot

我生成了这个工厂:

  FactoryGirl.define do
    sequence :account_login do |n|
      "login-#{ n }"
    end



  factory :account do
    sequence :email do |n|
      "someone#{n}@gmail.com"
    end
    email_confirmation { |account| account.send :email }
    url { Faker::Internet.url }
    login { generate(:account_login) }
    password { Faker::Internet.password }
    password_confirmation { |account| account.send(:password) }
    current_password { |account| account.send(:password) }
    twitter_account 'openhub'
    name { Faker::Name.name + rand(999_999).to_s }
    about_raw { Faker::Lorem.characters(10) }
    activated_at { Time.current }
    activation_code nil
    country_code 'us'
    email_master true
    email_kudos true
    email_posts true
    association :github_verification
  end
 end

我真正需要做的是创建第二个工厂,创建一个具有nil github_verification属性的用户。

这样的事情:

factory :account_with_no_verifications, parent: :account do
  associaton github_verification = nil
end

有办法吗?

1 个答案:

答案 0 :(得分:1)

只需使用FactoryGirl::Strategy::Null http://www.rubydoc.info/github/thoughtbot/factory_girl/FactoryGirl/Strategy/Null

即可
factory :account_with_no_verifications, parent: :account do
  association github_verification, strategy: :null
end