有没有人遇到过这个:
我有这样的事情:
楷模:
class User < ActiveRecord::Base
authenticates_with_sorcery!
attr_accessible :forename, :surname, :email, :password, :password_confirmation
...
end
class Manager < User
has_many :things_to_manage
...
end
class ThingsToManage < ActiveRecord::Base
attr_accessible :stuff, :more_stuff
belongs_to :manager
...
end
我想建立一个工厂,以便 FactoryGirl.create(:things_to_manage) 将创建一个带有管理器(继承自用户)的 ThingsToManager 模型(保存在数据库中)
我的工厂是这样的:
FactoryGirl.define do
factory :user do
forename 'Test'
surname 'User'
sequence(:email) {|n| "#{forename}.#{surname}#{n}@test.com".downcase}
password 'lalala123@@'
end
end
FactoryGirl.define do
factory :manager do
end
end
FactoryGirl.define do
factory :things_to_manage do
stuff "rhubarb rhubarb"
more_stuff "la la la"
association :manager, :factory => :user
end
end
association :manager, :factory => :user
不起作用;我明白了
ActiveRecord::AssociationTypeMismatch: Manager(#70275174714940) 预期,得到用户(#70275151319360)
有任何想法吗?