DEV: remove update_attributes which is deprecated in Rails 6

DEV: remove update_attributes which is deprecated in Rails 6

See: Deprecate `update_attributes` and `update_attributes!` by elebow · Pull Request #31998 · rails/rails · GitHub

update_attributes is a relic of the past, it should no longer be used.

diff --git a/app/controllers/admin/screened_ip_addresses_controller.rb b/app/controllers/admin/screened_ip_addresses_controller.rb
index 1447fe2..59f7742 100644
--- a/app/controllers/admin/screened_ip_addresses_controller.rb
+++ b/app/controllers/admin/screened_ip_addresses_controller.rb
@@ -32,7 +32,7 @@ class Admin::ScreenedIpAddressesController < Admin::AdminController
   end
 
   def update
-    if @screened_ip_address.update_attributes(allowed_params)
+    if @screened_ip_address.update(allowed_params)
       render_serialized(@screened_ip_address, ScreenedIpAddressSerializer)
     else
       render_json_error(@screened_ip_address)
diff --git a/app/controllers/admin/web_hooks_controller.rb b/app/controllers/admin/web_hooks_controller.rb
index 907bdfc..d11c8bf 100644
--- a/app/controllers/admin/web_hooks_controller.rb
+++ b/app/controllers/admin/web_hooks_controller.rb
@@ -42,7 +42,7 @@ class Admin::WebHooksController < Admin::AdminController
   end
 
   def update
-    if @web_hook.update_attributes(web_hook_params)
+    if @web_hook.update(web_hook_params)
       StaffActionLogger.new(current_user).log_web_hook(@web_hook, UserHistory.actions[:web_hook_update], changes: @web_hook.saved_changes)
       render_serialized(@web_hook, AdminWebHookSerializer, root: 'web_hook')
     else
@@ -92,7 +92,7 @@ class Admin::WebHooksController < Admin::AdminController
 
       now = Time.zone.now
       response = conn.post(headers: MultiJson.load(web_hook_event.headers), body: web_hook_event.payload)
-      web_hook_event.update_attributes!(status: response.status,
+      web_hook_event.update!(status: response.status,
                                         response_headers: MultiJson.dump(response.headers),
                                         response_body: response.body,
                                         duration: ((Time.zone.now - now) * 1000).to_i)
diff --git a/app/controllers/badges_controller.rb b/app/controllers/badges_controller.rb
index 902f3bf..f4f43ff 100644
--- a/app/controllers/badges_controller.rb
+++ b/app/controllers/badges_controller.rb
@@ -45,7 +45,7 @@ class BadgesController < ApplicationController
     if current_user
       user_badge = UserBadge.find_by(user_id: current_user.id, badge_id: @badge.id)
       if user_badge && user_badge.notification
-        user_badge.notification.update_attributes read: true
+        user_badge.notification.update read: true
       end
       if user_badge
         @badge.has_badge = true
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index ab9fdbe..4443583 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -175,7 +175,7 @@ class CategoriesController < ApplicationController
 
     custom_slug = params[:slug].to_s
 
-    if custom_slug.present? && @category.update_attributes(slug: custom_slug)
+    if custom_slug.present? && @category.update(slug: custom_slug)
       render json: success_json
     else
       render_json_error(@category)
diff --git a/app/jobs/onceoff/fix_featured_link_for_topics.rb b/app/jobs/onceoff/fix_featured_link_for_topics.rb
index f05d552..205584d 100644
--- a/app/jobs/onceoff/fix_featured_link_for_topics.rb
+++ b/app/jobs/onceoff/fix_featured_link_for_topics.rb
@@ -7,7 +7,7 @@ module Jobs
         begin
           URI.parse(featured_link)
         rescue URI::Error
-          topic.update_attributes(featured_link: URI.extract(featured_link).first)
+          topic.update(featured_link: URI.extract(featured_link).first)
         end
       end
     end
diff --git a/app/models/category.rb b/app/models/category.rb
index 1ae55c4..fac08a8 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -518,7 +518,7 @@ class Category < ActiveRecord::Base
       .pluck("topics.id")
       .first
 
-    self.update_attributes(latest_topic_id: latest_topic_id, latest_post_id: latest_post_id)
+    self.update(latest_topic_id: latest_topic_id, latest_post_id: latest_post_id)
   end
 
   def self.query_parent_category(parent_slug)
diff --git a/app/models/post.rb b/app/models/post.rb
index d39a4bc..9f06916 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -520,8 +520,8 @@ class Post < ActiveRecord::Base
   end
 
   def unhide!
-    self.update_attributes(hidden: false)
-    self.topic.update_attributes(visible: true) if is_first_post?
+    self.update(hidden: false)
+    self.topic.update(visible: true) if is_first_post?
     save(validate: false)
     publish_change_to_clients!(:acted)
   end
diff --git a/app/models/topic.rb b/app/models/topic.rb
index e685aa7..bb5a083 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -761,7 +761,7 @@ class Topic < ActiveRecord::Base
       increment!(:moderator_posts_count) if new_post.persisted?
       # If we are moving posts, we want to insert the moderator post where the previous posts were
       # in the stream, not at the end.
-      new_post.update_attributes!(post_number: opts[:post_number], sort_order: opts[:post_number]) if opts[:post_number].present?
+      new_post.update!(post_number: opts[:post_number], sort_order: opts[:post_number]) if opts[:post_number].present?
 
       # Grab any links that are present
       TopicLink.extract_from(new_post)
diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb
index 675a58e..44a1766 100644
--- a/app/services/badge_granter.rb
+++ b/app/services/badge_granter.rb
@@ -53,7 +53,7 @@ class BadgeGranter
                         badge_title: @badge.allow_title,
                         username: @user.username }.to_json
               )
