mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #5251 from luisramos0/Issue4654
Change Result of PriceSack Calculation from Integers to Floats, clone #4812
This commit is contained in:
@@ -17,9 +17,9 @@ module Spree
|
||||
order_amount = line_items_for(object).map { |x| x.price * x.quantity }.sum
|
||||
|
||||
if order_amount < min
|
||||
cost = preferred_normal_amount.to_i
|
||||
cost = preferred_normal_amount.to_f
|
||||
elsif order_amount >= min
|
||||
cost = preferred_discount_amount.to_i
|
||||
cost = preferred_discount_amount.to_f
|
||||
end
|
||||
|
||||
cost
|
||||
|
||||
@@ -8,11 +8,11 @@ describe Spree::Calculator::PriceSack do
|
||||
calculator.preferred_discount_amount = 1
|
||||
calculator
|
||||
end
|
||||
|
||||
let(:line_item) { build(:line_item, price: price, quantity: 2) }
|
||||
|
||||
context 'when the order amount is below preferred minimal' do
|
||||
let(:price) { 2 }
|
||||
|
||||
it "uses the preferred normal amount" do
|
||||
expect(calculator.compute(line_item)).to eq(10)
|
||||
end
|
||||
@@ -20,11 +20,35 @@ describe Spree::Calculator::PriceSack do
|
||||
|
||||
context 'when the order amount is above preferred minimal' do
|
||||
let(:price) { 6 }
|
||||
|
||||
it "uses the preferred discount amount" do
|
||||
expect(calculator.compute(line_item)).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "preferred discount amount is float" do
|
||||
before do
|
||||
calculator.preferred_normal_amount = 10.4
|
||||
calculator.preferred_discount_amount = 1.2
|
||||
end
|
||||
|
||||
context 'when the order amount is below preferred minimal' do
|
||||
let(:price) { 2 }
|
||||
|
||||
it "uses the float preferred normal amount" do
|
||||
expect(calculator.compute(line_item)).to eq(10.4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the order amount is above preferred minimal' do
|
||||
let(:price) { 6 }
|
||||
|
||||
it "uses the float preferred discount amount" do
|
||||
expect(calculator.compute(line_item)).to eq(1.2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "extends LocalizedNumber" do
|
||||
it_behaves_like "a model using the LocalizedNumber module", [:preferred_minimal_amount, :preferred_normal_amount, :preferred_discount_amount]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user