From 8d960333189d1a5f13b3601390d6a95c7cb12fec Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Fri, 5 Jul 2024 09:54:31 +0100 Subject: [PATCH] Require a note after further information requests If declining after a further information request, we want to require that the assessors write in a recommendation note as otherwise the applicant will see no reason for their decline. --- .../assessment_declaration_decline_form.rb | 9 ++++++--- app/models/assessment.rb | 4 ---- ...assessment_declaration_decline_form_spec.rb | 8 ++++++++ spec/models/assessment_spec.rb | 18 ------------------ 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/app/forms/assessor_interface/assessment_declaration_decline_form.rb b/app/forms/assessor_interface/assessment_declaration_decline_form.rb index 84d5803051..4bc902c7f3 100644 --- a/app/forms/assessor_interface/assessment_declaration_decline_form.rb +++ b/app/forms/assessor_interface/assessment_declaration_decline_form.rb @@ -11,9 +11,7 @@ class AssessorInterface::AssessmentDeclarationDeclineForm attribute :recommendation_assessor_note, :string validates :declaration, presence: true - validates :recommendation_assessor_note, - presence: true, - if: -> { assessment.selected_failure_reasons_empty? } + validates :recommendation_assessor_note, presence: true, if: :note_required? def save return false unless valid? @@ -24,4 +22,9 @@ def save true end + + def note_required? + assessment.sections.all? { _1.selected_failure_reasons.empty? } || + assessment.further_information_requests.exists?(review_passed: false) + end end diff --git a/app/models/assessment.rb b/app/models/assessment.rb index c812a1076a..9ea117424d 100644 --- a/app/models/assessment.rb +++ b/app/models/assessment.rb @@ -188,10 +188,6 @@ def available_recommendations end end - def selected_failure_reasons_empty? - sections.all? { |section| section.selected_failure_reasons.empty? } - end - def all_preliminary_sections_passed? sections.preliminary.all?(&:passed?) end diff --git a/spec/forms/assessor_interface/assessment_declaration_decline_form_spec.rb b/spec/forms/assessor_interface/assessment_declaration_decline_form_spec.rb index 4387af158d..0e452f2dec 100644 --- a/spec/forms/assessor_interface/assessment_declaration_decline_form_spec.rb +++ b/spec/forms/assessor_interface/assessment_declaration_decline_form_spec.rb @@ -35,6 +35,14 @@ ) end end + + context "when further information failed" do + before do + create(:further_information_request, :review_failed, assessment:) + end + + it { is_expected.to validate_presence_of(:recommendation_assessor_note) } + end end describe "#save" do diff --git a/spec/models/assessment_spec.rb b/spec/models/assessment_spec.rb index 3d3b56274d..30b2178480 100644 --- a/spec/models/assessment_spec.rb +++ b/spec/models/assessment_spec.rb @@ -489,22 +489,4 @@ it { is_expected.to include("request_further_information") } end end - - describe "#selected_failure_reasons_empty?" do - subject(:selected_failure_reasons_empty?) do - assessment.selected_failure_reasons_empty? - end - - context "with no failure reasons" do - it { is_expected.to be true } - end - - context "with failure reasons" do - before do - create(:assessment_section, :declines_with_already_qts, assessment:) - end - - it { is_expected.to be false } - end - end end