0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

confine exclusion to wizard fields

Dieser Commit ist enthalten in:
Faizaan Gagan 2021-05-07 03:28:16 +05:30
Ursprung 957a32cf5a
Commit 56268823c5
2 geänderte Dateien mit 49 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -250,7 +250,18 @@ class CustomWizard::Wizard
def filter_conditional_fields(submission) def filter_conditional_fields(submission)
included_fields = steps.map { |s| s.fields.map { |f| f.id } }.flatten included_fields = steps.map { |s| s.fields.map { |f| f.id } }.flatten
submission.select { |key, _| included_fields.include?(key) } submission.select do |key, _|
included_fields.include?(key) ||
required_fields.include?(key) ||
key.include?("action")
end
end
def required_fields
%w{
submitted_at
route_to
}
end end
def final_cleanup! def final_cleanup!

Datei anzeigen

@ -249,4 +249,41 @@ describe CustomWizard::StepsController do
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response.parsed_body['final']).to eq(true) expect(response.parsed_body['final']).to eq(true)
end end
it "excludes the non-included conditional fields from the submissions" do
new_template = wizard_template.dup
new_template['steps'][1]['fields'][0]['condition'] = wizard_field_condition_template['condition']
CustomWizard::Template.save(new_template, skip_jobs: true)
put '/w/super-mega-fun-wizard/steps/step_1.json', params: {
fields: {
step_1_field_1: "Condition will pass"
}
}
put '/w/super-mega-fun-wizard/steps/step_2.json', params: {
fields: {
step_2_field_1: "1995-04-23"
}
}
put '/w/super-mega-fun-wizard/steps/step_1.json', params: {
fields: {
step_1_field_1: "Condition will not pass"
}
}
wizard_id = response.parsed_body['wizard']['id']
wizard = CustomWizard::Wizard.create(wizard_id, user)
submission = wizard.submissions.last
expect(submission.keys).to include("step_2_field_1")
put '/w/super-mega-fun-wizard/steps/step_2.json', params: {
fields: {
step_2_field_1: "1995-04-23"
}
}
wizard = CustomWizard::Wizard.create(wizard_id, user)
submission = wizard.submissions.last
expect(submission.keys).not_to include("step_2_field_1")
end
end end