From caf4441fa345b34ad9fb8dec511cc843c5a26d56 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 14 Feb 2019 13:11:49 +0100 Subject: [PATCH] Do not mutate config's state in specs --- spec/models/spree/adjustment_spec.rb | 16 ++++++++++------ spec/models/spree/order_spec.rb | 12 ++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index dca4da1cfe..a8693843b0 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -75,17 +75,19 @@ module Spree end describe "when tax on shipping is disabled" do - before { Config.shipment_inc_vat = false } + before do + allow(Config).to receive(:shipment_inc_vat).and_return(false) + end it "records 0% tax on shipment adjustments" do - Config.shipping_tax_rate = 0 + allow(Config).to receive(:shipping_tax_rate).and_return(0) order.shipments = [shipment] expect(order.adjustments.first.included_tax).to eq(0) end it "records 0% tax on shipments when a rate is set but shipment_inc_vat is false" do - Config.shipping_tax_rate = 0.25 + allow(Config).to receive(:shipping_tax_rate).and_return(0.25) order.shipments = [shipment] expect(order.adjustments.first.included_tax).to eq(0) @@ -93,10 +95,12 @@ module Spree end describe "when tax on shipping is enabled" do - before { Config.shipment_inc_vat = true } + before do + allow(Config).to receive(:shipment_inc_vat).and_return(true) + end it "takes the shipment adjustment tax included from the system setting" do - Config.shipping_tax_rate = 0.25 + allow(Config).to receive(:shipping_tax_rate).and_return(0.25) order.shipments = [shipment] # Finding the tax included in an amount that's already inclusive of tax: @@ -107,7 +111,7 @@ module Spree end it "records 0% tax on shipments when shipping_tax_rate is not set" do - Config.shipping_tax_rate = nil + allow(Config).to receive(:shipping_tax_rate).and_return(0) order.shipments = [shipment] expect(order.adjustments.first.included_tax).to eq(0) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index cc95a675a4..316c186787 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -229,8 +229,8 @@ describe Spree::Order do context "with a taxed shipment" do before do - Spree::Config.shipment_inc_vat = true - Spree::Config.shipping_tax_rate = 0.25 + allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true) + allow(Spree::Config).to receive(:shipping_tax_rate).and_return(0.25) end let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) } @@ -261,8 +261,8 @@ describe Spree::Order do describe "getting the total tax" do before do - Spree::Config.shipment_inc_vat = true - Spree::Config.shipping_tax_rate = 0.25 + allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true) + allow(Spree::Config).to receive(:shipping_tax_rate).and_return(0.25) end let(:order) { create(:order) } @@ -321,8 +321,8 @@ describe Spree::Order do end before do - Spree::Config.shipment_inc_vat = true - Spree::Config.shipping_tax_rate = tax_rate15.amount + allow(Spree::Config).to receive(:shipment_inc_vat).and_return(true) + allow(Spree::Config).to receive(:shipping_tax_rate).and_return(tax_rate15.amount) end let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 46.0)) }