1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/test/models/wallet_test.rb

40 lines
799 B
Ruby
Raw Normal View History

2016-07-18 18:16:54 +02:00
require 'test_helper'
class WalletTest < ActiveSupport::TestCase
test "default amount must be zero" do
w = Wallet.new
assert w.amount == 0
end
test 'should user present' do
w = Wallet.create
assert w.errors[:user].present?
end
2016-07-04 19:20:10 +02:00
test 'can credit amount' do
w = Wallet.first
expected_amount = w.amount + 5
assert w.credit(5)
assert_equal w.amount, expected_amount
end
test 'can debit amount' do
w = Wallet.first
w.credit(5)
expected_amount = 0
assert w.debit(5)
assert_equal w.amount, expected_amount
end
2016-07-05 10:38:39 +02:00
test 'cant debit/credit a negative' do
w = Wallet.new
assert_not w.credit(-5)
assert_not w.debit(-5)
end
test 'wallet amount cant < 0 after debit' do
w = Wallet.new
assert_not w.debit(5)
end
2016-07-18 18:16:54 +02:00
end