From 9aa9b3a1b032f1a1be6c6137fb6b39d0d2b450aa Mon Sep 17 00:00:00 2001 From: Alessio Cappa <104093777+alessiocappa@users.noreply.github.com> Date: Sun, 11 Jan 2026 18:59:40 +0100 Subject: [PATCH] feat: Include notes in transaction search (#615) * feat: Include notes in transaction search * Add tests --- app/models/entry_search.rb | 2 +- test/models/transaction/search_test.rb | 45 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/models/entry_search.rb b/app/models/entry_search.rb index 7d81dda55..b082cac34 100644 --- a/app/models/entry_search.rb +++ b/app/models/entry_search.rb @@ -17,7 +17,7 @@ class EntrySearch return scope if search.blank? query = scope - query = query.where("entries.name ILIKE :search", + query = query.where("entries.name ILIKE :search OR entries.notes ILIKE :search", search: "%#{ActiveRecord::Base.sanitize_sql_like(search)}%" ) query diff --git a/test/models/transaction/search_test.rb b/test/models/transaction/search_test.rb index c4cf8f53c..bdfb264ac 100644 --- a/test/models/transaction/search_test.rb +++ b/test/models/transaction/search_test.rb @@ -365,4 +365,49 @@ class Transaction::SearchTest < ActiveSupport::TestCase assert_equal 0, totals.count assert_equal Money.new(0, "USD"), totals.expense_money end + + test "search matches entries name OR notes with ILIKE" do + # Transaction with matching text in name only + name_match = create_transaction( + account: @checking_account, + amount: 100, + kind: "standard", + name: "Grocery Store" + ) + + # Transaction with matching text in notes only + notes_match = create_transaction( + account: @checking_account, + amount: 50, + kind: "standard", + name: "Credit Card Payment", + notes: "Payment of 50 USD at Grocery Mart on 2026-11-01" + ) + + # Transaction with no matching text + no_match = create_transaction( + account: @checking_account, + amount: 75, + kind: "standard", + name: "Gas station", + notes: "Fuel refill" + ) + + search = Transaction::Search.new( + @family, + filters: { search: "grocery" } + ) + + results = search.transactions_scope + result_ids = results.pluck(:id) + + # Should match name + assert_includes result_ids, name_match.entryable.id + + # Should match notes + assert_includes result_ids, notes_match.entryable.id + + # Should not match unrelated transactions + assert_not_includes result_ids, no_match.entryable.id + end end