Skip to content

Commit

Permalink
Merge pull request #2289 from DFE-Digital/require-decline-note
Browse files Browse the repository at this point in the history
Require a note after further information requests
  • Loading branch information
thomasleese authored Jul 8, 2024
2 parents 8e7cb76 + 8d96033 commit c2b4093
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
4 changes: 0 additions & 4 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions spec/models/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c2b4093

Please sign in to comment.