DEV: raise error if search term length is less than required
This commit is contained in:
parent
341a6bd78a
commit
a313b01148
|
@ -9,6 +9,9 @@ class SearchController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@search_term = params.require(:q)
|
||||
raise Discourse::InvalidParameters.new(:q) if @search_term.length < SiteSetting.min_search_term_length
|
||||
|
||||
search_args = {
|
||||
type_filter: 'topic',
|
||||
guardian: guardian,
|
||||
|
@ -29,7 +32,6 @@ class SearchController < ApplicationController
|
|||
search_args[:ip_address] = request.remote_ip
|
||||
search_args[:user_id] = current_user.id if current_user.present?
|
||||
|
||||
@search_term = params[:q]
|
||||
search = Search.new(@search_term, search_args)
|
||||
result = search.execute
|
||||
|
||||
|
|
|
@ -127,6 +127,11 @@ describe SearchController do
|
|||
end
|
||||
|
||||
context "#show" do
|
||||
it "raises an error when the search term length is less than required" do
|
||||
get "/search.json", params: { q: 'ba' }
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
it "logs the search term" do
|
||||
SiteSetting.log_search_queries = true
|
||||
get "/search.json", params: { q: 'bantha' }
|
||||
|
|
Loading…
Reference in New Issue