From 13d5ccedf5fd8f5350c65766c1a180d23077d2ae Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Sun, 24 May 2020 22:12:55 +0200 Subject: [PATCH] FIX: Destroying a user failed when it had title ...because updating the user caused a validation of the primary email and the UserEmail records are already deleted at that time. --- app/models/group_user.rb | 2 +- spec/models/group_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/group_user.rb b/app/models/group_user.rb index 664a333e9bd..7b8d8652a61 100644 --- a/app/models/group_user.rb +++ b/app/models/group_user.rb @@ -38,7 +38,7 @@ class GroupUser < ActiveRecord::Base def grant_other_available_title if group.title.present? && group.title == user.title - user.update!(title: user.next_best_title) + user.update_attribute(:title, user.next_best_title) end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 0cb8362c804..ddc3224e331 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -502,6 +502,14 @@ describe Group do expect(user.title).to eq('Different') expect(user.primary_group).to eq(primary_group) end + + it "doesn't fail when the user gets destroyed" do + group.update(title: 'Awesome') + group.add(user) + user.reload + + UserDestroyer.new(Discourse.system_user).destroy(user) + end end it "has custom fields" do