diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index cc5751edf..12bf285d2 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -59,9 +59,9 @@ class OrganisationsController < ApplicationController private def filtered_users - if search_param = params["user-search-field"] + if (search_param = params["user-search-field"]) User.search_by(search_param) - else + else User.all end.filter_by_active end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 375a1052c..cb3b5fc51 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -78,9 +78,9 @@ class UsersController < ApplicationController private def filtered_users - if search_param = params["user-search-field"] + if (search_param = params["user-search-field"]) User.search_by(search_param) - else + else User.all end.filter_by_active end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 07845ac21..12ee95780 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -811,36 +811,33 @@ RSpec.describe UsersController, type: :request do expect(page).not_to have_content(other_org_user.name) end end - - context "when our search term matches an email" do - let(:search_param) { "other_org@other_example.com" } + context "when our search term matches an email" do + let(:search_param) { "other_org@other_example.com" } - it "returns only matching result" do - expect(page).not_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).to have_content(other_org_user.name) + it "returns only matching result" do + expect(page).not_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).to have_content(other_org_user.name) + end end - end - - context "when our search term matches an email and a name" do - let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "joe", email: "other@example.com") } - let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@other_example.com") } - let(:search_param) { "joe" } - - it "returns any results including joe" do - expect(page).to have_content(other_user.name) - expect(page).not_to have_content(inactive_user.name) - expect(page).to have_content(other_org_user.name) - expect(page).not_to have_content(user.name) + context "when our search term matches an email and a name" do + let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "joe", email: "other@example.com") } + let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@other_example.com") } + let(:search_param) { "joe" } + + it "returns any results including joe" do + expect(page).to have_content(other_user.name) + expect(page).not_to have_content(inactive_user.name) + expect(page).to have_content(other_org_user.name) + expect(page).not_to have_content(user.name) + end end end end end - end - describe "CSV download" do let(:headers) { { "Accept" => "text/csv" } }