mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
Fix uncategorized budget category showing incorrect available_to_spend (#1117)
The `subcategories` method queries `WHERE parent_id = category.id`, but for the synthetic uncategorized budget category, `category.id` is nil. This caused `WHERE parent_id IS NULL` to match ALL top-level categories, making them appear as subcategories of uncategorized. This inflated actual_spending and produced a large negative available_to_spend. Add a nil guard on category.id to return an empty relation for synthetic categories. Fixes #819 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
97195d9f13
commit
e66f9543f2
@@ -162,6 +162,15 @@ class BudgetCategoryTest < ActiveSupport::TestCase
|
||||
assert_equal 40.0, standalone_bc.percent_of_budget_spent
|
||||
end
|
||||
|
||||
test "uncategorized budget category returns no subcategories" do
|
||||
uncategorized_bc = BudgetCategory.uncategorized
|
||||
uncategorized_bc.budget = @budget
|
||||
|
||||
# Before the fix, this would return all top-level categories because
|
||||
# category.id is nil, causing WHERE parent_id IS NULL to match all roots
|
||||
assert_empty uncategorized_bc.subcategories
|
||||
end
|
||||
|
||||
test "parent with only inheriting subcategories shares entire budget" do
|
||||
# Set subcategory_with_limit to also inherit
|
||||
@subcategory_with_limit_bc.update!(budgeted_spending: 0)
|
||||
|
||||
Reference in New Issue
Block a user