From c0b33de0f01b2402a60cc11229a345efe94428de Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 14 Feb 2021 14:05:29 +0000 Subject: [PATCH] Move #adjustment_label to shipment --- app/models/spree/shipment.rb | 8 ++++++-- app/models/spree/shipping_method.rb | 4 ---- spec/models/spree/shipment_spec.rb | 15 +++------------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 38d0f49a14..305dfba81b 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -265,12 +265,12 @@ module Spree def ensure_correct_adjustment if adjustment adjustment.originator = shipping_method - adjustment.label = shipping_method.adjustment_label + adjustment.label = adjustment_label adjustment.amount = selected_shipping_rate.cost if adjustment.open? adjustment.save! adjustment.reload elsif selected_shipping_rate_id - shipping_method.create_adjustment(shipping_method.adjustment_label, + shipping_method.create_adjustment(adjustment_label, self, self, true, @@ -282,6 +282,10 @@ module Spree update_adjustment_included_tax if adjustment end + def adjustment_label + I18n.t('shipping') + end + private def manifest_unstock(item) diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb index 38f8a41438..909ed9c99f 100644 --- a/app/models/spree/shipping_method.rb +++ b/app/models/spree/shipping_method.rb @@ -54,10 +54,6 @@ module Spree where("spree_shipping_methods.display_on is null OR spree_shipping_methods.display_on = ''") } - def adjustment_label - I18n.t('shipping') - end - # Here we allow checkout with shipping methods without zones (see issue #3928 for details) # and also checkout with addresses outside of the zones of the selected shipping method # This method could be used, like in Spree, to validate shipping method zones on checkout. diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb index 4ebb1ff597..255d1d8833 100644 --- a/spec/models/spree/shipment_spec.rb +++ b/spec/models/spree/shipment_spec.rb @@ -386,20 +386,11 @@ describe Spree::Shipment do it "should create adjustment when not present" do allow(shipment).to receive_messages(selected_shipping_rate_id: 1) - expect(shipping_method).to receive(:create_adjustment).with(shipping_method.adjustment_label, + expect(shipping_method).to receive(:create_adjustment).with(shipment.adjustment_label, shipment, shipment, true, "open") shipment.__send__(:ensure_correct_adjustment) end - # Regression test for #3138 - it "should use the shipping method's adjustment label" do - allow(shipment).to receive_messages(selected_shipping_rate_id: 1) - allow(shipping_method).to receive_messages(adjustment_label: "Foobar") - expect(shipping_method).to receive(:create_adjustment).with("Foobar", shipment, - shipment, true, "open") - shipment.__send__(:ensure_correct_adjustment) - end - it "should update originator when adjustment is present" do allow(shipment). to receive_messages(selected_shipping_rate: Spree::ShippingRate.new(cost: 10.00)) @@ -407,7 +398,7 @@ describe Spree::Shipment do allow(shipment).to receive_messages(adjustment: adjustment, update_columns: true) allow(adjustment).to receive(:open?) { true } expect(shipment.adjustment).to receive(:originator=).with(shipping_method) - expect(shipment.adjustment).to receive(:label=).with(shipping_method.adjustment_label) + expect(shipment.adjustment).to receive(:label=).with(shipment.adjustment_label) expect(shipment.adjustment).to receive(:amount=).with(10.00) allow(shipment.adjustment).to receive(:save!) expect(shipment.adjustment).to receive(:reload) @@ -421,7 +412,7 @@ describe Spree::Shipment do allow(shipment).to receive_messages(adjustment: adjustment, update_columns: true) allow(adjustment).to receive(:open?) { false } expect(shipment.adjustment).to receive(:originator=).with(shipping_method) - expect(shipment.adjustment).to receive(:label=).with(shipping_method.adjustment_label) + expect(shipment.adjustment).to receive(:label=).with(shipment.adjustment_label) expect(shipment.adjustment).not_to receive(:amount=).with(10.00) allow(shipment.adjustment).to receive(:save!) expect(shipment.adjustment).to receive(:reload)