我的spec文件夹中有以下代码
let(:team_lead) { create(:user) }
let(:developers) { FactoryGirl.create_list(:user, 3) }
let(:project) { create(:project, team_lead: team_lead, users: [developers]) }
但它一直给我这个错误
*** ActiveRecord::AssociationTypeMismatch Exception: User(#70271414797520) expected, got
[#<User id: 420, name: "Litzy Champlin", email: "dahlia@feil.net", created_at: "2018-05-25 02:59:17", updated_at: "2018-05-25 02:59:17", provider: nil, uid: nil, token: nil, token_expires_at: nil>,
#<User id: 421, name: "Missouri Hilll DDS", email: "elizabeth@sauerhaag.com", created_at: "2018-05-25 02:59:17", updated_at: "2018-05-25 02:59:17", provider: nil, uid: nil, token: nil, token_expires_at: nil>,
#<User id: 422, name: "Joel Williamson Sr.", email: "maurine@gutkowski.net", created_at: "2018-05-25 02:59:17", updated_at: "2018-05-25 02:59:17", provider: nil, uid: nil, token: nil, token_expires_at: nil>]
which is an instance of Array(#70271403139340)
我在spec/factory/project.rb
FactoryGirl.define do
factory :project do
name { Faker::Name.name }
team_lead nil
factory :project_with_team_lead do
team_lead
end
end
end
项目和用户模型之间的关系是has_and_belongs_to_many。我不想删除开发人员,因为我想将它用于更多测试用例。那我该怎么做呢?