From 1f1f2c57269753a9ed0a78d0ac62f2148724b107 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 6 Nov 2020 16:39:26 +1100 Subject: [PATCH] Don't require fields on a step update --- controllers/custom_wizard/steps.rb | 12 ++++-------- spec/requests/custom_wizard/steps_controller_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/controllers/custom_wizard/steps.rb b/controllers/custom_wizard/steps.rb index 778707a6..c972c0c5 100644 --- a/controllers/custom_wizard/steps.rb +++ b/controllers/custom_wizard/steps.rb @@ -9,17 +9,13 @@ class CustomWizard::StepsController < ::ApplicationController wizard = @builder.build step = wizard.steps.select { |s| s.id == update_params[:step_id] }.first - if !step || step.fields.blank? - raise Discourse::InvalidParameters.new(:step_id) - end - - field_ids = step.fields.map(&:id) + raise Discourse::InvalidParameters.new(:step_id) if !step update = update_params.to_h - + + update[:fields] = {} if params[:fields] - update[:fields] = {} - + field_ids = step.fields.map(&:id) params[:fields].each do |k, v| update[:fields][k] = v if field_ids.include? k end diff --git a/spec/requests/custom_wizard/steps_controller_spec.rb b/spec/requests/custom_wizard/steps_controller_spec.rb index eeea6c17..4db3ff3a 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -31,4 +31,12 @@ describe CustomWizard::StepsController do expect(wizard.current_submission['step_1_field_1']).to eq("Text input") expect(wizard.start.id).to eq("step_2") end + + it "works if the step has no fields" do + put '/w/super-mega-fun-wizard/steps/step_1.json' + expect(response.status).to eq(200) + + wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build + expect(wizard.start.id).to eq("step_2") + end end \ No newline at end of file