From 68b6140089e7afdc32ce30e5e1a063d70863bb0e Mon Sep 17 00:00:00 2001 From: Joel Van Horn Date: Thu, 18 May 2017 21:53:37 -0400 Subject: [PATCH] Added tests to make sure members and groups aren't added more than once --- spec/active_record_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/active_record_spec.rb b/spec/active_record_spec.rb index 2841188..eadcac3 100644 --- a/spec/active_record_spec.rb +++ b/spec/active_record_spec.rb @@ -179,6 +179,28 @@ class ProjectMember < ActiveRecord::Base expect(group.users).to include(*users) end + it "only adds group to member.groups once when added directly to association" do + user.groups << group + user.groups << group + + expect(user.groups.count).to eq(1) + + user.groups.reload + + expect(user.groups.count).to eq(1) + end + + it "only adds member to group.members once when added directly to association" do + group.members << user + group.members << user + + expect(group.members.count).to eq(1) + + group.members.reload + + expect(group.members.count).to eq(1) + end + it "only allows members to be added to their configured group type" do classroom = Classroom.create! expect { classroom.add(user) }.to raise_error(ActiveRecord::AssociationTypeMismatch)