Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ! from assign_default_user_addresses! #2019

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/controllers/spree/checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down