From 03c894107aaafc127f60a62bd614635150a30eb0 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Mon, 14 Oct 2024 14:17:03 +0100 Subject: [PATCH] Fixes missing reference for claim If the form is invalid, say the journey session has already been submitted and the user double clicks the submit button, we need to return early from the child `save` method to avoid calling the mailer with a claim that hasn't been saved (which triggeres an error as the claim has no reference number). --- app/forms/claim_submission_base_form.rb | 2 ++ .../further_education_payments/claim_submission_form.rb | 2 +- .../further_education_payments/claim_submission_form_spec.rb | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/forms/claim_submission_base_form.rb b/app/forms/claim_submission_base_form.rb index f57862ccb9..87a76f58c0 100644 --- a/app/forms/claim_submission_base_form.rb +++ b/app/forms/claim_submission_base_form.rb @@ -27,6 +27,8 @@ def save ClaimMailer.submitted(claim).deliver_later ClaimVerifierJob.perform_later(claim) + + true end private diff --git a/app/forms/journeys/further_education_payments/claim_submission_form.rb b/app/forms/journeys/further_education_payments/claim_submission_form.rb index 8959ee87f8..da48296a04 100644 --- a/app/forms/journeys/further_education_payments/claim_submission_form.rb +++ b/app/forms/journeys/further_education_payments/claim_submission_form.rb @@ -2,7 +2,7 @@ module Journeys module FurtherEducationPayments class ClaimSubmissionForm < ::ClaimSubmissionBaseForm def save - super + return false unless super if Policies::FurtherEducationPayments.duplicate_claim?(claim) claim.eligibility.update!(flagged_as_duplicate: true) diff --git a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb index ab0e2a7c5f..c979deaf78 100644 --- a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb +++ b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb @@ -108,9 +108,12 @@ ).and_return(double(deliver_later: nil)) first_claim_form = described_class.new(journey_session: journey_session) - second_claim_form = described_class.new(journey_session: journey_session) first_claim_form.save + + journey_session.update! claim: nil + second_claim_form = described_class.new(journey_session: journey_session) + second_claim_form.save expect(ClaimMailer).to(