Files
once-campfire/test/controllers/searches_controller_test.rb
T
Marcello Costagliola 6cdcb459b9 Search for operator words instead of parsing them
The search box keeps only word characters, but FTS5 still reads AND, OR,
NOT and NEAR in the query as operators, so searching for "AND" or for
"salt AND" raised "fts5: syntax error" and answered with a 500. Quoting
each word makes FTS5 look for it as text, which is how it already treats
the same words in lower case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NuTtwJKhb77Dv7EQqv2C3C
2026-10-05 01:08:53 +02:00

67 lines
1.7 KiB
Ruby

require "test_helper"
class SearchesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in :david
@message = rooms(:designers).messages.create! body: "Hello world!", client_message_id: "search", creator: users(:david)
end
test "index initial view" do
get searches_url
assert_response :success
assert_select ".message", count: 0
end
test "finding reachable messages" do
get searches_url, params: { q: "hello" }
assert_response :success
assert_select ".message", text: /Hello world!/
end
test "operator words are searched for as words" do
rooms(:designers).messages.create! body: "Salt and pepper", client_message_id: "operators", creator: users(:david)
get searches_url, params: { q: "salt AND" }
assert_response :success
assert_select ".message", text: /Salt and pepper/
end
test "searching for an operator word alone doesn't fail" do
%w[ AND OR NOT ].each do |word|
get searches_url, params: { q: word }
assert_response :success
assert_select ".message", count: 0
end
end
test "unreachable messages are not found" do
memberships(:david_designers).destroy!
get searches_url, params: { q: "hello" }
assert_response :success
assert_select ".message", count: 0
end
test "create saves the search term" do
assert_difference -> { users(:david).searches.count }, +1 do
post searches_url, params: { q: "hello" }
end
assert_redirected_to searches_url(q: "hello")
assert users(:david).searches.exists?(query: "hello")
end
test "clear search history" do
assert users(:david).searches.any?
delete clear_searches_url
assert users(:david).searches.none?
end
end