From 38fafb7a7088b1aebb938efe97a8e6870b027e1e Mon Sep 17 00:00:00 2001 From: Peng DU Date: Mon, 11 Jul 2016 16:04:15 +0200 Subject: [PATCH] wallet credit amount can be a float --- app/models/concerns/amount_concern.rb | 2 +- test/integration/wallets_test.rb | 2 +- test/models/wallet_test.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/amount_concern.rb b/app/models/concerns/amount_concern.rb index 86b01b443..b2d07d050 100644 --- a/app/models/concerns/amount_concern.rb +++ b/app/models/concerns/amount_concern.rb @@ -8,7 +8,7 @@ module AmountConcern if amount.nil? write_attribute(:amount, amount) else - write_attribute(:amount, amount.to_i * 100) + write_attribute(:amount, (amount * 100).to_i) end end diff --git a/test/integration/wallets_test.rb b/test/integration/wallets_test.rb index 5ace5e4af..bc9c89aac 100644 --- a/test/integration/wallets_test.rb +++ b/test/integration/wallets_test.rb @@ -61,7 +61,7 @@ class WalletsTest < ActionDispatch::IntegrationTest admin = users(:user_1) login_as(admin, scope: :user) w = @vlonchamp.wallet - amount = 10 + amount = 10.5 expected_amount = w.amount + amount put "/api/wallet/#{w.id}/credit", { diff --git a/test/models/wallet_test.rb b/test/models/wallet_test.rb index 537ae6bdf..7eb1fbb01 100644 --- a/test/models/wallet_test.rb +++ b/test/models/wallet_test.rb @@ -13,8 +13,8 @@ class WalletTest < ActiveSupport::TestCase test 'can credit amount' do w = Wallet.first - expected_amount = w.amount + 5 - assert w.credit(5) + expected_amount = w.amount + 5.5 + assert w.credit(5.5) assert_equal w.amount, expected_amount end