FIX: use `update_attribute` method to trigger callbacks. (#13930)

FIX: use update_attribute method to trigger callbacks. (#13930)

Group flair is not removed while removing a user from the group since the before_save callback methods are not triggered while using the update_columns method.

diff --git a/app/models/group.rb b/app/models/group.rb
index 5cab53b..93ff94b 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -690,7 +690,7 @@ class Group < ActiveRecord::Base
     has_webhooks = WebHook.active_web_hooks(:group_user)
     payload = WebHook.generate_payload(:group_user, group_user, WebHookGroupUserSerializer) if has_webhooks
     group_user.destroy
-    user.update_columns(primary_group_id: nil) if user.primary_group_id == self.id
+    user.update_attribute(:primary_group_id, nil) if user.primary_group_id == self.id
     DiscourseEvent.trigger(:user_removed_from_group, user, self)
     WebHook.enqueue_hooks(:group_user, :user_removed_from_group,
       id: group_user.id,
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 2cd66c8..5f989c0 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -315,7 +315,7 @@ describe Group do
   end
 
   it "Correctly handles removal of primary group" do
-    group = Fabricate(:group)
+    group = Fabricate(:group, flair_icon: "icon")
     user = Fabricate(:user)
     group.add(user)
     group.save
@@ -330,6 +330,7 @@ describe Group do
 
     user.reload
     expect(user.primary_group).to eq nil
+    expect(user.flair_group_id).to eq nil
   end
 
   it "Can update moderator/staff/admin groups correctly" do

GitHub sha: 1da0aa838f255be3b64c489a26724fe1ae418450

This commit appears in #13930 which was approved by eviltrout. It was merged by vinothkannans.