Browse Source

Search is now non case sensitive

pull/600/head
Ted 3 years ago committed by baarkerlounger
parent
commit
0e3950be74
  1. 2
      app/controllers/users_controller.rb
  2. 25
      spec/requests/users_controller_spec.rb

2
app/controllers/users_controller.rb

@ -80,7 +80,7 @@ private
def filtered_users def filtered_users
search_param = params["user-search-field"] search_param = params["user-search-field"]
if search_param if search_param
User.where("name LIKE ?", "%#{search_param}%").where(active: true).includes(:organisation) User.where("name ILIKE ?", "%#{search_param}%").where(active: true).includes(:organisation)
else else
User.all.where(active: true).includes(:organisation) User.all.where(active: true).includes(:organisation)
end end

25
spec/requests/users_controller_spec.rb

@ -757,14 +757,27 @@ RSpec.describe UsersController, type: :request do
context "when a search parameter is passed" do context "when a search parameter is passed" do
before do before do
get "/users?user-search-field=Danny" get "/users?user-search-field=#{search_param}"
end end
it "returns only matching results" do context "when our search string matches case" do
expect(page).to have_content(user.name) let (:search_param){"Danny"}
expect(page).not_to have_content(other_user.name) it "returns only matching results" do
expect(page).not_to have_content(inactive_user.name) expect(page).to have_content(user.name)
expect(page).not_to have_content(other_org_user.name) expect(page).not_to have_content(other_user.name)
expect(page).not_to have_content(inactive_user.name)
expect(page).not_to have_content(other_org_user.name)
end
end
context "when we need case insensitive search" do
let (:search_param){"danny"}
it "returns only matching results" do
expect(page).to have_content(user.name)
expect(page).not_to have_content(other_user.name)
expect(page).not_to have_content(inactive_user.name)
expect(page).not_to have_content(other_org_user.name)
end
end end
end end
end end

Loading…
Cancel
Save