From: Go MAEDA Date: Thu, 13 Apr 2023 23:34:23 +0000 (+0000) Subject: Roles of a project member should not be made empty (#37166). X-Git-Tag: 5.1.0~178 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=798cd2d566a7b8c17b576068c805b8947aca09af;p=redmine.git Roles of a project member should not be made empty (#37166). Patch by Mizuki ISHIKAWA. git-svn-id: https://svn.redmine.org/redmine/trunk@22182 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- 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 fd54123cb..139651f1b 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