diff --git a/app/models/user.rb b/app/models/user.rb index 5f8239044..2e77e8921 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -336,7 +336,7 @@ def merge(*others) other.activities.update_all(trackable_id: id, trackable_type: self.class.name) other.subscriptions.update_all(user_id: id) new_collaborations += other.collaborations - new_editable_ids = other.editable_ids + new_editable_ids |= other.editable_ids attrs.reverse_merge!(other.attributes) end self.editable_ids = self.editable_ids | new_editable_ids diff --git a/test/models/user_test.rb b/test/models/user_test.rb index cd0b16159..e37a1b0ed 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -340,6 +340,10 @@ class UserTest < ActiveSupport::TestCase provider = content_providers(:goblet) provider.add_editor(user1) provider.add_editor(user2) + provider2 = content_providers(:iann) + provider2.add_editor(user2) + provider3 = content_providers(:two) + provider3.add_editor(user3) # Collaborations workflow1 = workflows(:one) @@ -348,12 +352,13 @@ class UserTest < ActiveSupport::TestCase workflow1.collaborators << user2 workflow2.collaborators << user3 - # Test assert_no_difference('Event.count') do assert_no_difference('Material.count') do assert_no_difference('Subscription.count') do assert_difference('provider.editors.count', -1) do + assert_no_difference('provider2.editors.count') do + assert_no_difference('provider3.editors.count') do assert_difference('Collaboration.count', -1) do assert_difference('User.count', -2) do assert user1.merge(user2, user3) @@ -365,6 +370,8 @@ class UserTest < ActiveSupport::TestCase end end end + end + end assert_equal 'base_user', user1.username assert_equal user1_id, user1.id @@ -387,7 +394,9 @@ class UserTest < ActiveSupport::TestCase assert_equal user1, subscription1.reload.user assert_equal user1, subscription2.reload.user - assert_includes provider.reload.editors, user1 + assert_equal [user1], provider.reload.editors + assert_equal [user1], provider2.reload.editors + assert_equal [user1], provider3.reload.editors assert_equal [user1], workflow1.reload.collaborators.to_a assert_equal [user1], workflow2.reload.collaborators.to_a