1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 14:19:39 +02:00
Maybe/test/models/account_test.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

2024-02-02 09:05:04 -06:00
require "test_helper"
class AccountTest < ActiveSupport::TestCase
include SyncableInterfaceTest, EntriesTestHelper
setup do
@account = @syncable = accounts(:depository)
@family = families(:dylan_family)
end
test "can destroy" do
assert_difference "Account.count", -1 do
@account.destroy
end
end
test "gets short/long subtype label" do
account = @family.accounts.create!(
name: "Test Investment",
balance: 1000,
currency: "USD",
subtype: "hsa",
accountable: Investment.new
)
assert_equal "HSA", account.short_subtype_label
assert_equal "Health Savings Account", account.long_subtype_label
# Test with nil subtype
account.update!(subtype: nil)
assert_equal "Investments", account.short_subtype_label
assert_equal "Investments", account.long_subtype_label
end
# Currency updates earn their own method because updating an account currency incurs
# side effects like recalculating balances, etc.
test "can update the account currency" do
@account.update_currency!("EUR")
assert_equal "EUR", @account.currency
assert_equal "EUR", @account.entries.valuations.first.currency
end
2024-02-02 09:05:04 -06:00
end