M lib/low_balance.rb => lib/low_balance.rb +2 -2
@@ 95,7 95,7 @@ class LowBalance
def top_up_amount
[
- (@target + @margin) - @customer.balance,
+ ((@target + @margin) - @customer.balance).round(2),
@customer.auto_top_up_amount
].max
end
@@ 116,7 116,7 @@ class LowBalance
)
@message.body =
"Automatic top-up transaction for " \
- "$#{top_up_amount} failed: #{e.message}"
+ "$#{'%.2f' % top_up_amount} failed: #{e.message}"
0
end
M test/test_low_balance.rb => test/test_low_balance.rb +2 -2
@@ 246,7 246,7 @@ class LowBalanceTest < Minitest::Test
nil,
[Matching.new { |m|
assert_equal(
- "Automatic top-up transaction for $100 failed: test",
+ "Automatic top-up transaction for $100.00 failed: test",
m.body
)
}]
@@ 254,7 254,7 @@ class LowBalanceTest < Minitest::Test
LowBalance::AutoTopUp::CreditCardSale.expect(
:create,
EMPromise.reject(RuntimeError.new("test")),
- [@customer], amount: 100
+ [@customer], amount: 100.to_d
)
@auto_top_up.notify!.sync
assert_mock @customer