1
0
Fork 0

Don't require fields on a step update

Dieser Commit ist enthalten in:
Angus McLeod 2020-11-06 16:39:26 +11:00
Ursprung b201289358
Commit 1f1f2c5726
2 geänderte Dateien mit 12 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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
if params[:fields]
update[:fields] = {}
if params[:fields]
field_ids = step.fields.map(&:id)
params[:fields].each do |k, v|
update[:fields][k] = v if field_ids.include? k
end

Datei anzeigen

@ -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