From bca5ee226da3baa4b706e43bf6c54f761b5692d4 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 10 Mar 2026 13:57:16 +1100 Subject: [PATCH] Add spec to test the correct customer is linked --- spec/controllers/enterprises_controller_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index dfe87211da..948c470753 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -39,6 +39,21 @@ RSpec.describe EnterprisesController do expect(controller.current_order.distributor).to eq(distributor) expect(controller.current_order.order_cycle).to be_nil end + + context "when customer doesn't belong to the order's distributor" do + it "sets the order's customer to distributor's customer" do + expected_customer = create(:customer, user:, enterprise: distributor) + + # 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(expected_customer) + end + end end it "sorts order cycles by the distributor's preferred ordering attr" do