-              user_badge.update_attributes notification_id: notification.id
+              user_badge.update notification_id: notification.id
             end
           end
         end
diff --git a/app/services/color_scheme_revisor.rb b/app/services/color_scheme_revisor.rb
index 0057ded..36776ea 100644
--- a/app/services/color_scheme_revisor.rb
+++ b/app/services/color_scheme_revisor.rb
@@ -19,7 +19,7 @@ class ColorSchemeRevisor
       if has_colors
         @params[:colors].each do |c|
           if existing = @color_scheme.colors_by_name[c[:name]]
-            existing.update_attributes(c)
+            existing.update(c)
           else
             @color_scheme.color_scheme_colors << ColorSchemeColor.new(name: c[:name], hex: c[:hex])
           end
diff --git a/app/services/topic_timestamp_changer.rb b/app/services/topic_timestamp_changer.rb
index a979d0a..8dffa33 100644
--- a/app/services/topic_timestamp_changer.rb
+++ b/app/services/topic_timestamp_changer.rb
@@ -43,7 +43,7 @@ class TopicTimestampChanger
   end
 
   def update_topic(last_posted_at)
-    @topic.update_attributes(
+    @topic.update(
       created_at: @timestamp,
       updated_at: @timestamp,
       bumped_at: @timestamp,
@@ -52,6 +52,6 @@ class TopicTimestampChanger
   end
 
   def update_post(post, timestamp)
-    post.update_attributes(created_at: timestamp, updated_at: timestamp)
+    post.update(created_at: timestamp, updated_at: timestamp)
   end
 end
diff --git a/app/services/user_merger.rb b/app/services/user_merger.rb
index 1f5709f..7635c03 100644
--- a/app/services/user_merger.rb
+++ b/app/services/user_merger.rb
@@ -354,7 +354,7 @@ class UserMerger
 
   def delete_source_user
     @source_user.reload
-    @source_user.update_attributes(
+    @source_user.update(
       admin: false,
       email: "#{@source_user.username}_#{SecureRandom.hex}@no-email.invalid"
     )
diff --git a/lib/email/processor.rb b/lib/email/processor.rb
index a721244..469acfa 100644
--- a/lib/email/processor.rb
+++ b/lib/email/processor.rb
@@ -125,7 +125,7 @@ module Email
     end
 
     def set_incoming_email_rejection_message(incoming_email, message)
-      incoming_email.update_attributes!(rejection_message: message) if incoming_email
+      incoming_email.update!(rejection_message: message) if incoming_email
     end
 
     def log_email_process_failure(mail_string, exception)

[... diff too long, it was truncated ...]

GitHub sha: 45285f14

1 Like