From 340736601770808a4df8be817e980f5f5bd3b84b Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 14 Apr 2023 00:54:50 +0000 Subject: [PATCH] Merged r22182 from trunk to 5.0-stable (#37166). git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@22183 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/member_role.rb | 2 +- test/unit/member_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/member_role.rb b/app/models/member_role.rb index 94c6615a2..a20531f94 100644 --- a/app/models/member_role.rb +++ b/app/models/member_role.rb @@ -52,7 +52,7 @@ class MemberRole < ActiveRecord::Base private def remove_member_if_empty - if @member_removal != false && member.roles.empty? + if @member_removal != false && member.roles.reload.empty? member.destroy end end diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb index 7fbaff6d6..696a584bc 100644 --- a/test/unit/member_test.rb +++ b/test/unit/member_test.rb @@ -225,4 +225,14 @@ class MemberTest < ActiveSupport::TestCase ) end end + + def test_destroy_member_when_member_role_is_empty + member = Member.find(1) + + assert_difference 'Member.count', -1 do + member.role_ids = [] # Destroy roles associated with member + end + assert member.destroyed? + assert_raise(ActiveRecord::RecordNotFound) { Member.find(1) } + end end -- 2.39.5