assigns: strip and lowercase the search filter

This commit is contained in:
Pierre de La Morinerie 2019-11-06 12:05:41 +01:00
parent 0eeac59ecd
commit 8df91df9fa
2 changed files with 11 additions and 2 deletions

View file

@ -17,8 +17,9 @@ class Admin::AssignsController < AdminController
not_assign_scope = current_administrateur.instructeurs.where.not(id: assign_scope.ids)
if params[:filter]
not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{params[:filter]}%")
if params[:filter].present?
filter = params[:filter].downcase.strip
not_assign_scope = not_assign_scope.where('users.email LIKE ?', "%#{filter}%")
end
@instructeurs_not_assign = smart_listing_create :instructeurs_not_assign,

View file

@ -34,6 +34,14 @@ describe Admin::AssignsController, type: :controller do
it 'does not filter the assigned instructeurs' do
expect(assigns(:instructeurs_assign)).to match_array([instructeur_assigned_1, instructeur_assigned_2])
end
context 'when the filter has spaces or a mixed case' do
let(:filter) { ' @ministere_A.gouv.fr ' }
it 'trims spaces and ignores the case' do
expect(assigns(:instructeurs_not_assign)).to match_array([instructeur_not_assigned_1])
end
end
end
end