Add tests for uncategorized transaction filter across locales (#862)

* test: Add tests for uncategorized filter across all locales

Adds two tests to catch the bug where filtering for "Uncategorized"
transactions fails when the user's locale is not English:

1. Tests that filtering with the locale-specific uncategorized name
   works correctly in all SUPPORTED_LOCALES
2. Tests that filtering with the English "Uncategorized" parameter
   works regardless of the current locale (catches the French bug)

https://claude.ai/code/session_01JcKj4776k5Es8Cscbm4kUo

* fix: Fix uncategorized filter for French, Catalan, and Dutch locales

The uncategorized filter was failing when the URL parameter contained
"Uncategorized" (English) but the user's locale was different. This
affected 3 locales with non-English translations:
- French: "Non catégorisé"
- Catalan: "Sense categoria"
- Dutch: "Ongecategoriseerd"

The fix adds Category.all_uncategorized_names which returns all possible
uncategorized name translations across supported locales, and updates
the search filter to check against all variants instead of just the
current locale's translation.

https://claude.ai/code/session_01JcKj4776k5Es8Cscbm4kUo

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Juan José Mata
2026-02-01 18:59:12 +01:00
committed by GitHub
parent ea0c70de8a
commit 70f483c603
3 changed files with 105 additions and 4 deletions

View File

@@ -109,6 +109,14 @@ class Category < ApplicationRecord
I18n.t(UNCATEGORIZED_NAME_KEY)
end
# Returns all possible uncategorized names across all supported locales
# Used to detect uncategorized filter regardless of URL parameter language
def all_uncategorized_names
LanguagesHelper::SUPPORTED_LOCALES.map do |locale|
I18n.t(UNCATEGORIZED_NAME_KEY, locale: locale)
end.uniq
end
# Helper to get the localized name for other investments
def other_investments_name
I18n.t(OTHER_INVESTMENTS_NAME_KEY)

View File

@@ -102,10 +102,10 @@ class Transaction::Search
def apply_category_filter(query, categories)
return query unless categories.present?
# Remove "Uncategorized" from category names to query the database
uncategorized_name = Category.uncategorized.name
include_uncategorized = categories.include?(uncategorized_name)
real_categories = categories - [ uncategorized_name ]
# Check for "Uncategorized" in any supported locale (handles URL params in different languages)
all_uncategorized_names = Category.all_uncategorized_names
include_uncategorized = (categories & all_uncategorized_names).any?
real_categories = categories - all_uncategorized_names
# Get parent category IDs for the given category names
parent_category_ids = family.categories.where(name: real_categories).pluck(:id)