From f83360af6f2dd503caf49725da40c29b8128af90 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 10:42:01 +0100 Subject: [PATCH 1/7] Basic search and results page - Add SearchesController with new and show actions - Add new.html.erb containing search form with last name input - Add show.html.erb with summary list rendering the result last_name - Update ApplicationController so that basic authentication used when service closed --- Gemfile | 1 + Gemfile.lock | 3 ++ app/controllers/application_controller.rb | 2 +- app/controllers/searches_controller.rb | 16 ++++++++++ app/views/searches/new.html.erb | 11 +++++++ app/views/searches/show.html.erb | 11 +++++++ config/locales/en.yml | 3 +- config/routes.rb | 5 +++- spec/rails_helper.rb | 3 +- .../support/system/activate_features_steps.rb | 5 ++++ spec/system/user_searches_list_spec.rb | 29 +++++++++++++++++++ 11 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 app/controllers/searches_controller.rb create mode 100644 app/views/searches/new.html.erb create mode 100644 app/views/searches/show.html.erb create mode 100644 spec/support/system/activate_features_steps.rb create mode 100644 spec/system/user_searches_list_spec.rb diff --git a/Gemfile b/Gemfile index d3b36727..a3175e7d 100644 --- a/Gemfile +++ b/Gemfile @@ -65,4 +65,5 @@ end group :test, :development do gem "rspec" gem "rspec-rails" + gem "launchy" end diff --git a/Gemfile.lock b/Gemfile.lock index 2acd3f6b..87f1c306 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,6 +142,8 @@ GEM kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) language_server-protocol (3.17.0.3) + launchy (2.5.2) + addressable (~> 2.8) loofah (2.21.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -357,6 +359,7 @@ DEPENDENCIES govuk_design_system_formbuilder govuk_feature_flags! jsbundling-rails + launchy okcomputer pg (~> 1.1) prettier_print diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6aa96e1c..48bfb498 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base default_form_builder(GOVUKDesignSystemFormBuilder::FormBuilder) - before_action :authenticate + before_action :authenticate, unless: -> { FeatureFlags::FeatureFlag.active?("service_open") } def authenticate valid_credentials = [ diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb new file mode 100644 index 00000000..9351a5cd --- /dev/null +++ b/app/controllers/searches_controller.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class SearchesController < ApplicationController + def new + end + + def show + @result = OpenStruct.new(last_name: search_params[:last_name]) + end + + private + + def search_params + params.permit(:last_name) + end +end diff --git a/app/views/searches/new.html.erb b/app/views/searches/new.html.erb new file mode 100644 index 00000000..5da6580a --- /dev/null +++ b/app/views/searches/new.html.erb @@ -0,0 +1,11 @@ +
+
+

Check the Children’s Barred List

+ + <%= form_with(url: result_path, method: :get) do |f| %> + <%= f.govuk_text_field :last_name, class: "govuk-input--width-20", label: { text: "Last name", size: "s" } %> + + <%= f.govuk_submit "Search" %> + <% end %> +
+
diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb new file mode 100644 index 00000000..dbe6faec --- /dev/null +++ b/app/views/searches/show.html.erb @@ -0,0 +1,11 @@ +

Record found

+ +<%= govuk_summary_list( + rows: [ + { key: { text: "Last name" }, value: { text: @result.last_name } } + ]) +%> + +

+ Contact DBS at <%= govuk_mail_to t('service.dbs_email'), t('service.dbs_email') %> for more details. +

diff --git a/config/locales/en.yml b/config/locales/en.yml index b86ee818..352260d8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,5 @@ en: service: name: Check the Childen's Barred List - email: my-service@email + email: employer.access@education.gov.uk + dbs_email: dbscost@dbs.gov.uk diff --git a/config/routes.rb b/config/routes.rb index b484fa11..4eab5bbe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do - root to: "pages#home" + root to: "searches#new" + + get "/search", to: "searches#new" + get "/result", to: "searches#show" mount FeatureFlags::Engine => "/features" end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e51fe7eb..62c5f7f9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -15,7 +15,7 @@ app, timeout: 10, process_timeout: 30, - window_size: [1200, 800] + window_size: [1200, 800], ) end Capybara.default_driver = :cuprite @@ -72,6 +72,7 @@ # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! + config.before(:each, type: :system) { driven_by(:cuprite) } # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") end diff --git a/spec/support/system/activate_features_steps.rb b/spec/support/system/activate_features_steps.rb new file mode 100644 index 00000000..c8dfa210 --- /dev/null +++ b/spec/support/system/activate_features_steps.rb @@ -0,0 +1,5 @@ +module ActivateFeaturesSteps + def given_the_service_is_open + FeatureFlags::FeatureFlag.activate(:service_open) + end +end diff --git a/spec/system/user_searches_list_spec.rb b/spec/system/user_searches_list_spec.rb new file mode 100644 index 00000000..48654fb4 --- /dev/null +++ b/spec/system/user_searches_list_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Valid search", type: :system do + include ActivateFeaturesSteps + + scenario "User searches with a last name" do + given_the_service_is_open + and_i_visit_the_search_page + and_i_search_with_a_last_name + then_i_see_a_result + end + + private + + def and_i_visit_the_search_page + visit search_path + end + + def and_i_search_with_a_last_name + fill_in "Last name", with: "Doe" + click_button "Search" + end + + def then_i_see_a_result + expect(page).to have_content "Doe" + end +end From 8639aaefee51b0530f70e453a312ca69f97d28a9 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 10:48:19 +0100 Subject: [PATCH 2/7] Add validation to last_name in search form - Create SearchForm to handle validations on the search parameters - Add presence validation to last_name field - Add error message to en.yml --- app/controllers/searches_controller.rb | 11 ++++++-- app/forms/search_form.rb | 8 ++++++ app/views/searches/new.html.erb | 4 ++- config/locales/en.yml | 7 +++++ ..._searches_list_with_missing_params_spec.rb | 28 +++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 app/forms/search_form.rb create mode 100644 spec/system/user_searches_list_with_missing_params_spec.rb diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 9351a5cd..2baa2941 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -2,15 +2,22 @@ class SearchesController < ApplicationController def new + @search_form = SearchForm.new end def show - @result = OpenStruct.new(last_name: search_params[:last_name]) + @search_form = SearchForm.new(search_params) + + if @search_form.valid? + @result = OpenStruct.new(last_name: search_params[:last_name]) + else + render :new + end end private def search_params - params.permit(:last_name) + params.require(:search_form).permit(:last_name) end end diff --git a/app/forms/search_form.rb b/app/forms/search_form.rb new file mode 100644 index 00000000..3b2c3c51 --- /dev/null +++ b/app/forms/search_form.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class SearchForm + include ActiveModel::Model + attr_accessor :last_name + + validates :last_name, presence: true +end diff --git a/app/views/searches/new.html.erb b/app/views/searches/new.html.erb index 5da6580a..a61e8e5b 100644 --- a/app/views/searches/new.html.erb +++ b/app/views/searches/new.html.erb @@ -2,7 +2,9 @@

Check the Children’s Barred List

- <%= form_with(url: result_path, method: :get) do |f| %> + <%= form_with(model: @search_form, url: result_path, method: :get) do |f| %> + <%= f.govuk_error_summary %> + <%= f.govuk_text_field :last_name, class: "govuk-input--width-20", label: { text: "Last name", size: "s" } %> <%= f.govuk_submit "Search" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 352260d8..eba1168b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,3 +3,10 @@ en: name: Check the Childen's Barred List email: employer.access@education.gov.uk dbs_email: dbscost@dbs.gov.uk + activemodel: + errors: + models: + search_form: + attributes: + last_name: + blank: Enter a last name diff --git a/spec/system/user_searches_list_with_missing_params_spec.rb b/spec/system/user_searches_list_with_missing_params_spec.rb new file mode 100644 index 00000000..40a16c09 --- /dev/null +++ b/spec/system/user_searches_list_with_missing_params_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Invalid search", type: :system do + include ActivateFeaturesSteps + + scenario "User searches without a last name" do + given_the_service_is_open + and_i_visit_the_search_page + and_i_click_search + then_i_see_an_error + end + + private + + def and_i_visit_the_search_page + visit search_path + end + + def and_i_click_search + click_button "Search" + end + + def then_i_see_an_error + expect(page).to have_content("Enter a last name") + end +end From 0174a998e218a8ca19fb7bbede5a71aa48726169 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 10:49:28 +0100 Subject: [PATCH 3/7] Update link to feedback to match prototype --- app/views/layouts/application.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0f4d6657..ce52a9e2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,7 +31,9 @@
<%= govuk_phase_banner(tag: { text: "Beta" }) do %> - This is a new service – <%= govuk_link_to("your feedback will help us to improve it.", t('service.feedback_form')) %> + This is a new service – your + <%= govuk_link_to("feedback", t('service.feedback_form')) %> + will help us to improve it. <% end %> <%= govuk_back_link(href: yield(:back_link_url)) if content_for?(:back_link_url) %> <%= yield(:breadcrumbs) if content_for?(:breadcrumbs) %> From 9e9c9f0c2f867f318ecb00df9566648dd6ea50d7 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 10:52:17 +0100 Subject: [PATCH 4/7] Remove old pages controller and rename authentication spec --- app/controllers/pages_controller.rb | 4 ---- spec/requests/{pages_spec.rb => authentication_spec.rb} | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 app/controllers/pages_controller.rb rename spec/requests/{pages_spec.rb => authentication_spec.rb} (81%) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb deleted file mode 100644 index 45f463e4..00000000 --- a/app/controllers/pages_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -class PagesController < ApplicationController - def home - end -end diff --git a/spec/requests/pages_spec.rb b/spec/requests/authentication_spec.rb similarity index 81% rename from spec/requests/pages_spec.rb rename to spec/requests/authentication_spec.rb index a4cdc515..e4ea6a8e 100644 --- a/spec/requests/pages_spec.rb +++ b/spec/requests/authentication_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" -RSpec.describe "Pages", type: :request do - describe "GET /home" do +RSpec.describe "Authentication", type: :request do + describe "GET /" do it "requires authentication" do get "/" expect(response).to have_http_status(:unauthorized) @@ -11,7 +11,7 @@ let(:credentials) do ActionController::HttpAuthentication::Basic.encode_credentials( ENV.fetch("SUPPORT_USERNAME", "support"), - ENV.fetch("SUPPORT_PASSWORD", "support") + ENV.fetch("SUPPORT_PASSWORD", "support"), ) end From 8d7a64fea8321905eb5af4f19fac308d8f897b9b Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 13:53:44 +0100 Subject: [PATCH 5/7] Implement search across ChildrensBarredListEntry - New includes_record? method in ChidrensBarredListEntry model which checks whether theres a matching record on the list - Use new includes_record? method in SearchesController and redirect to no_record page if none found - New no_record page - Install factorybot for system specs and tidy up rails_helper.rb --- Gemfile | 3 +- Gemfile.lock | 6 +++ app/controllers/searches_controller.rb | 8 +++- app/models/childrens_barred_list_entry.rb | 4 ++ app/views/searches/no_record.html.erb | 15 +++++++ app/views/searches/show.html.erb | 22 +++++----- .../childrens_barred_list_entries.rb | 7 ++++ spec/rails_helper.rb | 40 +------------------ ...ser_searches_with_matching_record_spec.rb} | 14 +++++-- ...user_searches_with_missing_params_spec.rb} | 0 ...r_searches_with_no_matching_record_spec.rb | 35 ++++++++++++++++ 11 files changed, 100 insertions(+), 54 deletions(-) create mode 100644 app/views/searches/no_record.html.erb create mode 100644 spec/factories/childrens_barred_list_entries.rb rename spec/system/{user_searches_list_spec.rb => user_searches_with_matching_record_spec.rb} (55%) rename spec/system/{user_searches_list_with_missing_params_spec.rb => user_searches_with_missing_params_spec.rb} (100%) create mode 100644 spec/system/user_searches_with_no_matching_record_spec.rb diff --git a/Gemfile b/Gemfile index a3175e7d..ebf63d61 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,8 @@ group :test do end group :test, :development do + gem "factory_bot_rails" + gem "launchy" gem "rspec" gem "rspec-rails" - gem "launchy" end diff --git a/Gemfile.lock b/Gemfile.lock index 87f1c306..361a6050 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,11 @@ GEM diff-lcs (1.5.0) e2mmap (0.1.0) erubi (1.12.0) + factory_bot (6.2.1) + activesupport (>= 5.0.0) + factory_bot_rails (6.2.0) + factory_bot (~> 6.2.0) + railties (>= 5.0.0) ferrum (0.13) addressable (~> 2.5) concurrent-ruby (~> 1.1) @@ -355,6 +360,7 @@ DEPENDENCIES cssbundling-rails cuprite debug + factory_bot_rails govuk-components govuk_design_system_formbuilder govuk_feature_flags! diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 2baa2941..1e386d60 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -9,7 +9,7 @@ def show @search_form = SearchForm.new(search_params) if @search_form.valid? - @result = OpenStruct.new(last_name: search_params[:last_name]) + render :no_record unless any_records? else render :new end @@ -20,4 +20,10 @@ def show def search_params params.require(:search_form).permit(:last_name) end + + def any_records? + ChildrensBarredListEntry.includes_record?( + last_name: search_params[:last_name], + ) + end end diff --git a/app/models/childrens_barred_list_entry.rb b/app/models/childrens_barred_list_entry.rb index fa435356..75e44759 100644 --- a/app/models/childrens_barred_list_entry.rb +++ b/app/models/childrens_barred_list_entry.rb @@ -2,4 +2,8 @@ class ChildrensBarredListEntry < ApplicationRecord validates :first_names, presence: true validates :last_name, presence: true validates :date_of_birth, presence: true + + def self.includes_record?(last_name:) + where(last_name: last_name).any? + end end diff --git a/app/views/searches/no_record.html.erb b/app/views/searches/no_record.html.erb new file mode 100644 index 00000000..c2597d39 --- /dev/null +++ b/app/views/searches/no_record.html.erb @@ -0,0 +1,15 @@ +
+
+

No record found

+ + <%= govuk_summary_list( + rows: [ + { key: { text: "Last name" }, value: { text: @search_form.last_name } } + ]) + %> + +

+ <%= govuk_link_to "Try another search", search_path %> +

+
+
diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index dbe6faec..7b61f668 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -1,11 +1,15 @@ -

Record found

+
+
+

Record found

-<%= govuk_summary_list( - rows: [ - { key: { text: "Last name" }, value: { text: @result.last_name } } - ]) -%> + <%= govuk_summary_list( + rows: [ + { key: { text: "Last name" }, value: { text: @search_form.last_name } } + ]) + %> -

- Contact DBS at <%= govuk_mail_to t('service.dbs_email'), t('service.dbs_email') %> for more details. -

+

+ Contact DBS at <%= govuk_mail_to t('service.dbs_email'), t('service.dbs_email') %> for more details. +

+
+
diff --git a/spec/factories/childrens_barred_list_entries.rb b/spec/factories/childrens_barred_list_entries.rb new file mode 100644 index 00000000..f2f489f8 --- /dev/null +++ b/spec/factories/childrens_barred_list_entries.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :childrens_barred_list_entry do + first_names { "John" } + last_name { "Doe" } + date_of_birth { 25.years.ago } + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 62c5f7f9..4b8cd8ac 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -21,19 +21,6 @@ Capybara.default_driver = :cuprite Capybara.javascript_driver = :cuprite -# Requires supporting ruby files with custom matchers and macros, etc, in -# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are -# run as spec files by default. This means that files in spec/support that end -# in _spec.rb will both be required and run as specs, causing the specs to be -# run twice. It is recommended that you do not name files matching this glob to -# end with _spec.rb. You can configure this pattern with the --pattern -# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -# -# The following line is provided for convenience purposes. It has the downside -# of increasing the boot-up time by auto-requiring all files in the support -# directory. Alternatively, in the individual `*_spec.rb` files, manually -# require only the support files necessary. -# Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } # Checks for pending migrations and applies them before tests are run. @@ -44,37 +31,12 @@ abort e.to_s.strip end RSpec.configure do |config| - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.include FactoryBot::Syntax::Methods config.fixture_path = Rails.root.join("spec/fixtures") - - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. config.use_transactional_fixtures = true - - # You can uncomment this line to turn off ActiveRecord support entirely. - # config.use_active_record = false - - # RSpec Rails can automatically mix in different behaviours to your tests - # based on their file location, for example enabling you to call `get` and - # `post` in specs under `spec/controllers`. - # - # You can disable this behaviour by removing the line below, and instead - # explicitly tag your specs with their type, e.g.: - # - # RSpec.describe UsersController, type: :controller do - # # ... - # end - # - # The different available types are documented in the features, such as in - # https://rspec.info/features/6-0/rspec-rails config.infer_spec_type_from_file_location! - - # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! config.before(:each, type: :system) { driven_by(:cuprite) } - # arbitrary gems may also be filtered via: - # config.filter_gems_from_backtrace("gem name") end Shoulda::Matchers.configure do |config| diff --git a/spec/system/user_searches_list_spec.rb b/spec/system/user_searches_with_matching_record_spec.rb similarity index 55% rename from spec/system/user_searches_list_spec.rb rename to spec/system/user_searches_with_matching_record_spec.rb index 48654fb4..1c4bcf37 100644 --- a/spec/system/user_searches_list_spec.rb +++ b/spec/system/user_searches_with_matching_record_spec.rb @@ -7,23 +7,29 @@ scenario "User searches with a last name" do given_the_service_is_open + and_there_is_a_record and_i_visit_the_search_page - and_i_search_with_a_last_name + and_i_search_for_their_last_name then_i_see_a_result end private + def and_there_is_a_record + @record = create(:childrens_barred_list_entry) + end + def and_i_visit_the_search_page visit search_path end - def and_i_search_with_a_last_name - fill_in "Last name", with: "Doe" + def and_i_search_for_their_last_name + fill_in "Last name", with: @record.last_name click_button "Search" end def then_i_see_a_result - expect(page).to have_content "Doe" + expect(page).to have_content "Record found" + expect(page).to have_content @record.last_name end end diff --git a/spec/system/user_searches_list_with_missing_params_spec.rb b/spec/system/user_searches_with_missing_params_spec.rb similarity index 100% rename from spec/system/user_searches_list_with_missing_params_spec.rb rename to spec/system/user_searches_with_missing_params_spec.rb diff --git a/spec/system/user_searches_with_no_matching_record_spec.rb b/spec/system/user_searches_with_no_matching_record_spec.rb new file mode 100644 index 00000000..c24d3bf2 --- /dev/null +++ b/spec/system/user_searches_with_no_matching_record_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "No matching record search", type: :system do + include ActivateFeaturesSteps + + scenario "User searches with no matching last name" do + given_the_service_is_open + and_there_is_a_record + and_i_visit_the_search_page + and_i_search_for_a_different_last_name + then_i_see_a_result + end + + private + + def and_there_is_a_record + @record = create(:childrens_barred_list_entry) + end + + def and_i_visit_the_search_page + visit search_path + end + + def and_i_search_for_a_different_last_name + fill_in "Last name", with: "Random name" + click_button "Search" + end + + def then_i_see_a_result + expect(page).to have_content "No record found" + expect(page).to have_content "Random name" + end +end From fed53b26fabab38aba6743c8aafe1c3fe994adf6 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 14:17:02 +0100 Subject: [PATCH 6/7] Use case-insensitive where clause for last_name --- app/models/childrens_barred_list_entry.rb | 2 +- .../childrens_barred_list_entry_spec.rb | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/models/childrens_barred_list_entry.rb b/app/models/childrens_barred_list_entry.rb index 75e44759..71620a93 100644 --- a/app/models/childrens_barred_list_entry.rb +++ b/app/models/childrens_barred_list_entry.rb @@ -4,6 +4,6 @@ class ChildrensBarredListEntry < ApplicationRecord validates :date_of_birth, presence: true def self.includes_record?(last_name:) - where(last_name: last_name).any? + where("lower(last_name) = ?", last_name.downcase).any? end end diff --git a/spec/models/childrens_barred_list_entry_spec.rb b/spec/models/childrens_barred_list_entry_spec.rb index cd1d343e..2aa6c492 100644 --- a/spec/models/childrens_barred_list_entry_spec.rb +++ b/spec/models/childrens_barred_list_entry_spec.rb @@ -4,4 +4,34 @@ it { is_expected.to validate_presence_of(:first_names) } it { is_expected.to validate_presence_of(:last_name) } it { is_expected.to validate_presence_of(:date_of_birth) } + + describe "#self.includes_record?" do + let(:record) { create(:childrens_barred_list_entry) } + + context "with an exact match" do + it "returns true" do + expect( + described_class.includes_record?(last_name: record.last_name), + ).to be_truthy + end + end + + context "with a case-insensitive match" do + it "returns true" do + expect( + described_class.includes_record?( + last_name: record.last_name.downcase, + ), + ).to be_truthy + end + end + + context "with no matching record" do + it "returns false" do + expect( + described_class.includes_record?(last_name: "Random name"), + ).to be_falsey + end + end + end end From 74f043cef5741070607269461e8677bceaa20231 Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Wed, 19 Jul 2023 14:27:51 +0100 Subject: [PATCH 7/7] Add page titles --- app/views/searches/new.html.erb | 2 ++ app/views/searches/no_record.html.erb | 2 ++ app/views/searches/show.html.erb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/app/views/searches/new.html.erb b/app/views/searches/new.html.erb index a61e8e5b..596469f1 100644 --- a/app/views/searches/new.html.erb +++ b/app/views/searches/new.html.erb @@ -1,3 +1,5 @@ +<% content_for :page_title, "#{'Error: ' if @search_form.errors.any?}Check the Children’s Barred List" %> +

Check the Children’s Barred List

diff --git a/app/views/searches/no_record.html.erb b/app/views/searches/no_record.html.erb index c2597d39..76183cd5 100644 --- a/app/views/searches/no_record.html.erb +++ b/app/views/searches/no_record.html.erb @@ -1,3 +1,5 @@ +<% content_for :page_title, "No record found" %> +

No record found

diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index 7b61f668..6bc5dbee 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -1,3 +1,5 @@ +<% content_for :page_title, "Record found" %> +

Record found