summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/member.rb3
-rw-r--r--test/unit/member_test.rb11
2 files changed, 13 insertions, 1 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index b19f78c6b..61cec0d79 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -172,7 +172,8 @@ class Member < ActiveRecord::Base
end
end
- # Creates memberships for principal with the attributes
+ # Creates memberships for principal with the attributes, or add the roles
+ # if the membership already exists.
# * project_ids : one or more project ids
# * role_ids : ids of the roles to give to each membership
#
diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb
index ce9898f4b..344aec7b9 100644
--- a/test/unit/member_test.rb
+++ b/test/unit/member_test.rb
@@ -196,4 +196,15 @@ class MemberTest < ActiveSupport::TestCase
member.roles << Role.generate!(:all_roles_managed => true)
assert_equal [], member.managed_roles
end
+
+ def test_create_principal_memberships_should_not_error_with_2_projects_and_inheritance
+ parent = Project.generate!
+ child = Project.generate!(:parent_id => parent.id, :inherit_members => true)
+ user = User.generate!
+
+ assert_difference 'Member.count', 2 do
+ members = Member.create_principal_memberships(user, :project_ids => [parent.id, child.id], :role_ids => [1])
+ assert members.none?(&:new_record?), "Unsaved members were returned: #{members.select(&:new_record?).map{|m| m.errors.full_messages}*","}"
+ end
+ end
end