From b33c9b05af3d426ea0b5d0a6a5ed016e5e8326c2 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 27 Jun 2024 10:42:06 +0100 Subject: [PATCH] Update clear all to ignore setup questions --- app/controllers/check_errors_controller.rb | 8 +++++++- app/controllers/form_controller.rb | 5 ++++- spec/requests/check_errors_controller_spec.rb | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/check_errors_controller.rb b/app/controllers/check_errors_controller.rb index 0cf30efea..f246e0b01 100644 --- a/app/controllers/check_errors_controller.rb +++ b/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? } diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 64c73e689..0bb4a2f81 100644 --- a/app/controllers/form_controller.rb +++ b/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) } diff --git a/spec/requests/check_errors_controller_spec.rb b/spec/requests/check_errors_controller_spec.rb index 6e78d7098..f0f1887aa 100644 --- a/spec/requests/check_errors_controller_spec.rb +++ b/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