FactoryGirl错误:未初始化的常量Post :: user

时间:2015-09-20 05:07:30

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

我有点奇怪的命名空间错误处理FactoryGirl。该模型为Post ⤞ User。 代码是:

require 'factory_girl'
require 'active_record'

class User < ActiveRecord::Base ; end
class Post < ActiveRecord::Base
  has_one :moderator, class_name: :user
end

::FactoryGirl.define do
  factory :user do
    name 'Ghghghgh Ghghg'
  end
  factory :post do
    text 'Lorem ipsum etc'
    association :moderator, factory: :user, strategy: :create
  end
end

要求罚款,返回true。现在当我尝试生成一个实例时,我收到了这个错误:

FactoryGirl.create :post
#⇒ NameError: uninitialized constant Post::user

我错过了哪些明显的东西?

0 个答案:

没有答案