Remove use of :source polymorphic association for return adjustments

This commit is contained in:
Matt-Yorkley
2021-03-19 15:55:14 +00:00
parent 8db598bff7
commit 3c1883dac2
3 changed files with 11 additions and 7 deletions

View File

@@ -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) }

View File

@@ -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]

View File

@@ -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