no crash when q is missing on RechercheController::index

This commit is contained in:
clemkeirua 2019-05-22 14:34:46 +02:00
parent 64009a5e10
commit f06ae1631f
2 changed files with 13 additions and 1 deletions

View file

@ -38,7 +38,8 @@ class DossierSearchService
end
def self.to_tsquery(search_terms)
search_terms.strip
(search_terms || "")
.strip
.gsub(/['?\\:&|!<>\(\)]/, "") # drop disallowed characters
.split(/\s+/) # split words
.map { |x| "#{x}:*" } # enable prefix matching

View file

@ -48,5 +48,16 @@ describe Gestionnaires::RechercheController, type: :controller do
end
end
end
context 'with no query param it does not crash' do
subject { get :index, params: {} }
it { is_expected.to have_http_status(200) }
it 'returns 0 dossier' do
subject
expect(assigns(:dossiers).count).to eq(0)
end
end
end
end