diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index ac95e8659c4..5a1f890b55f 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -698,7 +698,10 @@ def ship_address_attributes=(attributes) self.ship_address = Spree::Address.immutable_merge(ship_address, attributes) end - def assign_default_user_addresses! + # Assigns a default bill_address and ship_address to the order based on the + # associated user's bill_address and ship_address. + # @note This doesn't persist the change bill_address or ship_address + def assign_default_user_addresses if user # this is one of 2 places still using User#bill_address self.bill_address ||= user.bill_address if user.bill_address.try!(:valid?) @@ -707,8 +710,11 @@ def assign_default_user_addresses! self.ship_address ||= user.ship_address if user.ship_address.try!(:valid?) && checkout_steps.include?("delivery") end end - alias_method :assign_default_addresses!, :assign_default_user_addresses! - deprecate assign_default_addresses!: :assign_default_user_addresses!, deprecator: Spree::Deprecation + + alias_method :assign_default_user_addresses!, :assign_default_user_addresses + deprecate assign_default_user_addresses!: :assign_default_user_addresses, deprecator: Spree::Deprecation + alias_method :assign_default_addresses!, :assign_default_user_addresses + deprecate assign_default_addresses!: :assign_default_user_addresses, deprecator: Spree::Deprecation def persist_user_address! if !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb index 81ef4b2b7a4..6aeaa9e798c 100644 --- a/core/app/models/spree/order/checkout.rb +++ b/core/app/models/spree/order/checkout.rb @@ -90,7 +90,7 @@ def define_state_machine! before_transition from: :cart, do: :ensure_line_items_present if states[:address] - before_transition to: :address, do: :assign_default_user_addresses! + before_transition to: :address, do: :assign_default_user_addresses before_transition from: :address, do: :persist_user_address! end diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb index a688a247756..78ec30795eb 100644 --- a/core/spec/models/spree/order_spec.rb +++ b/core/spec/models/spree/order_spec.rb @@ -785,10 +785,10 @@ def merge!(other_order, user = nil) end end - context "#assign_default_user_addresses!" do + context "#assign_default_user_addresses" do let(:order) { Spree::Order.new } - subject { order.assign_default_user_addresses! } + subject { order.assign_default_user_addresses } context "when no user is associated to the order" do it "does not associate any bill address" do diff --git a/frontend/app/controllers/spree/checkout_controller.rb b/frontend/app/controllers/spree/checkout_controller.rb index 8dc6dae7c38..d2952c9e3e1 100644 --- a/frontend/app/controllers/spree/checkout_controller.rb +++ b/frontend/app/controllers/spree/checkout_controller.rb @@ -171,7 +171,7 @@ def setup_for_current_state end def before_address - @order.assign_default_user_addresses! + @order.assign_default_user_addresses # If the user has a default address, the previous method call takes care # of setting that; but if he doesn't, we need to build an empty one here default = {country_id: Spree::Country.default.id} diff --git a/frontend/spec/controllers/spree/checkout_controller_spec.rb b/frontend/spec/controllers/spree/checkout_controller_spec.rb index c4fb2b370eb..cb8b8c9dc16 100644 --- a/frontend/spec/controllers/spree/checkout_controller_spec.rb +++ b/frontend/spec/controllers/spree/checkout_controller_spec.rb @@ -145,7 +145,7 @@ def post_address context 'landing to address page' do it "tries to associate user addresses to order" do - expect(order).to receive(:assign_default_user_addresses!) + expect(order).to receive(:assign_default_user_addresses) get :edit end end