工厂女孩不加载关系

时间:2013-06-07 11:34:04

标签: ruby-on-rails factory-bot relation

我正在使用工厂女孩测试rails应用程序。

用户belongs_to Adresse。

我想用adresse测试用户,这是我的用户工厂:

# encoding: utf-8
require 'faker'

FactoryGirl.define do

  factory :user do
    nom_proprietaire    { Faker::Name.first_name }
    email    { Faker::Internet.email}
    raison_sociale    { Faker::Company.name}
    password               "password"
    password_confirmation  "password"
    adresse
  end

  factory :user_with_recurring_order_to_generate, parent: :user do
    after(:build) {|u| FactoryGirl.create(:contrat_with_active_product, :user=>u)}
  end
end

这是我的工厂:

# encoding: utf-8
require 'faker'

FactoryGirl.define do

  factory :adresse do
    nom_prenom   "qfsd"
    #{ Faker::Name.first_name }
    adresse_ligne_1    { Faker::Address.street_address}
    ville { Faker::Address.city}
    code_postal { Faker::Address.zip_code}
    pays { Faker::Address.country}
    telephone { Faker::PhoneNumber.phone_number}
  end
end

然而,当我在测试中使用用户时,我有以下错误:

ActiveRecord::RecordInvalid:
   La validation a échoué : Ville doit être rempli(e)

意思是我不尊重为我的地址验证ville的存在。当我想创建一个地址时,我如何告诉工厂女孩使用我的工厂?

编辑:我的代码没问题,这是为法国人打破的faker宝石......

1 个答案:

答案 0 :(得分:0)

我的代码很好,这是Faker的宝石,因法国人而被打破。

相关问题