Browse Source

Update clear all to ignore setup questions

pull/2483/head
Kat 2 years ago
parent
commit
b33c9b05af
  1. 8
      app/controllers/check_errors_controller.rb
  2. 5
      app/controllers/form_controller.rb
  3. 6
      spec/requests/check_errors_controller_spec.rb

8
app/controllers/check_errors_controller.rb

@ -11,7 +11,13 @@ class CheckErrorsController < ApplicationController
@page = @log.form.get_page(params[@log.model_name.param_key]["page_id"])
if params["clear_all"]
@questions_to_clear = @related_question_ids.map { |id| @log.form.get_question(id, @log).page.questions.map(&:id) }.flatten
@questions_to_clear = @related_question_ids.map { |id|
question = @log.form.get_question(id, @log)
next if question.subsection.id == "setup"
question.page.questions.map(&:id)
}.flatten.compact
render :confirm_clear_all_answers
else
question_id = @related_question_ids.find { |id| !params[id].nil? }

5
app/controllers/form_controller.rb

@ -405,7 +405,10 @@ private
if params[@log.model_name.param_key]["clear_question_ids"].present?
question_ids = params[@log.model_name.param_key]["clear_question_ids"].split(" ")
question_ids.each do |question_id|
@log.form.get_question(question_id, @log).page.questions.map(&:id).each { |id| @log[id] = nil }
question = @log.form.get_question(question_id, @log)
next if question.subsection.id == "setup"
question.page.questions.map(&:id).each { |id| @log[id] = nil }
end
@log.save!
@questions = params[@log.model_name.param_key].keys.reject { |id| %w[clear_question_ids page].include?(id) }.map { |id| @log.form.get_question(id, @log) }

6
spec/requests/check_errors_controller_spec.rb

@ -86,7 +86,7 @@ RSpec.describe CheckErrorsController, type: :request do
it "displays correct clear and change links" do
expect(page.all(:button, value: "Clear").count).to eq(2)
expect(page).to have_link("Change", count: 1)
expect(page).to have_link("Clear all", href: "/sales-logs/#{sales_log.id}/confirm-clear-all-answers")
expect(page).to have_button("Clear all")
end
end
end
@ -231,7 +231,7 @@ RSpec.describe CheckErrorsController, type: :request do
it "displays correct clear links" do
expect(page).to have_content("Are you sure you want to clear all")
expect(page).to have_content("You've selected 4 answers to clear")
expect(page).to have_content("You've selected 3 answers to clear")
expect(page).to have_content("You will not be able to undo this action")
expect(page).to have_link("Cancel")
expect(page).to have_button("Confirm and continue")
@ -447,7 +447,7 @@ RSpec.describe CheckErrorsController, type: :request do
expect(page.all(:button, value: "Clear").count).to eq(0)
expect(sales_log.reload.income1).to eq(nil)
expect(sales_log.reload.la).to eq(nil)
expect(sales_log.reload.ownershipsch).to eq(nil)
expect(sales_log.reload.ownershipsch).not_to eq(nil)
end
end
end

Loading…
Cancel
Save