autocomplete: fix exception when type param is missing.

This commit is contained in:
evazion
2021-01-01 04:06:38 -06:00
parent 430ba5dced
commit 5b7894a8b2
2 changed files with 8 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ class AutocompleteService
def initialize(query, type, current_user: User.anonymous, limit: 10)
@query = query.to_s
@type = type.to_sym
@type = type.to_s.to_sym
@current_user = current_user
@limit = limit
end

View File

@@ -35,6 +35,13 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
assert_autocomplete_equals(["rating:safe"], "-rating:s", "tag_query")
end
should "work for a missing type" do
get autocomplete_index_path(search: { query: "azur" }), as: :json
assert_response :success
assert_equal([], response.parsed_body)
end
should "not set session cookies when the response is publicly cached" do
get autocomplete_index_path(search: { query: "azur", type: "tag_query" }), as: :json