Browse Source
* Add search to organisations * Fix title * Spec page title * Don't seed org in testpull/619/head
17 changed files with 248 additions and 104 deletions
@ -0,0 +1,13 @@
|
||||
module Modules::SearchFilter |
||||
def filtered_collection(base_collection, search_term = nil) |
||||
if search_term.present? |
||||
base_collection.search_by(search_term) |
||||
else |
||||
base_collection |
||||
end |
||||
end |
||||
|
||||
def filtered_users(base_collection, search_term = nil) |
||||
filtered_collection(base_collection, search_term).filter_by_active.includes(:organisation) |
||||
end |
||||
end |
@ -1,9 +0,0 @@
|
||||
module Modules::UsersFilter |
||||
def filtered_users(base_collection, search_term = nil) |
||||
if search_term.present? |
||||
base_collection.search_by(search_term) |
||||
else |
||||
base_collection |
||||
end.filter_by_active.includes(:organisation) |
||||
end |
||||
end |
@ -1,2 +1,15 @@
|
||||
<%= render partial: "organisation_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy } %> |
||||
<% item_label = @pagy.count > 1 ? "organisations" : "organisation" %> |
||||
<% if @searched.present? %> |
||||
<% title = "Organisations (#{@pagy.count} #{item_label} matching ‘#{@searched}’ of #{@total_count} total organisations)" %> |
||||
<% else %> |
||||
<% title = "Organisations" %> |
||||
<% end %> |
||||
|
||||
<% content_for :title, title %> |
||||
|
||||
<%= render SearchComponent.new(current_user:, search_label: "Search by organisation name", value: @searched) %> |
||||
|
||||
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m"> |
||||
|
||||
<%= render partial: "organisation_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> |
||||
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> |
||||
|
@ -0,0 +1,56 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Modules::SearchFilter do |
||||
subject(:instance) { Class.new.include(described_class).new } |
||||
|
||||
describe "filtered_collection" do |
||||
before do |
||||
FactoryBot.create_list(:organisation, 5) |
||||
FactoryBot.create(:organisation, name: "Acme LTD") |
||||
end |
||||
|
||||
let(:organisation_list) { Organisation.all } |
||||
|
||||
context "when given a search term" do |
||||
let(:search_term) { "Acme" } |
||||
|
||||
it "filters the collection on search term" do |
||||
expect(instance.filtered_collection(organisation_list, search_term).count).to eq(1) |
||||
end |
||||
end |
||||
|
||||
context "when not given a search term" do |
||||
let(:search_term) { nil } |
||||
|
||||
it "does not filter the given collection" do |
||||
expect(instance.filtered_collection(organisation_list, search_term).count).to eq(6) |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe "filtered_users" do |
||||
before do |
||||
FactoryBot.create_list(:user, 5) |
||||
FactoryBot.create(:user, name: "Joe Blogg") |
||||
FactoryBot.create(:user, name: "Tom Blogg", active: false) |
||||
end |
||||
|
||||
let(:user_list) { User.all } |
||||
|
||||
context "when given a search term" do |
||||
let(:search_term) { "Blogg" } |
||||
|
||||
it "filters the collection on search term and active users" do |
||||
expect(instance.filtered_users(user_list, search_term).count).to eq(1) |
||||
end |
||||
end |
||||
|
||||
context "when not given a search term" do |
||||
let(:search_term) { nil } |
||||
|
||||
it "filters the collection on active users" do |
||||
expect(instance.filtered_users(user_list, search_term).count).to eq(6) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,31 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Modules::UsersFilter do |
||||
describe "filtered_users" do |
||||
subject(:instance) { Class.new.include(described_class).new } |
||||
|
||||
before do |
||||
FactoryBot.create_list(:user, 5) |
||||
FactoryBot.create(:user, name: "Joe Blogg") |
||||
FactoryBot.create(:user, name: "Tom Blogg", active: false) |
||||
end |
||||
|
||||
let(:user_list) { User.all } |
||||
|
||||
context "when given a search term" do |
||||
let(:search_term) { "Blogg" } |
||||
|
||||
it "filters the collection on search term and active users" do |
||||
expect(instance.filtered_users(user_list, search_term).count).to eq(1) |
||||
end |
||||
end |
||||
|
||||
context "when not given a search term" do |
||||
let(:search_term) { nil } |
||||
|
||||
it "filters the collection on active users" do |
||||
expect(instance.filtered_users(user_list, search_term).count).to eq(6) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue