2024-02-02 09:05:04 -06:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class AccountTest < ActiveSupport::TestCase
|
2024-02-06 12:30:51 -05:00
|
|
|
def setup
|
2024-02-03 13:07:23 -06:00
|
|
|
depository = Account::Depository.create!
|
2024-02-06 12:30:51 -05:00
|
|
|
@account = Account.create!(family: families(:dylan_family), name: "Explicit Checking", balance_cents: 1200, accountable: depository)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "new account should be valid" do
|
|
|
|
assert @account.valid?
|
|
|
|
assert_not_nil @account.accountable_id
|
|
|
|
assert_not_nil @account.accountable
|
|
|
|
end
|
|
|
|
|
|
|
|
test "balance returns Money object" do
|
|
|
|
@account.balance = 10
|
|
|
|
assert_instance_of Money, @account.balance
|
|
|
|
assert_equal :usd, @account.balance.currency.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "correctly assigns Money objects to the attribute" do
|
|
|
|
@account.balance = Money.new(2500, "USD")
|
|
|
|
assert_equal 2500, @account.balance_cents
|
|
|
|
end
|
|
|
|
|
|
|
|
test "balance_cents can be updated" do
|
|
|
|
new_balance = Money.new(10000, "USD")
|
|
|
|
@account.balance = new_balance
|
|
|
|
assert_equal new_balance, @account.balance
|
2024-02-03 13:07:23 -06:00
|
|
|
end
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|