From d758787a7270964abf04f82be998f1df52e18d57 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 26 May 2020 11:26:20 +0100 Subject: [PATCH] Make enterprises controller spec assert the corrrect state of current_distributor This validates bug #5496 is fixed --- spec/controllers/enterprises_controller_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 43cc38fa71..f67972563f 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe EnterprisesController, type: :controller do describe "shopping for a distributor" do + let(:user) { create(:user) } let(:order) { controller.current_order(true) } let(:line_item) { create(:line_item) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } @@ -17,10 +18,23 @@ describe EnterprisesController, type: :controller do it "sets the shop as the distributor on the order when shopping for the distributor" do spree_get :shop, id: distributor + expect(controller.current_distributor).to eq(distributor) expect(controller.current_order.distributor).to eq(distributor) expect(controller.current_order.order_cycle).to be_nil end + context "when user is logged in" do + before { allow(controller).to receive(:spree_current_user) { user } } + + it "sets the shop as the distributor on the order when shopping for the distributor" do + spree_get :shop, id: distributor + + expect(controller.current_distributor).to eq(distributor) + expect(controller.current_order.distributor).to eq(distributor) + expect(controller.current_order.order_cycle).to be_nil + end + end + it "sorts order cycles by the distributor's preferred ordering attr" do distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_close_at') spree_get :shop, id: distributor @@ -32,7 +46,6 @@ describe EnterprisesController, type: :controller do end context "using FilterOrderCycles tag rules" do - let(:user) { create(:user) } let!(:order_cycle3) { create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago, orders_close_at: 4.days.from_now) } let!(:oc3_exchange) { order_cycle3.exchanges.outgoing.to_enterprise(distributor).first } let(:customer) { create(:customer, user: user, enterprise: distributor) }