feat: Include notes in transaction search (#615)

* feat: Include notes in transaction search

* Add tests
This commit is contained in:
Alessio Cappa
2026-01-11 18:59:40 +01:00
committed by GitHub
parent 726c84580d
commit 9aa9b3a1b0
2 changed files with 46 additions and 1 deletions

View File

@@ -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