Per review, remove customer when no existing customer

This commit is contained in:
Gaetan Craig-Riou
2026-03-10 15:20:56 +11:00
parent bca5ee226d
commit d706b3a6c2
3 changed files with 16 additions and 3 deletions

View File

@@ -21,7 +21,7 @@ module Orders
def reset_other!(current_user, current_customer)
reset_user(current_user)
reset_order_cycle(current_customer)
order.customer = current_customer if current_customer.present?
order.customer = current_customer
order.save!
end

View File

@@ -29,6 +29,19 @@ RSpec.describe EnterprisesController do
expect(controller.current_order.order_cycle).to be_nil
end
context "when the order is linked to a customer" do
it "removes the customer" do
# Make sure the order is linked to a customer
customer = create(:customer)
order.customer = customer
order.save!
expect do
get :shop, params: { id: distributor }
end.to change { controller.current_order.customer }.to(nil)
end
end
context "when user is logged in" do
before { allow(controller).to receive(:spree_current_user) { user } }

View File

@@ -70,10 +70,10 @@ RSpec.describe Orders::CartResetService do
end
context "when customer is missing" do
it "does not reset the customer" do
it "removes the customer" do
expect do
described_class.new(order, distributor.id.to_s).reset_other!(nil, nil)
end.not_to change { order.customer }
end.to change { order.customer }.to(nil)
end
end