From 4170387aa18a6fceb2ea24754e559e8e80ca3c7a Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Wed, 23 Jul 2025 09:43:43 -0400 Subject: [PATCH] Assert flows factor --- app/models/balance/base_calculator.rb | 3 ++- test/support/ledger_testing_helper.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/balance/base_calculator.rb b/app/models/balance/base_calculator.rb index c7c3bde0..9d1d288f 100644 --- a/app/models/balance/base_calculator.rb +++ b/app/models/balance/base_calculator.rb @@ -133,7 +133,8 @@ class Balance::BaseCalculator non_cash_outflows: args[:non_cash_outflows] || 0, cash_adjustments: args[:cash_adjustments] || 0, non_cash_adjustments: args[:non_cash_adjustments] || 0, - net_market_flows: args[:net_market_flows] || 0 + net_market_flows: args[:net_market_flows] || 0, + flows_factor: account.classification == "asset" ? 1 : -1 ) end end diff --git a/test/support/ledger_testing_helper.rb b/test/support/ledger_testing_helper.rb index d1345c76..d5e08aec 100644 --- a/test/support/ledger_testing_helper.rb +++ b/test/support/ledger_testing_helper.rb @@ -135,6 +135,11 @@ module LedgerTestingHelper if expected assert calculated_balance, "Expected balance for #{date} but none was calculated" + # Always assert flows_factor is correct based on account classification + expected_flows_factor = calculated_balance.account.classification == "asset" ? 1 : -1 + assert_equal expected_flows_factor, calculated_balance.flows_factor, + "Flows factor mismatch for #{date}: expected #{expected_flows_factor} for #{calculated_balance.account.classification} account" + legacy_balances = expected[:legacy_balances] balances = expected[:balances] flows = expected[:flows]