mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
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:
@@ -494,4 +494,97 @@ class Transaction::SearchTest < ActiveSupport::TestCase
|
||||
# Should not match unrelated transactions
|
||||
assert_not_includes result_ids, no_match.entryable.id
|
||||
end
|
||||
|
||||
test "uncategorized filter returns same results across all supported locales" do
|
||||
# Create uncategorized transactions
|
||||
uncategorized1 = create_transaction(
|
||||
account: @checking_account,
|
||||
amount: 100,
|
||||
kind: "standard"
|
||||
)
|
||||
|
||||
uncategorized2 = create_transaction(
|
||||
account: @checking_account,
|
||||
amount: 200,
|
||||
kind: "standard"
|
||||
)
|
||||
|
||||
# Create a categorized transaction to ensure filter is working
|
||||
categorized = create_transaction(
|
||||
account: @checking_account,
|
||||
amount: 300,
|
||||
category: categories(:food_and_drink),
|
||||
kind: "standard"
|
||||
)
|
||||
|
||||
# Get the expected count using English locale (known working case)
|
||||
I18n.with_locale(:en) do
|
||||
english_uncategorized_name = Category.uncategorized.name
|
||||
english_results = Transaction::Search.new(@family, filters: { categories: [ english_uncategorized_name ] }).transactions_scope
|
||||
@expected_count = english_results.count
|
||||
assert_equal 2, @expected_count, "English locale should return 2 uncategorized transactions"
|
||||
end
|
||||
|
||||
# Test every supported locale returns the same count when filtering by that locale's uncategorized name
|
||||
LanguagesHelper::SUPPORTED_LOCALES.each do |locale|
|
||||
I18n.with_locale(locale) do
|
||||
localized_uncategorized_name = Category.uncategorized.name
|
||||
results = Transaction::Search.new(@family, filters: { categories: [ localized_uncategorized_name ] }).transactions_scope
|
||||
result_count = results.count
|
||||
|
||||
assert_equal @expected_count, result_count,
|
||||
"Locale '#{locale}' with uncategorized name '#{localized_uncategorized_name}' should return #{@expected_count} transactions but got #{result_count}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "uncategorized filter works with English parameter name regardless of current locale" do
|
||||
# This tests the bug where URL contains English "Uncategorized" but user's locale is different
|
||||
# Bug: /transactions/?q[categories][]=Uncategorized fails when locale is French
|
||||
|
||||
# Create uncategorized transactions
|
||||
uncategorized1 = create_transaction(
|
||||
account: @checking_account,
|
||||
amount: 100,
|
||||
kind: "standard"
|
||||
)
|
||||
|
||||
uncategorized2 = create_transaction(
|
||||
account: @checking_account,
|
||||
amount: 200,
|
||||
kind: "standard"
|
||||
)
|
||||
|
||||
# Create a categorized transaction to ensure filter is working
|
||||
categorized = create_transaction(
|
||||
account: @checking_account,
|
||||
amount: 300,
|
||||
category: categories(:food_and_drink),
|
||||
kind: "standard"
|
||||
)
|
||||
|
||||
# Get the English uncategorized name (this is what URLs typically contain)
|
||||
english_uncategorized_name = I18n.t("models.category.uncategorized", locale: :en)
|
||||
|
||||
# Get the expected count using English locale (known working case)
|
||||
expected_count = nil
|
||||
I18n.with_locale(:en) do
|
||||
results = Transaction::Search.new(@family, filters: { categories: [ english_uncategorized_name ] }).transactions_scope
|
||||
expected_count = results.count
|
||||
assert_equal 2, expected_count, "English locale should return 2 uncategorized transactions"
|
||||
end
|
||||
|
||||
# Test that using the English parameter name works in every supported locale
|
||||
# This catches the bug where French locale fails with English "Uncategorized" parameter
|
||||
LanguagesHelper::SUPPORTED_LOCALES.each do |locale|
|
||||
I18n.with_locale(locale) do
|
||||
# Simulate URL parameter: q[categories][]=Uncategorized (English, regardless of user's locale)
|
||||
results = Transaction::Search.new(@family, filters: { categories: [ english_uncategorized_name ] }).transactions_scope
|
||||
result_count = results.count
|
||||
|
||||
assert_equal expected_count, result_count,
|
||||
"Locale '#{locale}' should return #{expected_count} transactions when filtering with English 'Uncategorized' parameter, but got #{result_count}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user