初学 ruby
------------------------------ model 部分 ------------------------------
class User < ActiveRecord::Base
end
class Member < ActiveRecord::Base
belongs_to :user
end
class ProjectMember < Member
end
------------------------------ spec 部分 ------------------------------
factory :project_member do
association :user, :factory => :user
project
access_level { ProjectMember::MASTER }
end
此时 p ProjectMember.instance_methods 中明明有 user= 这个函数,但是执行 rspec 却出错
提示 factory_girl 生成假数据时出错
2) project_member factory should be valid
Failure/Error: expect(build(factory_name)).to be_valid
ActiveRecord::AssociationNotFoundError: Association named 'user' was not found on ProjectMember; perhaps you misspelled it?
如果将 ProjectMember 改为
class ProjectMember < Member
belongs_to :user
end
则一切 OK 我哪里出错了么?