Skip to content

Commit

Permalink
Merge pull request #6019 from ministryofjustice/ap-4592/fix-involved-…
Browse files Browse the repository at this point in the history
…child-save-as-draft

AP-4592: Fix "involved child for proceeding" save as draft
  • Loading branch information
jsugarman authored Nov 21, 2023
2 parents 54347db + 3bfe275 commit 2cb1821
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2cb1821

Please sign in to comment.