mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Remove use of :source polymorphic association for return adjustments
This commit is contained in:
@@ -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) }
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user