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.
This commit is contained in:
Gerhard Schlager 2020-05-24 22:12:55 +02:00
parent 058bf56b4c
commit 13d5ccedf5
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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