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:
parent
5d1a2937bb
commit
9a2a7b31d4
45 changed files with 342 additions and 84 deletions
|
@ -93,7 +93,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
|
|||
created_entry = Account::Entry.order(created_at: :desc).first
|
||||
|
||||
assert created_entry.amount.positive?
|
||||
assert created_entry.marked_as_transfer
|
||||
assert created_entry.entryable.category.transfer?
|
||||
assert_redirected_to @entry.account
|
||||
end
|
||||
|
||||
|
|
2
test/fixtures/account/entries.yml
vendored
2
test/fixtures/account/entries.yml
vendored
|
@ -31,7 +31,6 @@ transfer_out:
|
|||
amount: 100
|
||||
currency: USD
|
||||
account: depository
|
||||
marked_as_transfer: true
|
||||
transfer: one
|
||||
entryable_type: Account::Transaction
|
||||
entryable: transfer_out
|
||||
|
@ -42,7 +41,6 @@ transfer_in:
|
|||
amount: -100
|
||||
currency: USD
|
||||
account: credit_card
|
||||
marked_as_transfer: true
|
||||
transfer: one
|
||||
entryable_type: Account::Transaction
|
||||
entryable: transfer_in
|
||||
|
|
7
test/fixtures/account/transactions.yml
vendored
7
test/fixtures/account/transactions.yml
vendored
|
@ -2,5 +2,8 @@ one:
|
|||
category: food_and_drink
|
||||
merchant: amazon
|
||||
|
||||
transfer_out: { }
|
||||
transfer_in: { }
|
||||
transfer_out:
|
||||
category: transfer
|
||||
|
||||
transfer_in:
|
||||
category: transfer
|
4
test/fixtures/budget_categories.yml
vendored
Normal file
4
test/fixtures/budget_categories.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
food_and_drink:
|
||||
budget: one
|
||||
category: food_and_drink
|
||||
budgeted_amount: 800
|
6
test/fixtures/budgets.yml
vendored
Normal file
6
test/fixtures/budgets.yml
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
one:
|
||||
start_date: <%= 1.month.ago.to_date %>
|
||||
end_date: <%= Date.current %>
|
||||
family: dylan_family
|
||||
budgeted_amount: 5000
|
||||
expected_income: 8000
|
16
test/fixtures/categories.yml
vendored
16
test/fixtures/categories.yml
vendored
|
@ -1,17 +1,33 @@
|
|||
one:
|
||||
name: Test
|
||||
classification: expense
|
||||
family: empty
|
||||
|
||||
income:
|
||||
name: Income
|
||||
classification: income
|
||||
color: "#fd7f6f"
|
||||
family: dylan_family
|
||||
|
||||
transfer:
|
||||
name: Transfer
|
||||
classification: transfer
|
||||
color: "#fd7f6f"
|
||||
family: dylan_family
|
||||
|
||||
payment:
|
||||
name: Payment
|
||||
classification: payment
|
||||
color: "#fd7f6f"
|
||||
family: dylan_family
|
||||
|
||||
food_and_drink:
|
||||
name: Food & Drink
|
||||
classification: expense
|
||||
family: dylan_family
|
||||
|
||||
subcategory:
|
||||
name: Restaurants
|
||||
classification: expense
|
||||
parent: food_and_drink
|
||||
family: dylan_family
|
||||
|
|
8
test/fixtures/goals.yml
vendored
Normal file
8
test/fixtures/goals.yml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
saving:
|
||||
name: Vacation savings
|
||||
type: saving
|
||||
start_date: <%= 1.month.ago.to_date %>
|
||||
target_date: <%= 1.year.from_now.to_date %>
|
||||
target_amount: 10000
|
||||
starting_amount: 2000
|
||||
family: dylan_family
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
7
test/models/budget_category_test.rb
Normal file
7
test/models/budget_category_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class BudgetCategoryTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
7
test/models/budget_test.rb
Normal file
7
test/models/budget_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class BudgetTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -124,7 +124,7 @@ class FamilyTest < ActiveSupport::TestCase
|
|||
create_transaction(account: account, date: 2.days.ago.to_date, amount: -500)
|
||||
create_transaction(account: account, date: 1.day.ago.to_date, amount: 100)
|
||||
create_transaction(account: account, date: Date.current, amount: 20)
|
||||
create_transaction(account: liability_account, date: 2.days.ago.to_date, amount: -333)
|
||||
create_transaction(account: liability_account, date: 2.days.ago.to_date, amount: -333, category: categories(:payment))
|
||||
|
||||
snapshot = @family.snapshot_transactions
|
||||
|
||||
|
|
7
test/models/goal_test.rb
Normal file
7
test/models/goal_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class GoalTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
28
test/models/transfer_matcher_test.rb
Normal file
28
test/models/transfer_matcher_test.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require "test_helper"
|
||||
|
||||
class TransferMatcherTest < ActiveSupport::TestCase
|
||||
include Account::EntriesTestHelper
|
||||
|
||||
setup do
|
||||
@family = families(:dylan_family)
|
||||
@matcher = TransferMatcher.new(@family)
|
||||
end
|
||||
|
||||
test "matches entries with opposite amounts and different accounts within 4 days" do
|
||||
entry1 = create_transaction(account: accounts(:depository), amount: 100, date: Date.current)
|
||||
entry2 = create_transaction(account: accounts(:credit_card), amount: -100, date: 2.days.ago.to_date)
|
||||
|
||||
assert_difference "Account::Transfer.count", 1 do
|
||||
@matcher.match!([ entry1, entry2 ])
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't match entries more than 4 days apart" do
|
||||
entry1 = create_transaction(account: accounts(:depository), amount: 100, date: Date.current)
|
||||
entry2 = create_transaction(account: accounts(:credit_card), amount: -100, date: Date.current + 5.days)
|
||||
|
||||
assert_no_difference "Account::Transfer.count" do
|
||||
@matcher.match!([ entry1, entry2 ])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -210,7 +210,7 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
def number_of_transactions_on_page
|
||||
[ @user.family.entries.without_transfers.count, @page_size ].min
|
||||
[ @user.family.entries.count, @page_size ].min
|
||||
end
|
||||
|
||||
def all_transactions_checkbox
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue