The personal finance app for everyone (by everyone)
Ruby
feat: Include notes in transaction search (#615)
Alessio Cappa9aa9b3a1b032
diff --git a/app/models/entry_search.rb b/app/models/entry_search.rbindex 7d81dda558..b082cac34b 100644--- a/app/models/entry_search.rb+++ b/app/models/entry_search.rb@@ -17,7 +17,7 @@ class EntrySearchreturn 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)}%")querydiff --git a/test/models/transaction/search_test.rb b/test/models/transaction/search_test.rbindex c4cf8f53c5..bdfb264ac1 100644--- a/test/models/transaction/search_test.rb+++ b/test/models/transaction/search_test.rb@@ -365,4 +365,49 @@ class Transaction::SearchTest < ActiveSupport::TestCaseassert_equal 0, totals.countassert_equal Money.new(0, "USD"), totals.expense_moneyend++ 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+ endend