mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
New Design System + Codebase Refresh (#1823)
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
This commit is contained in:
parent
8539ac7dec
commit
d75be2282b
278 changed files with 3428 additions and 4354 deletions
83
test/models/balance_sheet_test.rb
Normal file
83
test/models/balance_sheet_test.rb
Normal file
|
@ -0,0 +1,83 @@
|
|||
require "test_helper"
|
||||
|
||||
class BalanceSheetTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@family = families(:empty)
|
||||
end
|
||||
|
||||
test "calculates total assets" do
|
||||
assert_equal 0, BalanceSheet.new(@family).total_assets
|
||||
|
||||
create_account(balance: 1000, accountable: Depository.new)
|
||||
create_account(balance: 5000, accountable: OtherAsset.new)
|
||||
create_account(balance: 10000, accountable: CreditCard.new) # ignored
|
||||
|
||||
assert_equal 1000 + 5000, BalanceSheet.new(@family).total_assets
|
||||
end
|
||||
|
||||
test "calculates total liabilities" do
|
||||
assert_equal 0, BalanceSheet.new(@family).total_liabilities
|
||||
|
||||
create_account(balance: 1000, accountable: CreditCard.new)
|
||||
create_account(balance: 5000, accountable: OtherLiability.new)
|
||||
create_account(balance: 10000, accountable: Depository.new) # ignored
|
||||
|
||||
assert_equal 1000 + 5000, BalanceSheet.new(@family).total_liabilities
|
||||
end
|
||||
|
||||
test "calculates net worth" do
|
||||
assert_equal 0, BalanceSheet.new(@family).net_worth
|
||||
|
||||
create_account(balance: 1000, accountable: CreditCard.new)
|
||||
create_account(balance: 50000, accountable: Depository.new)
|
||||
|
||||
assert_equal 50000 - 1000, BalanceSheet.new(@family).net_worth
|
||||
end
|
||||
|
||||
test "disabled accounts do not affect totals" do
|
||||
create_account(balance: 1000, accountable: CreditCard.new)
|
||||
create_account(balance: 10000, accountable: Depository.new)
|
||||
|
||||
other_liability = create_account(balance: 5000, accountable: OtherLiability.new)
|
||||
other_liability.update!(is_active: false)
|
||||
|
||||
assert_equal 10000 - 1000, BalanceSheet.new(@family).net_worth
|
||||
assert_equal 10000, BalanceSheet.new(@family).total_assets
|
||||
assert_equal 1000, BalanceSheet.new(@family).total_liabilities
|
||||
end
|
||||
|
||||
test "calculates asset group totals" do
|
||||
create_account(balance: 1000, accountable: Depository.new)
|
||||
create_account(balance: 2000, accountable: Depository.new)
|
||||
create_account(balance: 3000, accountable: Investment.new)
|
||||
create_account(balance: 5000, accountable: OtherAsset.new)
|
||||
create_account(balance: 10000, accountable: CreditCard.new) # ignored
|
||||
|
||||
asset_groups = BalanceSheet.new(@family).account_groups("asset")
|
||||
|
||||
assert_equal 3, asset_groups.size
|
||||
assert_equal 1000 + 2000, asset_groups.find { |ag| ag.name == "Cash" }.total
|
||||
assert_equal 3000, asset_groups.find { |ag| ag.name == "Investments" }.total
|
||||
assert_equal 5000, asset_groups.find { |ag| ag.name == "Other Assets" }.total
|
||||
end
|
||||
|
||||
test "calculates liability group totals" do
|
||||
create_account(balance: 1000, accountable: CreditCard.new)
|
||||
create_account(balance: 2000, accountable: CreditCard.new)
|
||||
create_account(balance: 3000, accountable: OtherLiability.new)
|
||||
create_account(balance: 5000, accountable: OtherLiability.new)
|
||||
create_account(balance: 10000, accountable: Depository.new) # ignored
|
||||
|
||||
liability_groups = BalanceSheet.new(@family).account_groups("liability")
|
||||
|
||||
assert_equal 2, liability_groups.size
|
||||
assert_equal 1000 + 2000, liability_groups.find { |ag| ag.name == "Credit Cards" }.total
|
||||
assert_equal 3000 + 5000, liability_groups.find { |ag| ag.name == "Other Liabilities" }.total
|
||||
end
|
||||
|
||||
private
|
||||
def create_account(attributes = {})
|
||||
account = @family.accounts.create! name: "Test", currency: "USD", **attributes
|
||||
account
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue