diff --git a/app/models/spree/calculator/price_sack_decorator.rb b/app/models/spree/calculator/price_sack_decorator.rb index 41aeabf330..b474f77861 100644 --- a/app/models/spree/calculator/price_sack_decorator.rb +++ b/app/models/spree/calculator/price_sack_decorator.rb @@ -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 diff --git a/spec/models/spree/calculator/price_sack_spec.rb b/spec/models/spree/calculator/price_sack_spec.rb index 9b0a38d0e8..921b657f88 100644 --- a/spec/models/spree/calculator/price_sack_spec.rb +++ b/spec/models/spree/calculator/price_sack_spec.rb @@ -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