Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/spree/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/calculator/flat_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions core/spec/models/spree/calculator/flat_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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