Strip search query of leading & trailing whitespace

This commit is contained in:
James Kiesel 2014-10-09 23:28:30 +13:00
parent d44300c7a2
commit 206ec99f8f
2 changed files with 12 additions and 1 deletions

View file

@ -20,7 +20,7 @@ class SearchController < ApplicationController
private
def search_query
@search_query ||= params[:q] || params[:term] || ''
@search_query ||= (params[:q] || params[:term] || '').strip
end
end

View file

@ -35,5 +35,16 @@ describe SearchController, :type => :controller do
end
end
describe '#search_query' do
it 'strips the term parameter' do
@controller.params[:term] = ' IN SPACE! '
expect(@controller.send(:search_query)).to eq 'IN SPACE!'
end
it 'strips the q parameter' do
@controller.params[:q] = ' IN SPACE! '
expect(@controller.send(:search_query)).to eq 'IN SPACE!'
end
end
end