Skip to content

Commit

Permalink
Update form state when page of an archived form is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencdaly committed Mar 28, 2024
1 parent 7c1f2b0 commit 1e51511
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 1e51511

Please sign in to comment.