From 712c15e84515194b499195bd7592b34d3a4eaa94 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 21 Jun 2023 09:53:42 +0100 Subject: [PATCH] FIX: upon revisit, start at step 1 if reset on revisit is set --- lib/custom_wizard/wizard.rb | 2 +- spec/components/custom_wizard/wizard_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 3d62cf25..bb22f873 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -145,7 +145,7 @@ class CustomWizard::Wizard step.last_step = true end - if step.previous && step.previous.id === last_completed_step_id + if !@restart_on_revisit && step.previous && step.previous.id === last_completed_step_id @start = step.id end end diff --git a/spec/components/custom_wizard/wizard_spec.rb b/spec/components/custom_wizard/wizard_spec.rb index 17151077..3483d211 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -226,6 +226,21 @@ describe CustomWizard::Wizard do end end + context "with subscription and restart upon revisit" do + before do + enable_subscription("standard") + @wizard.restart_on_revisit = true + CustomWizard::Template.save(@wizard.as_json) + end + + it "returns to step 1 if option to clear submissions on each visit is set" do + append_steps + expect(@wizard.unfinished?).to eq(true) + progress_step('step_1') + expect(@wizard.start).to eq('step_1') + end + end + context "with subscription and guest wizard" do before do enable_subscription("standard")