FIX: raises an error if q param is empty in search page

This commit is contained in:
Vinoth Kannan 2018-12-20 21:43:14 +05:30
parent 400eea4d13
commit e7e4074856
2 changed files with 7 additions and 2 deletions

View File

@ -9,8 +9,8 @@ class SearchController < ApplicationController
end end
def show def show
@search_term = params.require(:q) @search_term = params[:q]
raise Discourse::InvalidParameters.new(:q) if @search_term.length < SiteSetting.min_search_term_length raise Discourse::InvalidParameters.new(:q) if @search_term.present? && @search_term.length < SiteSetting.min_search_term_length
search_args = { search_args = {
type_filter: 'topic', type_filter: 'topic',

View File

@ -127,6 +127,11 @@ describe SearchController do
end end
context "#show" do context "#show" do
it "doesn't raise an error when search term not specified" do
get "/search"
expect(response.status).to eq(200)
end
it "raises an error when the search term length is less than required" do it "raises an error when the search term length is less than required" do
get "/search.json", params: { q: 'ba' } get "/search.json", params: { q: 'ba' }
expect(response.status).to eq(400) expect(response.status).to eq(400)