Browse Source

Ensure all checkbox selections are preserved not just the first that doesn't match the all

pull/823/head
baarkerlounger 3 years ago
parent
commit
635f6a88bf
  1. 3
      app/controllers/form_controller.rb
  2. 15
      spec/features/form/checkboxes_spec.rb

3
app/controllers/form_controller.rb

@ -161,10 +161,11 @@ private
def question_missing_response?(responses_for_page, question)
if %w[checkbox validation_override].include?(question.type)
question.answer_options.keys.reject { |x| x.match(/divider/) }.all? do |option|
answered = question.answer_options.keys.reject { |x| x.match(/divider/) }.map do |option|
session["fields"][option] = @case_log[option] = params["case_log"][question.id].include?(option) ? 1 : 0
params["case_log"][question.id].exclude?(option)
end
answered.all?
else
session["fields"][question.id] = @case_log[question.id] = responses_for_page[question.id]
responses_for_page[question.id].nil? || responses_for_page[question.id].blank?

15
spec/features/form/checkboxes_spec.rb

@ -45,12 +45,21 @@ RSpec.describe "Checkboxes" do
allow(case_log).to receive(:update).and_return(false)
end
it "shows an error summary", js:true do
it "shows an error summary" do
visit("/logs/#{id}/accessibility-requirements")
page.check("case-log-accessibility-requirements-housingneeds-a-field", allow_label_click: true)
page.check("case-log-accessibility-requirements-housingneeds-c-field", allow_label_click: true)
page.check("case-log-accessibility-requirements-housingneeds-a-field")
page.check("case-log-accessibility-requirements-housingneeds-c-field")
click_button("Save and continue")
expect(page).to have_title("Error")
end
it "persists the original selections" do
visit("/logs/#{id}/accessibility-requirements")
page.check("case-log-accessibility-requirements-housingneeds-a-field")
page.check("case-log-accessibility-requirements-housingneeds-c-field")
click_button("Save and continue")
expect(page).to have_checked_field("case-log-accessibility-requirements-housingneeds-a-field")
expect(page).to have_checked_field("case-log-accessibility-requirements-housingneeds-c-field")
end
end
end

Loading…
Cancel
Save