From 1e515117f610162cf00e6c3b347be469fa7350d9 Mon Sep 17 00:00:00 2001 From: Stephen Daly Date: Thu, 28 Mar 2024 16:49:25 +0000 Subject: [PATCH] Update form state when page of an archived form is updated --- app/models/page.rb | 1 + spec/models/page_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/page.rb b/app/models/page.rb index 9f802724..1c44a781 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -33,6 +33,7 @@ def save_and_update_form # TODO: https://trello.com/c/dg9CFPgp/1503-user-triggers-state-change-from-live-to-livewithdraft # Will not be needed when users can trigger this event themselves through the UI form.create_draft_from_live_form! if form.live? + form.create_draft_from_archived_form! if form.archived? form.update!(question_section_completed: false) check_conditions.destroy_all if answer_type_changed_from_selection diff --git a/spec/models/page_spec.rb b/spec/models/page_spec.rb index b4fb09c3..365d6cb2 100644 --- a/spec/models/page_spec.rb +++ b/spec/models/page_spec.rb @@ -203,6 +203,26 @@ expect(form.question_section_completed).to be false end + context "when the form is live" do + let(:form) { create(:form, :live) } + + it "updates the form state to live_with_draft" do + page.question_text = "Edited question" + page.save_and_update_form + expect(form.state).to eq("live_with_draft") + end + end + + context "when the form is archived" do + let(:form) { create(:form, :archived) } + + it "updates the form state to archived_with_draft" do + page.question_text = "Edited question" + page.save_and_update_form + expect(form.state).to eq("archived_with_draft") + end + end + context "when page has routing conditions" do let(:routing_conditions) { [(create :condition)] } let(:check_conditions) { routing_conditions }