The personal finance app for everyone (by everyone)
Ruby
feat(transactions): align Uncategorized category filter with No merchant/Untagged pattern (#3186)
GFR4e2084b662b7
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rbindex a3218a06c4..665cb2ec22 100644--- a/app/controllers/pages_controller.rb+++ b/app/controllers/pages_controller.rb@@ -264,9 +264,9 @@ class PagesController < ApplicationControllerlinks = []node_indices = {}- add_node = ->(unique_key, display_name, value, percentage, color) {+ add_node = ->(unique_key, display_name, value, percentage, color, filter_value = nil) {node_indices[unique_key] ||= begin- nodes << { id: unique_key, name: display_name, value: value.to_f.round(2), percentage: percentage.to_f.round(1), color: color }+ nodes << { id: unique_key, name: display_name, filter_value: filter_value, value: value.to_f.round(2), percentage: percentage.to_f.round(1), color: color }nodes.size - 1end}@@ -375,7 +375,7 @@ class PagesController < ApplicationControlleropposite_subs = all_subs.select { |s| s[:net_direction] != matching_direction }if same_side_subs.any?- parent_idx = add_node.call(node_key, ct.category.name, val, percentage, color)+ parent_idx = add_node.call(node_key, ct.category.name, val, percentage, color, ct.category.filter_value)if flow_direction == :inboundlinks << { source: parent_idx, target: cash_flow_idx, value: val, color: color, percentage: percentage }@@ -388,7 +388,7 @@ class PagesController < ApplicationControllersub_pct = val.zero? ? 0 : (sub_val / val * 100).round(1)sub_color = sub[:category].color.presence || colorsub_key = "#{prefix}_sub_#{sub[:category].id}"- sub_idx = add_node.call(sub_key, sub[:category].name, sub_val, sub_pct, sub_color)+ sub_idx = add_node.call(sub_key, sub[:category].name, sub_val, sub_pct, sub_color, sub[:category].filter_value)if flow_direction == :inboundlinks << { source: sub_idx, target: parent_idx, value: sub_val, color: sub_color, percentage: sub_pct }@@ -397,7 +397,7 @@ class PagesController < ApplicationControllerendendelse- idx = add_node.call(node_key, ct.category.name, val, percentage, color)+ idx = add_node.call(node_key, ct.category.name, val, percentage, color, ct.category.filter_value)if flow_direction == :inboundlinks << { source: idx, target: cash_flow_idx, value: val, color: color, percentage: percentage }@@ -415,7 +415,7 @@ class PagesController < ApplicationControllersub_pct = total.zero? ? 0 : (sub_val / total * 100).round(1)sub_color = sub[:category].color.presence || colorsub_key = "#{opposite_prefix}_sub_#{sub[:category].id}"- sub_idx = add_node.call(sub_key, sub[:category].name, sub_val, sub_pct, sub_color)+ sub_idx = add_node.call(sub_key, sub[:category].name, sub_val, sub_pct, sub_color, sub[:category].filter_value)# Opposite direction: if parent is outbound (expense), this sub is inbound (income)if flow_direction == :inbound@@ -438,6 +438,7 @@ class PagesController < ApplicationController{id: ct.category.id,name: ct.category.name,+ filter_value: ct.category.filter_value,amount: ct.total.to_f.round(2),currency: ct.currency,percentage: ct.weight.round(1),diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rbindex dd498fb6b4..c91f49aad2 100644--- a/app/controllers/reports_controller.rb+++ b/app/controllers/reports_controller.rb@@ -397,10 +397,11 @@ class ReportsController < ApplicationControllerfamily_currency = Current.family.currency# Helper to initialize a category group hash- init_category_group = ->(id, name, color, icon, type) do+ init_category_group = ->(id, name, color, icon, type, filter_value) do{category_id: id,category_name: name,+ category_filter_value: filter_value,category_color: color,category_icon: icon,type: type,@@ -416,6 +417,7 @@ class ReportsController < ApplicationController{category_id: category.id,category_name: category.name,+ category_filter_value: category.filter_value,category_color: category.color,category_icon: category.lucide_icon,total: 0,@@ -437,16 +439,16 @@ class ReportsController < ApplicationController# Uncategorized or Other Investments (for trades)if is_tradeparent_key = [ :other_investments, type ]- grouped_data[parent_key] ||= init_category_group.call(:other_investments, Category.other_investments.name, Category.other_investments.color, Category.other_investments.lucide_icon, type)+ grouped_data[parent_key] ||= init_category_group.call(:other_investments, Category.other_investments.name, Category.other_investments.color, Category.other_investments.lucide_icon, type, Category.other_investments.name)elseparent_key = [ :uncategorized, type ]- grouped_data[parent_key] ||= init_category_group.call(:uncategorized, Category.uncategorized.name, Category.uncategorized.color, Category.uncategorized.lucide_icon, type)+ grouped_data[parent_key] ||= init_category_group.call(:uncategorized, Category.uncategorized.name, Category.uncategorized.color, Category.uncategorized.lucide_icon, type, Category.uncategorized.filter_value)endelsif category.parent_id.present?# This is a subcategory - group under parentparent = category.parentparent_key = [ parent.id, type ]- grouped_data[parent_key] ||= init_category_group.call(parent.id, parent.name, parent.color || Category::UNCATEGORIZED_COLOR, parent.lucide_icon, type)+ grouped_data[parent_key] ||= init_category_group.call(parent.id, parent.name, parent.color || Category::UNCATEGORIZED_COLOR, parent.lucide_icon, type, parent.filter_value)# Add to subcategorygrouped_data[parent_key][:subcategories][category.id] ||= init_subcategory.call(category)@@ -456,7 +458,7 @@ class ReportsController < ApplicationControllerelse# This is a root category (no parent)parent_key = [ category.id, type ]- grouped_data[parent_key] ||= init_category_group.call(category.id, category.name, category.color || Category::UNCATEGORIZED_COLOR, category.lucide_icon, type)+ grouped_data[parent_key] ||= init_category_group.call(category.id, category.name, category.color || Category::UNCATEGORIZED_COLOR, category.lucide_icon, type, category.filter_value)endgrouped_data[parent_key][:count] += 1diff --git a/app/javascript/controllers/donut_chart_controller.js b/app/javascript/controllers/donut_chart_controller.jsindex 9392d94590..7f0ef24d8e 100644--- a/app/javascript/controllers/donut_chart_controller.js+++ b/app/javascript/controllers/donut_chart_controller.js@@ -251,11 +251,11 @@ export default class extends Controller {// Handles click on segment (optional, controlled by enableClick value)#handleClick(segment) {- if (!segment.name) return;+ if (!segment.filter_value) return;Turbo.visit(buildCategoryTransactionsUrl({- name: segment.name,+ filterValue: segment.filter_value,startDate: this.startDateValue,endDate: this.endDateValue,}),diff --git a/app/javascript/controllers/sankey_chart_controller.js b/app/javascript/controllers/sankey_chart_controller.jsindex 21d1478cf5..5a25528218 100644--- a/app/javascript/controllers/sankey_chart_controller.js+++ b/app/javascript/controllers/sankey_chart_controller.js@@ -178,7 +178,7 @@ export default class extends Controller {Turbo.visit(buildCategoryTransactionsUrl({- name: d.name,+ filterValue: d.filter_value,startDate: this.startDateValue,endDate: this.endDateValue,}),diff --git a/app/javascript/utils/transactions_filter_url.mjs b/app/javascript/utils/transactions_filter_url.mjsindex b10c9b01b5..d58d925247 100644--- a/app/javascript/utils/transactions_filter_url.mjs+++ b/app/javascript/utils/transactions_filter_url.mjs@@ -6,17 +6,22 @@ export function isNavigableCategoryNode(id) {}// Builds a relative deep link to the transactions index, filtered by a single-// category name and (optionally) a start/end date range. Mirrors the params-// the transactions search form submits: q[categories][], q[start_date],-// q[end_date].+// category and (optionally) a start/end date range. Mirrors the params the+// transactions search form submits: q[categories][], q[start_date], q[end_date].+//+// filterValue must be the category's stable filter value (Category#filter_value:+// the persisted name for a real category, or Category::UNCATEGORIZED_FILTER_VALUE+// for the synthetic "Uncategorized" node/segment) -- not the display name, since+// the transactions search filter no longer matches the localized "Uncategorized"+// label.export function buildCategoryTransactionsUrl({- name,+ filterValue,startDate,endDate,basePath = "/transactions",}) {const params = new URLSearchParams();- params.append("q[categories][]", name);+ params.append("q[categories][]", filterValue);if (startDate) params.append("q[start_date]", startDate);if (endDate) params.append("q[end_date]", endDate);return `${basePath}?${params.toString()}`;diff --git a/app/models/assistant/function/get_transactions.rb b/app/models/assistant/function/get_transactions.rbindex f873852c46..a084947360 100644--- a/app/models/assistant/function/get_transactions.rb+++ b/app/models/assistant/function/get_transactions.rb@@ -145,6 +145,21 @@ class Assistant::Function::GetTransactions < Assistant::Functionsearch_params = params.except("order", "page", "page_size", "sort_by")search_params["status"] = search_params.delete("statuses") if search_params.key?("statuses")+ # The categories filter now matches Category::UNCATEGORIZED_FILTER_VALUE, a stable+ # sentinel, rather than the localized display name. params_schema still documents+ # (and the AI still passes) the literal "Uncategorized", so translate it here --+ # unless the family has a real category with that exact name, which takes priority+ # (get_categories never lists the synthetic option, so a real category by that+ # name is what the AI actually meant).+ if search_params["categories"].present?+ uncategorized_aliases = [ "Uncategorized", Category.uncategorized_name ].uniq+ real_names_matching_alias = family.categories.where(name: uncategorized_aliases).pluck(:name)+ search_params["categories"] = search_params["categories"].map do |name|+ next name if real_names_matching_alias.include?(name)+ uncategorized_aliases.include?(name) ? Category::UNCATEGORIZED_FILTER_VALUE : name+ end+ end+search = Transaction::Search.new(family,filters: search_params,diff --git a/app/models/category.rb b/app/models/category.rbindex bad3148a1f..8962600ae8 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -12,9 +12,19 @@ class Category < ApplicationRecorddependent: :nullifybelongs_to :parent, class_name: "Category", optional: true+ # Set by .uncategorized so #filter_value can identify the synthetic instance+ # without a locale-sensitive name comparison. Not a DB column.+ attr_writer :synthetic_uncategorized++ # Stable, non-localized filter value for the synthetic "Uncategorized" option.+ # Using an opaque sentinel (rather than the translated display name) means a real+ # category can never collide with it, regardless of name or locale.+ UNCATEGORIZED_FILTER_VALUE = "__uncategorized__"+validates :name, :color, :lucide_icon, :family, presence: truevalidates :color, format: { with: /\A#[0-9A-Fa-f]{6}\z/ }validates :name, uniqueness: { scope: :family_id }+ validates :name, exclusion: { in: [ UNCATEGORIZED_FILTER_VALUE ] }validate :category_level_limit@@ -228,7 +238,7 @@ class Category < ApplicationRecordname: I18n.t(UNCATEGORIZED_NAME_KEY),color: UNCATEGORIZED_COLOR,lucide_icon: "circle-dashed"- )+ ).tap { |category| category.synthetic_uncategorized = true }enddef other_investments@@ -373,6 +383,18 @@ class Category < ApplicationRecord!persisted? && name == I18n.t(UNCATEGORIZED_NAME_KEY)end+ # The value the transactions-filter checkbox submits for this category: the+ # persisted name for a real category, or the stable sentinel for the+ # synthetic "Uncategorized" pseudo-category returned by .uncategorized.+ #+ # Uses the explicit synthetic_uncategorized marker set by .uncategorized, not+ # uncategorized? -- that predicate compares name against I18n.t in the *current*+ # locale, so it would give the wrong answer if the instance were built under one+ # locale and read under another.+ def filter_value+ @synthetic_uncategorized ? UNCATEGORIZED_FILTER_VALUE : name+ end+# Predicate: is this the synthetic "Other Investments" category?def other_investments?!persisted? && name == I18n.t(OTHER_INVESTMENTS_NAME_KEY)diff --git a/app/models/transaction/search.rb b/app/models/transaction/search.rbindex dabd909624..1603c20383 100644--- a/app/models/transaction/search.rb+++ b/app/models/transaction/search.rb@@ -131,10 +131,8 @@ class Transaction::Searchdef apply_category_filter(query, categories)return query unless categories.present?- # 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+ include_uncategorized = categories.include?(Category::UNCATEGORIZED_FILTER_VALUE)+ real_categories = categories - [ Category::UNCATEGORIZED_FILTER_VALUE ]# Get parent category IDs for the given category namesparent_category_ids = family.categories.where(name: real_categories).pluck(:id)diff --git a/app/views/budget_categories/show.html.erb b/app/views/budget_categories/show.html.erbindex 7bec0188f0..cf86853043 100644--- a/app/views/budget_categories/show.html.erb+++ b/app/views/budget_categories/show.html.erb@@ -133,7 +133,7 @@variant: "outline",full_width: true,href: transactions_path(q: {- categories: [@budget_category.name],+ categories: [@budget_category.category.filter_value],start_date: @budget.start_date,end_date: @budget.end_date}),diff --git a/app/views/pages/dashboard/_outflows_donut.html.erb b/app/views/pages/dashboard/_outflows_donut.html.erbindex 2e430da536..07f993314f 100644--- a/app/views/pages/dashboard/_outflows_donut.html.erb+++ b/app/views/pages/dashboard/_outflows_donut.html.erb@@ -90,7 +90,7 @@<% end %><% if category[:clickable] != false %>- <%= link_to transactions_path(q: { categories: [category[:name]], start_date: period.date_range.first, end_date: period.date_range.last }),+ <%= link_to transactions_path(q: { categories: [category[:filter_value]], start_date: period.date_range.first, end_date: period.date_range.last }),class: "flex items-center justify-between mx-3 p-3 rounded-lg cursor-pointer group gap-3",data: {turbo_frame: "_top",diff --git a/app/views/reports/_category_row.html.erb b/app/views/reports/_category_row.html.erbindex fcb04e1994..2b932d1068 100644--- a/app/views/reports/_category_row.html.erb+++ b/app/views/reports/_category_row.html.erb@@ -7,7 +7,7 @@# /transactions only lists Transaction rows. Skip trade-only buckets (e.g. Other# Investments) so the destination is not empty relative to the report row.clickable = item[:has_transactions] && row_start_date.present? && row_end_date.present?- transactions_href = clickable ? transactions_path(q: { categories: [ item[:category_name] ], start_date: row_start_date, end_date: row_end_date }) : nil+ transactions_href = clickable ? transactions_path(q: { categories: [ item[:category_filter_value] ], start_date: row_start_date, end_date: row_end_date }) : nil%><tr data-category="category-<%= item[:category_id] %>"diff --git a/app/views/transactions/searches/filters/_badge.html.erb b/app/views/transactions/searches/filters/_badge.html.erbindex feec464f1e..05933e8343 100644--- a/app/views/transactions/searches/filters/_badge.html.erb+++ b/app/views/transactions/searches/filters/_badge.html.erb@@ -48,6 +48,10 @@<div class="flex items-center gap-2"><p><%= Tag.untagged_name %></p></div>+ <% elsif param_key == "categories" && param_value == Category::UNCATEGORIZED_FILTER_VALUE %>+ <div class="flex items-center gap-2">+ <p><%= Category.uncategorized_name %></p>+ </div><% else %><div class="flex items-center gap-2"><p><%= param_value %></p>diff --git a/app/views/transactions/searches/filters/_category_filter.html.erb b/app/views/transactions/searches/filters/_category_filter.html.erbindex 44284d518b..b5e687a9d4 100644--- a/app/views/transactions/searches/filters/_category_filter.html.erb+++ b/app/views/transactions/searches/filters/_category_filter.html.erb@@ -16,7 +16,7 @@<%= form.check_box :categories,{multiple: true,- checked: @q[:categories]&.include?(category.name),+ checked: @q[:categories]&.include?(category.filter_value),class: "checkbox checkbox--light",data: {category_filter_target: "checkbox",@@ -25,9 +25,9 @@parent_id: category.parent_id}},- category.name,+ category.filter_value,nil %>- <%= form.label :categories, category.display_name, value: category.name, class: "text-sm text-primary cursor-pointer flex items-center gap-1" do %>+ <%= form.label :categories, category.display_name, value: category.filter_value, class: "text-sm text-primary cursor-pointer flex items-center gap-1" do %><% if is_child %><%= icon("corner-down-right", size: "sm") %><% end %>diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rbindex 46bbfccb81..a4f367c18a 100644--- a/test/controllers/pages_controller_test.rb+++ b/test/controllers/pages_controller_test.rb@@ -141,6 +141,30 @@ class PagesControllerTest < ActionDispatch::IntegrationTestassert sankey_data.fetch("nodes").any? { |node| node.fetch("id").start_with?("expense_") }end+ test "dashboard sankey nodes carry a stable filter_value, including opposite-direction subcategories" do+ parent_category = @family.categories.create!(name: "Shopping", color: "#FF5733")+ subcategory = @family.categories.create!(name: "Rebate Program", parent: parent_category, color: "#33FF57")++ # Parent nets as an expense; the subcategory nets as income (more refunded than spent),+ # which routes it into the "opposite_subs" branch as its own standalone node.+ create_transaction(account: @family.accounts.first, name: "Shopping trip", amount: 100, category: parent_category)+ create_transaction(account: @family.accounts.first, name: "Rebate refund", amount: -30, category: subcategory)++ get root_path+ assert_response :ok++ chart = css_select("[data-controller='sankey-chart']").first+ sankey_data = JSON.parse(chart["data-sankey-chart-data-value"])+ nodes = sankey_data.fetch("nodes")++ opposite_node = nodes.find { |node| node.fetch("id").start_with?("income_sub_") }+ assert_not_nil opposite_node, "expected an opposite-direction subcategory node"+ assert_equal subcategory.name, opposite_node["filter_value"]++ parent_node = nodes.find { |node| node.fetch("id") == "expense_#{parent_category.id}" }+ assert_equal parent_category.name, parent_node["filter_value"]+ end+test "dashboard renders money flow widget" doget root_pathdiff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rbindex d2729540b4..eb8b4cb610 100644--- a/test/controllers/reports_controller_test.rb+++ b/test/controllers/reports_controller_test.rb@@ -436,7 +436,7 @@ class ReportsControllerTest < ActionDispatch::IntegrationTestexpense_href = transactions_path(q: { categories: [ expense_category.name ], start_date: start_date, end_date: end_date })income_href = transactions_path(q: { categories: [ income_category.name ], start_date: start_date, end_date: end_date })- uncategorized_href = transactions_path(q: { categories: [ Category.uncategorized.name ], start_date: start_date, end_date: end_date })+ uncategorized_href = transactions_path(q: { categories: [ Category.uncategorized.filter_value ], start_date: start_date, end_date: end_date })assert_select "tr[data-category='category-#{expense_category.id}'] a[href=?]", expense_href, text: expense_category.nameassert_select "tr[data-category='category-#{income_category.id}'] a[href=?]", income_href, text: income_category.name@@ -449,7 +449,7 @@ class ReportsControllerTest < ActionDispatch::IntegrationTestassert_select "tr.group\\/category-row[data-category='category-#{expense_category.id}'] td div.relative a[class*='before:absolute'][class*='before:inset-0']"end- test "index uncategorized category link uses localized name that Search accepts" do+ test "index uncategorized category link stays on the stable filter value while the displayed text is localized" dostart_date = Date.current.beginning_of_monthend_date = Date.current.end_of_monthaccount = @family.accounts.first@@ -457,12 +457,11 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest@user.update!(locale: "zh-CN")localized_name = I18n.with_locale(:"zh-CN") { Category.uncategorized.name }- assert_includes Category.all_uncategorized_names, localized_nameget reports_path(period_type: :monthly, start_date: start_date, end_date: end_date)assert_response :ok- href = transactions_path(q: { categories: [ localized_name ], start_date: start_date, end_date: end_date })+ href = transactions_path(q: { categories: [ Category::UNCATEGORIZED_FILTER_VALUE ], start_date: start_date, end_date: end_date })assert_select "tr[data-category='category-uncategorized'] a[href=?]", href, text: localized_nameenddiff --git a/test/fixtures/users.yml b/test/fixtures/users.ymlindex 2e2aa6d82c..dfdf4800f2 100644--- a/test/fixtures/users.yml+++ b/test/fixtures/users.yml@@ -9,6 +9,11 @@ empty:email: [email protected]password_digest: $2a$04$deKu1NIqviMgrl.4NkXcieFkAmLa33RN9Tw/R/Llr22eMd4x/o/ROonboarded_at: <%= 3.days.ago %>+ # Explicit created_at so this admin sorts before the other admin fixture+ # (sso_only) in family "empty" — without it, both rows get the same+ # fixture-load timestamp and Account#assign_default_owner's+ # order(:created_at).first becomes non-deterministic (test/models/account_test.rb).+ created_at: <%= 4.days.ago %>role: adminai_enabled: trueshow_sidebar: truediff --git a/test/javascript/utils/transactions_filter_url_test.mjs b/test/javascript/utils/transactions_filter_url_test.mjsindex c7d2109fa0..7406a9c051 100644--- a/test/javascript/utils/transactions_filter_url_test.mjs+++ b/test/javascript/utils/transactions_filter_url_test.mjs@@ -20,7 +20,7 @@ test("category nodes are navigable, structural nodes are not", () => {test("builds a transactions deep link with category and date range", () => {const url = buildCategoryTransactionsUrl({- name: "Groceries",+ filterValue: "Groceries",startDate: "2026-05-01",endDate: "2026-05-31",});@@ -32,16 +32,25 @@ test("builds a transactions deep link with category and date range", () => {test("encodes category names with special characters", () => {const url = buildCategoryTransactionsUrl({- name: "Food & Drink",+ filterValue: "Food & Drink",startDate: "2026-05-01",endDate: "2026-05-31",});assert.match(url, /q%5Bcategories%5D%5B%5D=Food\+%26\+Drink/);});+test("passes the Uncategorized sentinel through unchanged, not a display name", () => {+ const url = buildCategoryTransactionsUrl({+ filterValue: "__uncategorized__",+ startDate: "2026-05-01",+ endDate: "2026-05-31",+ });+ assert.match(url, /q%5Bcategories%5D%5B%5D=__uncategorized__/);+});+test("omits date params when dates are blank", () => {const url = buildCategoryTransactionsUrl({- name: "Groceries",+ filterValue: "Groceries",startDate: "",endDate: "",});diff --git a/test/models/assistant/function/get_transactions_test.rb b/test/models/assistant/function/get_transactions_test.rbindex 9d5f144826..8f965e780b 100644--- a/test/models/assistant/function/get_transactions_test.rb+++ b/test/models/assistant/function/get_transactions_test.rb@@ -42,6 +42,51 @@ class Assistant::Function::GetTransactionsTest < ActiveSupport::TestCaseassert_empty result[:transactions]end+ test "translates the documented Uncategorized category alias to the filter sentinel" do+ uncategorized_entry = Entry.create!(+ account: accounts(:depository),+ name: "AI uncategorized lookup",+ date: Date.current,+ amount: 42,+ currency: "USD",+ entryable: Transaction.new+ )++ result = @function.call("categories" => [ "Uncategorized" ])+ result_ids = result[:transactions].map { |t| t[:id] }++ assert_includes result_ids, uncategorized_entry.entryable.id+ end++ test "a real category literally named Uncategorized takes priority over the alias translation" do+ family = @user.family+ lookalike_category = family.categories.create!(name: "Uncategorized", color: "#123456")++ lookalike_entry = Entry.create!(+ account: accounts(:depository),+ name: "AI lookalike category lookup",+ date: Date.current,+ amount: 42,+ currency: "USD",+ entryable: Transaction.new(category: lookalike_category)+ )++ truly_uncategorized_entry = Entry.create!(+ account: accounts(:depository),+ name: "AI truly uncategorized lookup",+ date: Date.current,+ amount: 42,+ currency: "USD",+ entryable: Transaction.new+ )++ result = @function.call("categories" => [ "Uncategorized" ])+ result_ids = result[:transactions].map { |t| t[:id] }++ assert_includes result_ids, lookalike_entry.entryable.id+ assert_not_includes result_ids, truly_uncategorized_entry.entryable.id+ end+test "schema no longer inlines user data enums" doschema = @function.params_schemadiff --git a/test/models/category_test.rb b/test/models/category_test.rbindex c227b1ebc3..803e08e3d0 100644--- a/test/models/category_test.rb+++ b/test/models/category_test.rb@@ -91,6 +91,30 @@ class CategoryTest < ActiveSupport::TestCaseendend+ test "rejects the reserved Uncategorized filter sentinel as a name" do+ category = Category.new(name: Category::UNCATEGORIZED_FILTER_VALUE, color: "#123456", lucide_icon: "folder", family: @family)++ assert_not category.valid?+ assert_includes category.errors[:name], "is reserved"+ end++ test "filter_value returns the sentinel for the synthetic Uncategorized category and the name for real categories" do+ assert_equal Category::UNCATEGORIZED_FILTER_VALUE, Category.uncategorized.filter_value+ assert_equal categories(:food_and_drink).name, categories(:food_and_drink).filter_value+ end++ test "filter_value stays the sentinel even when read under a different locale than it was built in" do+ # Regression test: filter_value must not rely on a locale-sensitive name+ # comparison (uncategorized? checks name against I18n.t in the *current*+ # locale), or a synthetic instance built under one locale and read under+ # another would silently stop matching.+ synthetic = I18n.with_locale(:"zh-CN") { Category.uncategorized }++ I18n.with_locale(:en) do+ assert_equal Category::UNCATEGORIZED_FILTER_VALUE, synthetic.filter_value+ end+ end+test "display_name preserves custom category names" docategory = Category.new(name: "School Supplies", color: "#123456", lucide_icon: "book", family: @family)diff --git a/test/models/transaction/search_test.rb b/test/models/transaction/search_test.rbindex 00b68f260a..06cfe06028 100644--- a/test/models/transaction/search_test.rb+++ b/test/models/transaction/search_test.rb@@ -120,7 +120,7 @@ class Transaction::SearchTest < ActiveSupport::TestCase)# Search for uncategorized transactions- uncategorized_results = Transaction::Search.new(@family, filters: { categories: [ Category.uncategorized.name ] }).transactions_scope+ uncategorized_results = Transaction::Search.new(@family, filters: { categories: [ Category::UNCATEGORIZED_FILTER_VALUE ] }).transactions_scopeuncategorized_ids = uncategorized_results.pluck(:id)# Should include standard uncategorized transactions@@ -153,7 +153,7 @@ class Transaction::SearchTest < ActiveSupport::TestCaseloan_payment = create_transaction(account: @loan_account, amount: 300, kind: "loan_payment")investment_contribution = create_transaction(account: @checking_account, amount: 400, kind: "investment_contribution")- uncategorized_ids = Transaction::Search.new(@family, filters: { categories: [ Category.uncategorized.name ] })+ uncategorized_ids = Transaction::Search.new(@family, filters: { categories: [ Category::UNCATEGORIZED_FILTER_VALUE ] }).transactions_scope.pluck(:id)assert_includes uncategorized_ids, loan_payment.entryable.id,@@ -172,7 +172,7 @@ class Transaction::SearchTest < ActiveSupport::TestCasecreate_transaction(account: account, amount: 100, kind: kind).entryable.idend- filter_ids = Transaction::Search.new(@family, filters: { categories: [ Category.uncategorized.name ] })+ filter_ids = Transaction::Search.new(@family, filters: { categories: [ Category::UNCATEGORIZED_FILTER_VALUE ] }).transactions_scope.pluck(:id).to_setwizard_ids = @family.entries.uncategorized_transactions.pluck(:entryable_id).to_set@@ -203,7 +203,7 @@ class Transaction::SearchTest < ActiveSupport::TestCase)# Filter for only uncategorized- results = Transaction::Search.new(@family, filters: { categories: [ Category.uncategorized.name ] }).transactions_scope+ results = Transaction::Search.new(@family, filters: { categories: [ Category::UNCATEGORIZED_FILTER_VALUE ] }).transactions_scoperesult_ids = results.pluck(:id)# Should only include uncategorized transaction@@ -238,7 +238,7 @@ class Transaction::SearchTest < ActiveSupport::TestCase)# Filter for food category + uncategorized- results = Transaction::Search.new(@family, filters: { categories: [ "Food & Drink", Category.uncategorized.name ] }).transactions_scope+ results = Transaction::Search.new(@family, filters: { categories: [ "Food & Drink", Category::UNCATEGORIZED_FILTER_VALUE ] }).transactions_scoperesult_ids = results.pluck(:id)# Should include both food and uncategorized@@ -597,8 +597,9 @@ class Transaction::SearchTest < ActiveSupport::TestCaseassert_not_includes result_ids, no_match.entryable.idend- test "uncategorized filter returns same results across all supported locales" do- # Create uncategorized transactions+ test "uncategorized filter works regardless of current locale since the filter value is a stable sentinel" do+ # The category filter now matches on the stable Category::UNCATEGORIZED_FILTER_VALUE sentinel+ # (not the translated display name), so the current locale can no longer affect matching.uncategorized1 = create_transaction(account: @checking_account,amount: 100,@@ -611,7 +612,6 @@ class Transaction::SearchTest < ActiveSupport::TestCasekind: "standard")- # Create a categorized transaction to ensure filter is workingcategorized = create_transaction(account: @checking_account,amount: 300,@@ -619,75 +619,45 @@ class Transaction::SearchTest < ActiveSupport::TestCasekind: "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 nameLanguagesHelper::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+ results = Transaction::Search.new(@family, filters: { categories: [ Category::UNCATEGORIZED_FILTER_VALUE ] }).transactions_scope+ result_ids = results.pluck(:id)- assert_equal @expected_count, result_count,- "Locale '#{locale}' with uncategorized name '#{localized_uncategorized_name}' should return #{@expected_count} transactions but got #{result_count}"+ assert_includes result_ids, uncategorized1.entryable.id+ assert_includes result_ids, uncategorized2.entryable.id+ assert_not_includes result_ids, categorized.entryable.idendendend- 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+ test "a real category literally named like the localized Uncategorized label remains selectable" do+ # Regression test: filter values are opaque sentinels (Category::UNCATEGORIZED_FILTER_VALUE), not the+ # translated display name, so a category a user happens to name "Uncategorized" can't be misdetected+ # as the synthetic filter option.+ lookalike_category = @family.categories.create!(+ name: Category.uncategorized_name,+ color: "#123456"+ )- # Create uncategorized transactions- uncategorized1 = create_transaction(+ lookalike_transaction = create_transaction(account: @checking_account,amount: 100,+ category: lookalike_category,kind: "standard")- uncategorized2 = create_transaction(+ uncategorized_transaction = 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+ results = Transaction::Search.new(@family, filters: { categories: [ lookalike_category.name ] }).transactions_scope+ result_ids = results.pluck(:id)- 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+ assert_includes result_ids, lookalike_transaction.entryable.id+ assert_not_includes result_ids, uncategorized_transaction.entryable.idendtest "filtering for only No merchant returns only transactions without a merchant" dodiff --git a/test/system/property_test.rb b/test/system/property_test.rbindex 7e905b645a..24610146e4 100644--- a/test/system/property_test.rb+++ b/test/system/property_test.rb@@ -30,8 +30,11 @@ class PropertiesEditTest < ApplicationSystemTestCase# racing the broadcast.def open_account_edit_dialog3.times do- # A prior (slow) attempt may have already opened the edit form.- return if has_selector?("#account_accountable_attributes_subtype", wait: 0)+ # A prior (slow) attempt may have already opened the edit form. Check+ # the field is enabled, not just present — the select briefly exists+ # but disabled while the form finishes hydrating, and assert_field's+ # default matcher (used by the caller) excludes disabled fields.+ return if has_field?("account_accountable_attributes_subtype", wait: 0)beginwithin_testid("account-menu") do@@ -50,9 +53,9 @@ class PropertiesEditTest < ApplicationSystemTestCase)nextend- return if has_selector?("#account_accountable_attributes_subtype", wait: 2)+ return if has_field?("account_accountable_attributes_subtype", wait: 2)end- assert_selector "#account_accountable_attributes_subtype"+ assert_field "account_accountable_attributes_subtype"enddef open_new_account_modal