【问题标题】:factory girl does not load a relation工厂女孩不加载关系
【发布时间】:2013-06-07 11:34:03
【问题描述】:

我正在使用 factory girl 来测试一个 rails 应用程序。

一个用户属于_to 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 gem...

【问题讨论】:

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


    【解决方案1】:

    我的代码没问题,是法语版的 Faker gem。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多