From 70f7d767234e0e7bd38b8ba583c16c1cc2be40b7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 23 Dec 2020 08:29:12 +0000 Subject: [PATCH] Delete dead code #eligible_for_originator? This check is used only by Spree::Promotion objects, which are not used in OFN. There are no objects which can be originators of an adjustment that respond to #eligible? in this way, so the method always returns true. --- app/models/spree/adjustment.rb | 10 +------ spec/models/spree/adjustment_spec.rb | 40 ---------------------------- 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index 8d398860fc..cb965b8aef 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -86,18 +86,10 @@ module Spree # Update the boolean _eligible_ attribute which determines which adjustments # count towards the order's adjustment_total. def set_eligibility - result = mandatory || (amount != 0 && eligible_for_originator?) + result = mandatory || amount != 0 update_column(:eligible, result) end - # Allow originator of the adjustment to perform an additional eligibility of the adjustment - # Should return _true_ if originator is absent or doesn't implement _eligible?_ - def eligible_for_originator? - return true if originator.nil? - - !originator.respond_to?(:eligible?) || originator.eligible?(source) - end - # Update both the eligibility and amount of the adjustment. Adjustments # delegate updating of amount to their Originator when present, but only if # +locked+ is false. Adjustments that are +locked+ will never change their amount. diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index ef66733ec1..766cc9106b 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -76,20 +76,6 @@ module Spree adjustment.set_eligibility expect(adjustment).to be_eligible end - - it "should be eligible if not mandatory and eligible for the originator" do - adjustment.mandatory = false - allow(adjustment).to receive_messages(eligible_for_originator?: true) - adjustment.set_eligibility - expect(adjustment).to be_eligible - end - - it "should not be eligible if not mandatory not eligible for the originator" do - adjustment.mandatory = false - allow(adjustment).to receive_messages(eligible_for_originator?: false) - adjustment.set_eligibility - expect(adjustment).to_not be_eligible - end end end @@ -137,32 +123,6 @@ module Spree end end - context "#eligible_for_originator?" do - context "with no originator" do - specify { expect(adjustment).to be_eligible_for_originator } - end - - context "with originator that doesn't have 'eligible?'" do - before { adjustment.originator = build(:tax_rate) } - specify { expect(adjustment).to be_eligible_for_originator } - end - - context "with originator that has 'eligible?'" do - let(:originator) { Spree::TaxRate.new } - before { adjustment.originator = originator } - - context "and originator is eligible for order" do - before { allow(originator).to receive_messages(eligible?: true) } - specify { expect(adjustment).to be_eligible_for_originator } - end - - context "and originator is not eligible for order" do - before { allow(originator).to receive_messages(eligible?: false) } - specify { expect(adjustment).to_not be_eligible_for_originator } - end - end - end - context "#display_amount" do before { adjustment.amount = 10.55 }