I have the following code in my spec folder
let(:team_lead) { create(:user) }
let(:developers) { FactoryGirl.create_list(:user, 3) }
let(:project) { create(:project, team_lead: team_lead, users: [developers]) }
but it keep giving me this error
*** ActiveRecord::AssociationTypeMismatch Exception: User(#70271414797520) expected, got
[#<User id: 420, name: "Litzy Champlin", email: "[email protected]", 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: "[email protected]", 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: "[email protected]", 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)
I have this factorygirl in 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
The relations between projects and users model is has_and_belongs_to_many. I do not want remove the developers as I want to use it for more test cases. So how do I do this?