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
4 changes: 2 additions & 2 deletions core/app/models/spree/calculator/flat_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

def compute(object = nil)
if object && preferred_currency.casecmp(object.currency).zero?
preferred_amount
BigDecimal(preferred_amount.to_s)
else
0
BigDecimal("0")

Check failure on line 14 in core/app/models/spree/calculator/flat_rate.rb

View workflow job for this annotation

GitHub Actions / Check Ruby

Performance/BigDecimalWithNumericArgument: Convert string literal to integer and pass it to `BigDecimal`.
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions core/spec/models/spree/calculator/flat_rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,32 @@
calculator.preferred_currency = "GBP"
expect(calculator.compute.round(2)).to eq(0.0)
end
context "return type" do
it "always returns a BigDecimal when currency matches" do
calculator.preferred_amount = 25.0
calculator.preferred_currency = "USD"
allow(order).to receive_messages currency: "USD"
expect(calculator.compute(order)).to be_a(BigDecimal)
end

it "always returns a BigDecimal when currency does not match" do
calculator.preferred_amount = 100.0
calculator.preferred_currency = "GBP"
allow(order).to receive_messages currency: "USD"
expect(calculator.compute(order)).to be_a(BigDecimal)
end

it "always returns a BigDecimal when there is no object" do
calculator.preferred_amount = 100.0
expect(calculator.compute).to be_a(BigDecimal)
end

it "always returns a BigDecimal when amount is zero" do
calculator.preferred_amount = 0
calculator.preferred_currency = "USD"
allow(order).to receive_messages currency: "USD"
expect(calculator.compute(order)).to be_a(BigDecimal)
end
end

Check failure on line 77 in core/spec/models/spree/calculator/flat_rate_spec.rb

View workflow job for this annotation

GitHub Actions / Check Ruby

Layout/BlockAlignment: `end` at 77, 2 is not aligned with `context "return type" do` at 51, 4.
end
end
Loading