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