From 3bfe2751c6bf8133c4acb0291fb691adb478b0f0 Mon Sep 17 00:00:00 2001 From: Joel Sugarman Date: Mon, 20 Nov 2023 16:10:30 +0000 Subject: [PATCH] AP-4592: Only validate "one selected" when not a draft Allow save as draft button to function as expected. Namely to save the checked item if checked but not to enforce this as a requirement for returning to the "home" page. --- .../linked_children_form.rb | 2 +- .../linked_children_form_spec.rb | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/forms/providers/proceeding_merits_task/linked_children_form.rb b/app/forms/providers/proceeding_merits_task/linked_children_form.rb index d74e95ab28..b87471acd0 100644 --- a/app/forms/providers/proceeding_merits_task/linked_children_form.rb +++ b/app/forms/providers/proceeding_merits_task/linked_children_form.rb @@ -5,7 +5,7 @@ class LinkedChildrenForm < BaseForm attr_accessor :linked_children - validate :one_selected_child? + validate :one_selected_child?, unless: :draft? def value_list @value_list ||= legal_aid_application.involved_children.map do |child| diff --git a/spec/forms/providers/proceeding_merits_task/linked_children_form_spec.rb b/spec/forms/providers/proceeding_merits_task/linked_children_form_spec.rb index 4ac5e17d05..6a4bbba478 100644 --- a/spec/forms/providers/proceeding_merits_task/linked_children_form_spec.rb +++ b/spec/forms/providers/proceeding_merits_task/linked_children_form_spec.rb @@ -86,5 +86,39 @@ end end end + + context "when no linked_children selected" do + let(:linked_children_params) { ["", ""] } + + it "adds expected error messages" do + expect(form.errors).to be_empty + save_form + expect(form.errors.messages.values.flatten).to include("At least one child must be covered under this proceeding") + end + end + end + + describe ".save_as_draft" do + subject(:save_as_draft) { form.save_as_draft } + + context "when no linked_children selected" do + let(:linked_children_params) { [""] } + + it "does not validate the form, adding error messages" do + expect(form.errors.messages).to be_empty + save_as_draft + expect(form.errors.messages).to be_empty + end + end + + context "when linked_children selected" do + let(:linked_children_params) do + [legal_aid_application.involved_children.first.id, ""] + end + + it "saves the record" do + expect { save_as_draft }.to change(proceeding.proceeding_linked_children, :count).by(1) + end + end end end