]> source.dussan.org Git - redmine.git/commitdiff
Roles of a project member should not be made empty (#37166).
authorGo MAEDA <maeda@farend.jp>
Thu, 13 Apr 2023 23:34:23 +0000 (23:34 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 13 Apr 2023 23:34:23 +0000 (23:34 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: https://svn.redmine.org/redmine/trunk@22182 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 94c6615a2807501cbf83e493a0a69fded0ec6594..a20531f94ebb2ae7a99abe64abe293709a38a690 100644 (file)
@@ -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
index fd54123cb76c6171ed21b2c3314096ea33760fc6..139651f1b168ce1076a711c53d1fd14abd52bd27 100644 (file)
@@ -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