mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add #vouchers, return an array of voucher adjustments
This commit is contained in:
committed by
Maikel Linke
parent
9b680e1a92
commit
3ec58d8791
@@ -618,6 +618,10 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
def vouchers
|
||||
adjustments.where(originator_type: 'Voucher')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fee_handler
|
||||
|
||||
@@ -1430,4 +1430,21 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#vouchers" do
|
||||
let(:voucher) { Voucher.create(code: 'new_code', enterprise: order.distributor) }
|
||||
|
||||
context "when no voucher adjustment" do
|
||||
it 'returns an empty array' do
|
||||
expect(order.vouchers).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
it "returns an array of voucher adjusment" do
|
||||
order.save!
|
||||
expected_adjustments = Array.new(2) { voucher.create_adjustment(voucher.code, order) }
|
||||
|
||||
expect(order.vouchers).to eq(expected_adjustments)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user