From 275326eaa65ef3a62cddd857d805d9d964b28e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Tue, 28 Oct 2025 19:13:26 +0100 Subject: [PATCH] Replace alias_attribute with alias_method --- app/models/customer.rb | 6 ++++-- app/models/spree/order.rb | 6 ++++-- app/models/subscription.rb | 6 ++++-- config/environments/test.rb | 3 --- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 476dbc95f8..b514c0e1d0 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -25,11 +25,13 @@ class Customer < ApplicationRecord before_destroy :update_orders_and_delete_canceled_subscriptions belongs_to :bill_address, class_name: "Spree::Address", optional: true - alias_attribute :billing_address, :bill_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= accepts_nested_attributes_for :bill_address belongs_to :ship_address, class_name: "Spree::Address", optional: true - alias_attribute :shipping_address, :ship_address + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= accepts_nested_attributes_for :ship_address validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true } diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 0ba30064c5..160041bfff 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -35,10 +35,12 @@ module Spree belongs_to :created_by, class_name: "Spree::User", optional: true belongs_to :bill_address, class_name: 'Spree::Address', optional: true - alias_attribute :billing_address, :bill_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= belongs_to :ship_address, class_name: 'Spree::Address', optional: true - alias_attribute :shipping_address, :ship_address + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= has_many :state_changes, as: :stateful, dependent: :destroy has_many :line_items, -> { diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 4509c1ac75..8e2df44bd6 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -24,8 +24,10 @@ class Subscription < ApplicationRecord has_many :proxy_orders, dependent: :destroy has_many :orders, through: :proxy_orders - alias_attribute :billing_address, :bill_address - alias_attribute :shipping_address, :ship_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= accepts_nested_attributes_for :subscription_line_items, allow_destroy: true accepts_nested_attributes_for :bill_address, :ship_address diff --git a/config/environments/test.rb b/config/environments/test.rb index 8c7562aee0..9fd47d1c3e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -79,9 +79,6 @@ Rails.application.configure do "Passing the class as positional argument", - # Spree::Order model aliases `bill_address`, but `bill_address` is not an attribute. Starting in Rails 7.2, alias_attribute with non-attribute targets will raise. Use `alias_method :billing_address, :bill_address` or define the method manually. (called from initialize at app/models/spree/order.rb:188) - "alias_attribute with non-attribute targets will raise", - # Spree::CreditCard model aliases `cc_type` and has a method called `cc_type=` defined. Starting in Rails 7.2 `brand=` will not be calling `cc_type=` anymore. You may want to additionally define `brand=` to preserve the current behavior. "model aliases",