From ea269efcaefc359d79fbe62f6fd436db00540e6c Mon Sep 17 00:00:00 2001 From: Felix Clack Date: Fri, 27 Sep 2024 15:26:00 +0100 Subject: [PATCH 1/2] Fix the count of records When counting the total number of searched records, we are incorrectly using the paged values. This change ensures we count the total records before applying pagination. --- app/controllers/check_records/bulk_searches_controller.rb | 2 ++ app/views/check_records/bulk_searches/show.html.erb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/check_records/bulk_searches_controller.rb b/app/controllers/check_records/bulk_searches_controller.rb index 0398352e..d839cebf 100644 --- a/app/controllers/check_records/bulk_searches_controller.rb +++ b/app/controllers/check_records/bulk_searches_controller.rb @@ -40,6 +40,8 @@ def show data = @bulk_search_response.body @total = @bulk_search_response.total + @total_not_found = data['not_found'].count + @total_results = data['results'].count @results ||= data.fetch("results", []).map do |teacher| QualificationsApi::Teacher.new(teacher['api_data']) end diff --git a/app/views/check_records/bulk_searches/show.html.erb b/app/views/check_records/bulk_searches/show.html.erb index 826102a2..5e8907d1 100644 --- a/app/views/check_records/bulk_searches/show.html.erb +++ b/app/views/check_records/bulk_searches/show.html.erb @@ -1,14 +1,14 @@ <% content_for :page_title, "Bulk Search Results" %> <% content_for :breadcrumbs do %> <%= govuk_breadcrumbs(breadcrumbs: { "Home" => check_records_search_path, "Find multiple records" => new_check_records_bulk_search_path, "Results" => nil }) %> + <%= render ActionAtComponent.new(action: "searched") %> <% end %>
- <%= render ActionAtComponent.new(action: "searched") %>

<%= pluralize(@total, 'teacher record') %> found

- We found <%= pluralize(@total, 'teacher record') %> out of the <%= pluralize(@results.count + @not_found.count, 'entry') %> you uploaded. + We found <%= pluralize(@total, 'teacher record') %> out of the <%= pluralize(@total_results + @total_not_found, 'entry') %> you uploaded.

<%= govuk_tabs do |tabs| if @results.any? From 7a2bde7818065b50036d69e1d55d49a728cc364f Mon Sep 17 00:00:00 2001 From: Felix Clack Date: Fri, 27 Sep 2024 15:26:41 +0100 Subject: [PATCH 2/2] Only highlight known restrictions There are cases where a record will have restrictions that we don't want to highlight. We only display the restrictons tag if the code is listed in the `Sanction::SANCTIONS` constant. --- app/lib/qualifications_api/teacher.rb | 4 ++- spec/lib/qualifications_api/teacher_spec.rb | 30 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/lib/qualifications_api/teacher.rb b/app/lib/qualifications_api/teacher.rb index 90b9f09f..32e3b439 100644 --- a/app/lib/qualifications_api/teacher.rb +++ b/app/lib/qualifications_api/teacher.rb @@ -46,7 +46,9 @@ def restriction_status end def no_restrictions? - return true if sanctions.blank? || sanctions.all?(&:guilty_but_not_prohibited?) + return true if sanctions.blank? || + sanctions.all?(&:guilty_but_not_prohibited?) || + sanctions.map(&:title).join.blank? false end diff --git a/spec/lib/qualifications_api/teacher_spec.rb b/spec/lib/qualifications_api/teacher_spec.rb index 623f8b9d..01f24b65 100644 --- a/spec/lib/qualifications_api/teacher_spec.rb +++ b/spec/lib/qualifications_api/teacher_spec.rb @@ -425,7 +425,7 @@ let(:api_data) do { "sanctions" => [ - { "guiltyButNotProhibited" => true }, + { "code" => "T6", "start_date" => "2024-01-01" }, { "possibleMatchOnChildrensBarredList" => true } ] } @@ -434,11 +434,35 @@ it { is_expected.to be_falsey } end - context "when there are sanctions" do + context "when there are sanctions that are not prohibited" do let(:api_data) do { "sanctions" => [ - { "guiltyButNotProhibited" => true }, + { "code" => "T6", "start_date" => "2024-01-01" }, + ] + } + end + + it { is_expected.to be_truthy } + end + + context "when there are sanctions not listed in the Sanction model" do + let(:api_data) do + { + "sanctions" => [ + { "code" => "T7", "start_date" => "2024-01-01" }, + ] + } + end + + it { is_expected.to be_truthy } + end + + context "when there are sanctions that are prohibited" do + let(:api_data) do + { + "sanctions" => [ + { "code" => "A13", "start_date" => "2024-01-01" }, ] } end