summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-04-13 23:34:23 +0000
committerGo MAEDA <maeda@farend.jp>2023-04-13 23:34:23 +0000
commit798cd2d566a7b8c17b576068c805b8947aca09af (patch)
treecc728a197831dc045bb2b62026ff94475f83aaea
parenta48700d58b3d6ad466e56b8b64d5563c36134f33 (diff)
downloadredmine-798cd2d566a7b8c17b576068c805b8947aca09af.tar.gz
redmine-798cd2d566a7b8c17b576068c805b8947aca09af.zip
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
-rw-r--r--app/models/member_role.rb2
-rw-r--r--test/unit/member_test.rb10
2 files changed, 11 insertions, 1 deletions
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