From 3db6b1fdaaef4977c9f34fdcbe93356a694388ed Mon Sep 17 00:00:00 2001 From: David Biddle Date: Wed, 27 Mar 2024 16:55:45 +0000 Subject: [PATCH] Allow archived forms to be made live Updates the state machine to allow archived and archived_with_draft forms to be made live. This will enable us to implement unarchiving a form in forms-admin. --- app/state_machines/form_state_machine.rb | 2 +- .../state_machines/form_state_machine_spec.rb | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/state_machines/form_state_machine.rb b/app/state_machines/form_state_machine.rb index cf0decc8..6c0ec02e 100644 --- a/app/state_machines/form_state_machine.rb +++ b/app/state_machines/form_state_machine.rb @@ -34,7 +34,7 @@ module FormStateMachine made_live_forms.create!(json_form_blob: form_blob.to_json, created_at: live_at) end - transitions from: %i[draft live_with_draft], to: :live, guard: proc { ready_for_live } + transitions from: %i[draft live_with_draft archived archived_with_draft], to: :live, guard: proc { ready_for_live } end event :create_draft_from_live_form do diff --git a/spec/state_machines/form_state_machine_spec.rb b/spec/state_machines/form_state_machine_spec.rb index f1dea80f..ba02fdfb 100644 --- a/spec/state_machines/form_state_machine_spec.rb +++ b/spec/state_machines/form_state_machine_spec.rb @@ -50,6 +50,30 @@ class FakeForm < Form it_behaves_like "transition to live state", FakeForm, :live_with_draft end end + + context "when form is archived" do + let(:form) { FakeForm.new(state: :archived) } + + it "does not transition to live state by default" do + expect(form).not_to transition_from(:archived).to(:live).on_event(:make_live) + end + + context "when all sections are completed" do + it_behaves_like "transition to live state", FakeForm, :archived + end + end + + context "when form is archived_with_draft" do + let(:form) { FakeForm.new(state: :archived_with_draft) } + + it "does not transition to live state by default" do + expect(form).not_to transition_from(:archived_with_draft).to(:live).on_event(:make_live) + end + + context "when all sections are completed" do + it_behaves_like "transition to live state", FakeForm, :archived_with_draft + end + end end describe ".create_draft_from_live_form" do