Browse Source

Made search work for data co-ordinators

Co-authored-by: baarkerlounger  <baarkerlounger@users.noreply.github.com>
pull/600/head
Ted 3 years ago committed by baarkerlounger
parent
commit
7b7150735e
  1. 11
      app/controllers/organisations_controller.rb
  2. 3
      app/views/users/index.html.erb
  3. 31
      spec/requests/users_controller_spec.rb

11
app/controllers/organisations_controller.rb

@ -17,7 +17,7 @@ class OrganisationsController < ApplicationController
end end
def users def users
@pagy, @users = pagy(@organisation.users.where(active: true)) @pagy, @users = pagy(filtered_users)
render "users/index" render "users/index"
end end
@ -58,6 +58,15 @@ class OrganisationsController < ApplicationController
private private
def filtered_users
search_param = params["user-search-field"]
if search_param
User.where("name ILIKE ?", "%#{search_param}%").where(active: true)
else
User.all.where(active: true)
end
end
def org_params def org_params
params.require(:organisation).permit(:name, :address_line1, :address_line2, :postcode, :phone) params.require(:organisation).permit(:name, :address_line1, :address_line2, :postcode, :phone)
end end

3
app/views/users/index.html.erb

@ -8,7 +8,8 @@
<%= govuk_button_link_to "Invite user", new_user_path, html: { method: :get } %> <%= govuk_button_link_to "Invite user", new_user_path, html: { method: :get } %>
<% end %> <% end %>
<%= form_with model: @user, url: users_path(), method: "get", local: true do |f| %> <% path = current_user.support? ? users_path : users_organisation_path(current_user.organisation) %>
<%= form_with model: @user, url: path, method: "get", local: true do |f| %>
<div class="app-search govuk-!-margin-bottom-4"> <div class="app-search govuk-!-margin-bottom-4">
<div class="govuk-form-group app-search__form-group"> <div class="govuk-form-group app-search__form-group">
<label class="govuk-label govuk-!-margin-bottom-2" for="user-search-field"> <label class="govuk-label govuk-!-margin-bottom-2" for="user-search-field">

31
spec/requests/users_controller_spec.rb

@ -336,7 +336,7 @@ RSpec.describe UsersController, type: :request do
context "when user is signed in as a data coordinator" do context "when user is signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let(:other_user) { FactoryBot.create(:user, organisation: user.organisation) } let!(:other_user) { FactoryBot.create(:user, organisation: user.organisation, name: "filter name") }
describe "#index" do describe "#index" do
before do before do
@ -352,6 +352,33 @@ RSpec.describe UsersController, type: :request do
it "does not show the download csv link" do it "does not show the download csv link" do
expect(page).not_to have_link("Download (CSV)", href: "/users.csv") expect(page).not_to have_link("Download (CSV)", href: "/users.csv")
end end
it "shows a search bar" do
follow_redirect!
expect(page).to have_field("user-search-field", type: "search")
end
context "when a search parameter is passed" do
before do
get "/organisations/#{user.organisation.id}/users?user-search-field=#{search_param}"
end
context "when our search string matches case" do
let (:search_param){"filter"}
it "returns only matching results" do
expect(page).not_to have_content(user.name)
expect(page).to have_content(other_user.name)
end
end
context "when we need case insensitive search" do
let (:search_param){"Filter"}
it "returns only matching results" do
expect(page).not_to have_content(user.name)
expect(page).to have_content(other_user.name)
end
end
end
end end
describe "CSV download" do describe "CSV download" do
@ -613,7 +640,7 @@ RSpec.describe UsersController, type: :request do
it "does update other values" do it "does update other values" do
expect { patch "/users/#{other_user.id}", headers:, params: } expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.name }.from("Danny Rojas").to("new name") .to change { other_user.reload.name }.from("filter name").to("new name")
end end
end end
end end

Loading…
Cancel
Save