From 3c1883dac20a76172718740061b4cecd2a9854bb Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 19 Mar 2021 15:55:14 +0000 Subject: [PATCH] Remove use of :source polymorphic association for return adjustments --- app/models/spree/adjustment.rb | 2 +- spec/models/spree/adjustment_spec.rb | 2 +- spec/models/spree/return_authorization_spec.rb | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index ef34d0eb9f..7e6e314b4c 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -66,7 +66,7 @@ module Spree scope :optional, -> { where(mandatory: false) } scope :charge, -> { where('amount >= 0') } scope :credit, -> { where('amount < 0') } - scope :return_authorization, -> { where(source_type: "Spree::ReturnAuthorization") } + scope :return_authorization, -> { where(originator_type: "Spree::ReturnAuthorization") } scope :inclusive, -> { where(included: true) } scope :additional, -> { where(included: false) } diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 39e48cafc6..c1af27f7fe 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -9,7 +9,7 @@ module Spree describe "scopes" do let!(:arbitrary_adjustment) { create(:adjustment, source: nil, label: "Arbitrary") } - let!(:return_authorization_adjustment) { create(:adjustment, source: create(:return_authorization)) } + let!(:return_authorization_adjustment) { create(:adjustment, originator: create(:return_authorization)) } it "returns return_authorization adjustments" do expect(Spree::Adjustment.return_authorization.to_a).to eq [return_authorization_adjustment] diff --git a/spec/models/spree/return_authorization_spec.rb b/spec/models/spree/return_authorization_spec.rb index d37bac00ed..5fa696f522 100644 --- a/spec/models/spree/return_authorization_spec.rb +++ b/spec/models/spree/return_authorization_spec.rb @@ -82,11 +82,15 @@ describe Spree::ReturnAuthorization do it "should add credit for specified amount" do return_authorization.amount = 20 - mock_adjustment = double - expect(mock_adjustment).to receive(:source=).with(return_authorization) - expect(mock_adjustment).to receive(:adjustable=).with(order) - expect(mock_adjustment).to receive(:save) - expect(Spree::Adjustment).to receive(:new).with(amount: -20, label: Spree.t(:rma_credit)).and_return(mock_adjustment) + + expect(Spree::Adjustment).to receive(:create).with( + amount: -20, + label: I18n.t('spree.rma_credit'), + order: order, + adjustable: order, + originator: return_authorization + ) + return_authorization.receive! end