Don't require fields on a step update
Dieser Commit ist enthalten in:
Ursprung
b201289358
Commit
1f1f2c5726
2 geänderte Dateien mit 12 neuen und 8 gelöschten Zeilen
|
@ -9,17 +9,13 @@ class CustomWizard::StepsController < ::ApplicationController
|
||||||
wizard = @builder.build
|
wizard = @builder.build
|
||||||
step = wizard.steps.select { |s| s.id == update_params[:step_id] }.first
|
step = wizard.steps.select { |s| s.id == update_params[:step_id] }.first
|
||||||
|
|
||||||
if !step || step.fields.blank?
|
raise Discourse::InvalidParameters.new(:step_id) if !step
|
||||||
raise Discourse::InvalidParameters.new(:step_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
field_ids = step.fields.map(&:id)
|
|
||||||
|
|
||||||
update = update_params.to_h
|
update = update_params.to_h
|
||||||
|
|
||||||
|
update[:fields] = {}
|
||||||
if params[:fields]
|
if params[:fields]
|
||||||
update[:fields] = {}
|
field_ids = step.fields.map(&:id)
|
||||||
|
|
||||||
params[:fields].each do |k, v|
|
params[:fields].each do |k, v|
|
||||||
update[:fields][k] = v if field_ids.include? k
|
update[:fields][k] = v if field_ids.include? k
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,4 +31,12 @@ describe CustomWizard::StepsController do
|
||||||
expect(wizard.current_submission['step_1_field_1']).to eq("Text input")
|
expect(wizard.current_submission['step_1_field_1']).to eq("Text input")
|
||||||
expect(wizard.start.id).to eq("step_2")
|
expect(wizard.start.id).to eq("step_2")
|
||||||
end
|
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
|
end
|
Laden …
In neuem Issue referenzieren