mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 11:34:13 +00:00
Fix nil-key collision in budget category hash lookups (#1136)
Both Uncategorized and Other Investments are synthetic categories with id=nil. When expense_totals_by_category indexes by category.id, Other Investments overwrites Uncategorized at the nil key, causing uncategorized actual spending to always return 0. Use category.name as fallback key (id || name) to differentiate the two synthetic categories in all hash builders and lookup sites. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
f8d3678a40
commit
388f249e4e
@@ -304,4 +304,30 @@ class BudgetTest < ActiveSupport::TestCase
|
||||
|
||||
assert_not_nil budget.previous_budget_param
|
||||
end
|
||||
|
||||
test "uncategorized budget category actual spending reflects uncategorized transactions" do
|
||||
family = families(:dylan_family)
|
||||
budget = Budget.find_or_bootstrap(family, start_date: Date.current.beginning_of_month)
|
||||
account = accounts(:depository)
|
||||
|
||||
# Create an uncategorized expense
|
||||
Entry.create!(
|
||||
account: account,
|
||||
entryable: Transaction.create!(category: nil),
|
||||
date: Date.current,
|
||||
name: "Uncategorized lunch",
|
||||
amount: 75,
|
||||
currency: "USD"
|
||||
)
|
||||
|
||||
budget = Budget.find(budget.id)
|
||||
budget.sync_budget_categories
|
||||
|
||||
uncategorized_bc = budget.uncategorized_budget_category
|
||||
spending = budget.budget_category_actual_spending(uncategorized_bc)
|
||||
|
||||
# Must be > 0 — the nil-key collision between Uncategorized and
|
||||
# Other Investments synthetic categories previously caused this to return 0
|
||||
assert spending >= 75, "Uncategorized actual spending should include the $75 transaction, got #{spending}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user