1
0
Fork 0

Fix start step when step is added to previously used wizard

Dieser Commit ist enthalten in:
Angus McLeod 2023-03-22 11:20:30 +01:00
Ursprung e2797ced64
Commit 8734cda00b
3 geänderte Dateien mit 33 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -84,6 +84,10 @@ class CustomWizard::Submission
data
end
def submitted?
!!submitted_at
end
def self.get(wizard)
data = PluginStore.get("#{wizard.id}_#{KEY}", wizard.actor_id).last
new(wizard, data)

Datei anzeigen

@ -176,6 +176,7 @@ class CustomWizard::Wizard
def unfinished?
return nil unless actor_id
return false if last_submission&.submitted?
most_recent = CustomWizard::UserHistory.where(
actor_id: actor_id,
@ -194,6 +195,7 @@ class CustomWizard::Wizard
def completed?
return nil unless actor_id
return true if last_submission&.submitted?
history = CustomWizard::UserHistory.where(
actor_id: actor_id,
@ -282,6 +284,10 @@ class CustomWizard::Wizard
@submissions ||= CustomWizard::Submission.list(self).submissions
end
def last_submission
@last_submission ||= submissions&.last
end
def current_submission
@current_submission ||= begin
if submissions.present?

Datei anzeigen

@ -7,6 +7,7 @@ describe CustomWizard::Wizard do
let(:template_json) { get_wizard_fixture("wizard") }
let(:permitted_json) { get_wizard_fixture("wizard/permitted") }
let(:guests_permitted_json) { get_wizard_fixture("wizard/guests_permitted") }
let(:step_json) { get_wizard_fixture("step/step") }
before do
Group.refresh_automatic_group!(:trust_level_3)
@ -75,6 +76,28 @@ describe CustomWizard::Wizard do
expect(@wizard.start).to eq('step_2')
end
it "determines the user's current step if steps are added" do
append_steps
progress_step('step_1')
progress_step('step_2')
progress_step("step_3")
fourth_step = step_json.dup
fourth_step['id'] = "step_4"
template = template_json.dup
template['steps'] << fourth_step
CustomWizard::Template.save(template, skip_jobs: true)
wizard = CustomWizard::Wizard.new(template, user)
template['steps'].each do |step_template|
wizard.append_step(step_template['id'])
end
expect(wizard.steps.size).to eq(4)
expect(wizard.start).to eq(nil)
end
it "creates a step updater" do
expect(
@wizard.create_updater('step_1', step_1_field_1: "Text input")