]> source.dussan.org Git - redmine.git/commitdiff
Adds a test for #25289.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 8 Mar 2017 20:36:22 +0000 (20:36 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 8 Mar 2017 20:36:22 +0000 (20:36 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16382 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/member.rb
test/unit/member_test.rb

index b19f78c6b98a146cc12db740d8563d28a8c79c95..61cec0d7970474f7dc40da423f386866e0b51fe6 100644 (file)
@@ -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
   #
index ce9898f4b98af6e99321038a91b9bd697b4e254a..344aec7b9f2641d7b02cdcc3efa4764b9ec45bc6 100644 (file)
@@ -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