FactoryGirl Association给出“未初始化的常量”错误

时间:2014-06-19 15:24:39

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

我有工厂女孩和协会的问题。

NameError: uninitialized constant User::DefaultDeviceX

用户工厂:

FactoryGirl.define do
  factory :user do
    name "MyString"
    email "MyString"
    password "MyString"
    association :default_device_x, factory: :device
    association :default_device_y, factory: :device
  end
end

执行FactoryGirl.create(:user)会引发上面提到的错误。

那么,我做错了什么?

用户模型引用设备:

  belongs_to :default_device_x
  belongs_to :default_device_y

设备工厂

FactoryGirl.define do
 factory :device do
  name "Device 1"
  comments "Comment"
 end
end

0 个答案:

没有答案