From bf685c70745e0e096245d60965a13898a7413dbb Mon Sep 17 00:00:00 2001 From: kitcommerce <262714811+kitcommerce@users.noreply.github.com> Date: Fri, 20 Feb 2026 01:10:52 -0500 Subject: [PATCH] WA-NEW-009: Replace update_attributes calls with update/update! --- .../models/workarea/bulk_action/product_edit.rb | 6 +++--- core/app/models/workarea/data_file/export.rb | 2 +- core/app/models/workarea/order.rb | 4 ++-- core/app/models/workarea/pricing/discount.rb | 2 +- .../models/workarea/pricing/discount/code_list.rb | 2 +- core/app/models/workarea/pricing/request.rb | 4 ++-- core/app/models/workarea/reports/export.rb | 2 +- core/app/models/workarea/user/authorization.rb | 2 +- core/app/models/workarea/user/login.rb | 2 +- core/app/models/workarea/user/password_reset.rb | 14 +++++++++++--- core/app/seeds/workarea/dynamic_content_seeds.rb | 2 +- core/app/seeds/workarea/orders_seeds.rb | 2 +- core/app/seeds/workarea/search_settings_seeds.rb | 2 +- core/app/services/workarea/login.rb | 2 +- core/app/services/workarea/save_taxonomy.rb | 4 ++-- .../workers/workarea/save_user_order_details.rb | 2 +- core/lib/workarea/tasks/migrate.rb | 2 +- 17 files changed, 32 insertions(+), 24 deletions(-) diff --git a/core/app/models/workarea/bulk_action/product_edit.rb b/core/app/models/workarea/bulk_action/product_edit.rb index a53e9a3a90..49d7b7574e 100644 --- a/core/app/models/workarea/bulk_action/product_edit.rb +++ b/core/app/models/workarea/bulk_action/product_edit.rb @@ -25,7 +25,7 @@ def act_on!(product) apply_pricing!(product) apply_inventory!(product) - product.update_attributes!(settings) + product.update!(settings) end end @@ -54,7 +54,7 @@ def apply_pricing!(product) sku_pricing = pricing.dup changes = sku_pricing.delete('prices') - sku.update_attributes!(sku_pricing) + sku.update!(sku_pricing) sku.prices.build unless sku.prices.any? sku.prices.each do |price| @@ -77,7 +77,7 @@ def apply_inventory!(product) collection = Inventory::Collection.new(product.skus) collection.records.each do |record| - record.update_attributes!(inventory) + record.update!(inventory) end end end diff --git a/core/app/models/workarea/data_file/export.rb b/core/app/models/workarea/data_file/export.rb index 974f25f0bf..55d84989af 100644 --- a/core/app/models/workarea/data_file/export.rb +++ b/core/app/models/workarea/data_file/export.rb @@ -15,7 +15,7 @@ class Export def process! set(started_at: Time.current) run_callbacks(:process) { format.export! } - update_attributes!(file: tempfile.tap(&:close), completed_at: Time.current) + update!(file: tempfile.tap(&:close), completed_at: Time.current) end def models diff --git a/core/app/models/workarea/order.rb b/core/app/models/workarea/order.rb index bffe440a03..e037b2f0e2 100644 --- a/core/app/models/workarea/order.rb +++ b/core/app/models/workarea/order.rb @@ -266,10 +266,10 @@ def update_item(id, attributes) if existing_item.present? && existing_item.id.to_s != id.to_s item = items.find(id) - existing_item.update_attributes(quantity: existing_item.quantity + (attributes[:quantity] || item.quantity)) + existing_item.update(quantity: existing_item.quantity + (attributes[:quantity] || item.quantity)) item.delete else - items.find(id).update_attributes(attributes) + items.find(id).update(attributes) end end diff --git a/core/app/models/workarea/pricing/discount.rb b/core/app/models/workarea/pricing/discount.rb index 09a34718cd..f78c55094a 100644 --- a/core/app/models/workarea/pricing/discount.rb +++ b/core/app/models/workarea/pricing/discount.rb @@ -179,7 +179,7 @@ def <=>(other) # Automatically deactivates a discount # def auto_deactivate! - update_attributes!(active: false, auto_deactivated_at: Time.current) + update!(active: false, auto_deactivated_at: Time.current) end # Whether this discount qualifies for this order. It does so diff --git a/core/app/models/workarea/pricing/discount/code_list.rb b/core/app/models/workarea/pricing/discount/code_list.rb index 112d7f70e6..00075e1c5b 100644 --- a/core/app/models/workarea/pricing/discount/code_list.rb +++ b/core/app/models/workarea/pricing/discount/code_list.rb @@ -51,7 +51,7 @@ class CodeList # def generate_promo_codes! count.times { generate_code } - update_attributes!(generation_completed_at: Time.current) + update!(generation_completed_at: Time.current) end # Whether the list finished generating its codes diff --git a/core/app/models/workarea/pricing/request.rb b/core/app/models/workarea/pricing/request.rb index af9f6247fc..8c51f8de6d 100644 --- a/core/app/models/workarea/pricing/request.rb +++ b/core/app/models/workarea/pricing/request.rb @@ -137,7 +137,7 @@ def all_skus def save_order # as_document won't contain items in the hash if there isn't any items left. # ensure the items get cleared out when this happens - @persisted_order.update_attributes!(order.as_document.reverse_merge(items: [])) + @persisted_order.update!(order.as_document.reverse_merge(items: [])) cache_key.order = @persisted_order @persisted_order.set(pricing_cache_key: cache_key.to_s) end @@ -149,7 +149,7 @@ def save_shippings s.id == tmp_shipping.id end - matching_shipping.update_attributes!(shipping_attrs) + matching_shipping.update!(shipping_attrs) end end end diff --git a/core/app/models/workarea/reports/export.rb b/core/app/models/workarea/reports/export.rb index 6419fc6d5f..1b4d61dbc0 100644 --- a/core/app/models/workarea/reports/export.rb +++ b/core/app/models/workarea/reports/export.rb @@ -32,7 +32,7 @@ def name def process! set(started_at: Time.current) CSV.open(temp_path, 'w') { |csv| yield(csv) } - update_attributes!(file: temp_path, completed_at: Time.current) + update!(file: temp_path, completed_at: Time.current) end def report diff --git a/core/app/models/workarea/user/authorization.rb b/core/app/models/workarea/user/authorization.rb index 5a74eab872..4acb03c39a 100644 --- a/core/app/models/workarea/user/authorization.rb +++ b/core/app/models/workarea/user/authorization.rb @@ -41,7 +41,7 @@ def status_email_recipients end def mark_impersonated_by!(user) - update_attributes!( + update!( last_impersonated_by_id: user.id, last_impersonated_at: Time.current ) diff --git a/core/app/models/workarea/user/login.rb b/core/app/models/workarea/user/login.rb index 0cae370897..baade4a44e 100644 --- a/core/app/models/workarea/user/login.rb +++ b/core/app/models/workarea/user/login.rb @@ -55,7 +55,7 @@ def unlock_login! end def update_login!(request) - update_attributes!( + update!( ip_address: request.ip, user_agent: request.user_agent ) diff --git a/core/app/models/workarea/user/password_reset.rb b/core/app/models/workarea/user/password_reset.rb index 005a2f00e8..c630374c4c 100644 --- a/core/app/models/workarea/user/password_reset.rb +++ b/core/app/models/workarea/user/password_reset.rb @@ -25,12 +25,20 @@ def complete(new_password) return false end - if user.update_attributes(password: new_password) + if user.update(password: new_password) destroy else - user.errors.each do |attribute, error| - errors.add(attribute, error) + # Rails 7 yields ActiveModel::Error objects; older Rails yields + # [attribute, message] pairs. + user.errors.each do |error| + if error.respond_to?(:attribute) && error.respond_to?(:message) + errors.add(error.attribute, error.message) + else + attribute, message = error + errors.add(attribute, message) + end end + false end end diff --git a/core/app/seeds/workarea/dynamic_content_seeds.rb b/core/app/seeds/workarea/dynamic_content_seeds.rb index 7d4e0398d4..97dfb30b39 100644 --- a/core/app/seeds/workarea/dynamic_content_seeds.rb +++ b/core/app/seeds/workarea/dynamic_content_seeds.rb @@ -46,7 +46,7 @@ def content_blocks_from_file(path) def set_content(contentable, blocks) content = Content.for(contentable) - content.update_attributes!(blocks: blocks) + content.update!(blocks: blocks) end def seed_images diff --git a/core/app/seeds/workarea/orders_seeds.rb b/core/app/seeds/workarea/orders_seeds.rb index 61c4adf5a0..342ca75669 100644 --- a/core/app/seeds/workarea/orders_seeds.rb +++ b/core/app/seeds/workarea/orders_seeds.rb @@ -26,7 +26,7 @@ def create_order user = User.sample if user.first_name.blank? || user.last_name.blank? - user.update_attributes!( + user.update!( first_name: Faker::Name.first_name, last_name: Faker::Name.last_name ) diff --git a/core/app/seeds/workarea/search_settings_seeds.rb b/core/app/seeds/workarea/search_settings_seeds.rb index 82d5119b5b..1ecb8c7e29 100644 --- a/core/app/seeds/workarea/search_settings_seeds.rb +++ b/core/app/seeds/workarea/search_settings_seeds.rb @@ -8,7 +8,7 @@ def perform private def add_filters - Search::Settings.current.update_attributes!( + Search::Settings.current.update!( terms_facets: %w(Color Size), range_facets: { 'price' => [ diff --git a/core/app/services/workarea/login.rb b/core/app/services/workarea/login.rb index 13b821e847..00234d0ce6 100644 --- a/core/app/services/workarea/login.rb +++ b/core/app/services/workarea/login.rb @@ -29,7 +29,7 @@ def perform if current_order.started_checkout? Checkout.new(current_order).continue_as(user) else - current_order.update_attributes!(user_id: user.id) + current_order.update!(user_id: user.id) end end diff --git a/core/app/services/workarea/save_taxonomy.rb b/core/app/services/workarea/save_taxonomy.rb index 26900f528d..322e9913bf 100644 --- a/core/app/services/workarea/save_taxonomy.rb +++ b/core/app/services/workarea/save_taxonomy.rb @@ -16,7 +16,7 @@ def initialize(taxon, params) end def perform - @taxon.update_attributes!(parent_id: @params[:parent_id]) + @taxon.update!(parent_id: @params[:parent_id]) @taxon.move_to_position(@params[:position]) if @params[:position].present? set_taxonomy_slug @@ -26,7 +26,7 @@ def set_taxonomy_slug Release.with_current(nil) do Sidekiq::Callbacks.disable(RedirectNavigableSlugs) do slug = FindTaxonomySlug.new(@taxon.navigable, @taxon).slug - @taxon.navigable.update_attributes!(slug: slug) if slug.present? + @taxon.navigable.update!(slug: slug) if slug.present? end end end diff --git a/core/app/workers/workarea/save_user_order_details.rb b/core/app/workers/workarea/save_user_order_details.rb index bc6d779501..d30e9621f5 100644 --- a/core/app/workers/workarea/save_user_order_details.rb +++ b/core/app/workers/workarea/save_user_order_details.rb @@ -24,7 +24,7 @@ def save_payment_details(order, user) user.auto_save_billing_address(billing_address) if user.public_info.blank? - user.update_attributes!( + user.update!( first_name: billing_address[:first_name], last_name: billing_address[:last_name] ) diff --git a/core/lib/workarea/tasks/migrate.rb b/core/lib/workarea/tasks/migrate.rb index 8067a13538..e88a30a996 100644 --- a/core/lib/workarea/tasks/migrate.rb +++ b/core/lib/workarea/tasks/migrate.rb @@ -15,7 +15,7 @@ def v3_5 Workarea::Scheduler.delete(release.undo_job_id) - release.update_attributes!(undo_at: nil, undo_job_id: nil) + release.update!(undo_at: nil, undo_job_id: nil) count += 1 end