1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-08 23:15:24 +02:00

First sketch of budgeting module

This commit is contained in:
Zach Gollwitzer 2024-12-30 17:29:59 -05:00
parent 5d1a2937bb
commit 9a2a7b31d4
45 changed files with 342 additions and 84 deletions

View file

@ -74,7 +74,7 @@ class Account::EntryTest < ActiveSupport::TestCase
create_transaction(account: account, amount: 100)
create_transaction(account: account, amount: -500) # income, will be ignored
assert_equal Money.new(200), family.entries.expense_total("USD")
assert_equal Money.new(200), account.entries.expense_total("USD")
end
test "can calculate total income for a group of transactions" do
@ -82,8 +82,8 @@ class Account::EntryTest < ActiveSupport::TestCase
account = family.accounts.create! name: "Test", balance: 0, currency: "USD", accountable: Depository.new
create_transaction(account: account, amount: -100)
create_transaction(account: account, amount: -100)
create_transaction(account: account, amount: 500) # income, will be ignored
create_transaction(account: account, amount: 500) # expense, will be ignored
assert_equal Money.new(-200), family.entries.income_total("USD")
assert_equal Money.new(-200), account.entries.income_total("USD")
end
end

View file

@ -28,28 +28,31 @@ class Account::TransferTest < ActiveSupport::TestCase
name: "Inflow",
amount: -100,
currency: "USD",
marked_as_transfer: true,
entryable: Account::Transaction.new
entryable: Account::Transaction.new(
category: account.family.default_transfer_category
)
outflow = account.entries.create! \
date: Date.current,
name: "Outflow",
amount: 100,
currency: "USD",
marked_as_transfer: true,
entryable: Account::Transaction.new
entryable: Account::Transaction.new(
category: account.family.default_transfer_category
)
assert_raise ActiveRecord::RecordInvalid do
Account::Transfer.create! entries: [ inflow, outflow ]
end
end
test "all transfer transactions must be marked as transfers" do
@inflow.update! marked_as_transfer: false
test "all transfer transactions must have transfer category" do
@inflow.entryable.update! category: nil
assert_raise ActiveRecord::RecordInvalid do
Account::Transfer.create! entries: [ @inflow, @outflow ]
end
transfer = Account::Transfer.new entries: [ @inflow, @outflow ]
assert_not transfer.valid?
assert_equal "Entries must have transfer category", transfer.errors.full_messages.first
end
test "single-currency transfer transactions must net to zero" do