diff --git a/core/app/models/spree/calculator.rb b/core/app/models/spree/calculator.rb index 7c931ec39c1..57a8449c718 100644 --- a/core/app/models/spree/calculator.rb +++ b/core/app/models/spree/calculator.rb @@ -21,7 +21,7 @@ class Calculator < Spree::Base # Spree::ShippingRate) # @param ... [args, kwargs] Additional arguments passed to the specific compute method # - # @return [BigDecimal, Numeric] The computed amount + # @return [BigDecimal] The computed amount # # @raise [NotImplementedError] If the calculator doesn't implement the required compute method # diff --git a/core/app/models/spree/calculator/flat_rate.rb b/core/app/models/spree/calculator/flat_rate.rb index 20b5b501468..87224d5ab42 100644 --- a/core/app/models/spree/calculator/flat_rate.rb +++ b/core/app/models/spree/calculator/flat_rate.rb @@ -11,7 +11,7 @@ def compute(object = nil) if object && preferred_currency.casecmp(object.currency).zero? preferred_amount else - 0 + Spree::ZERO end end end diff --git a/core/spec/models/spree/calculator/flat_rate_spec.rb b/core/spec/models/spree/calculator/flat_rate_spec.rb index f4955f0ec3c..89b8dbdccf9 100644 --- a/core/spec/models/spree/calculator/flat_rate_spec.rb +++ b/core/spec/models/spree/calculator/flat_rate_spec.rb @@ -26,14 +26,18 @@ calculator.preferred_amount = 100.0 calculator.preferred_currency = "GBP" allow(order).to receive_messages currency: "USD" - expect(calculator.compute(order).round(2)).to eq(0.0) + result = calculator.compute(order) + expect(result).to be_a(BigDecimal) + expect(result.round(2)).to eq(0.0) end it "should compute the amount as 0 when currency is blank" do calculator.preferred_amount = 100.0 calculator.preferred_currency = "" allow(order).to receive_messages currency: "GBP" - expect(calculator.compute(order).round(2)).to eq(0.0) + result = calculator.compute(order) + expect(result).to be_a(BigDecimal) + expect(result.round(2)).to eq(0.0) end it "should compute the amount as the rate when the currencies use different casing" do @@ -46,7 +50,9 @@ it "should compute the amount as 0 when there is no object" do calculator.preferred_amount = 100.0 calculator.preferred_currency = "GBP" - expect(calculator.compute.round(2)).to eq(0.0) + result = calculator.compute + expect(result).to be_a(BigDecimal) + expect(result.round(2)).to eq(0.0) end end end