From 5b7894a8b2d1015d142499d2742c1058cd060520 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 1 Jan 2021 04:06:38 -0600 Subject: [PATCH] autocomplete: fix exception when type param is missing. --- app/logical/autocomplete_service.rb | 2 +- test/functional/autocomplete_controller_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/logical/autocomplete_service.rb b/app/logical/autocomplete_service.rb index 23bb33f92..b870755b5 100644 --- a/app/logical/autocomplete_service.rb +++ b/app/logical/autocomplete_service.rb @@ -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 diff --git a/test/functional/autocomplete_controller_test.rb b/test/functional/autocomplete_controller_test.rb index ae372ab1f..fa877579d 100644 --- a/test/functional/autocomplete_controller_test.rb +++ b/test/functional/autocomplete_controller_test.rb @@ -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