]> source.dussan.org Git - redmine.git/commitdiff
Merged r22182 from trunk to 5.0-stable (#37166).
authorGo MAEDA <maeda@farend.jp>
Fri, 14 Apr 2023 00:54:50 +0000 (00:54 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 14 Apr 2023 00:54:50 +0000 (00:54 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/5.0-stable@22183 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 7fbaff6d6316b19c6647acb41cd830c9b7760e13..696a584bc7b2a7721aa11a8644d60ab77b30a6c6 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