Skip to content

Commit

Permalink
Added tests to make sure members and groups aren't added more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvh committed May 19, 2017
1 parent 757d091 commit 68b6140
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68b6140

Please sign in to comment.