diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index f162f1f64..39a0dac55 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -29,11 +29,11 @@ class CaseLogsController < ApplicationController @case_log.update!(answers_for_page) next_page = form.next_page(previous_page) redirect_path = if next_page == :check_answers - subsection = form.subsection_for_page(previous_page) - "case_log_#{subsection}_check_answers_path" - else - "case_log_#{next_page}_path" - end + subsection = form.subsection_for_page(previous_page) + "case_log_#{subsection}_check_answers_path" + else + "case_log_#{next_page}_path" + end redirect_to(send(redirect_path, @case_log)) end @@ -41,8 +41,8 @@ class CaseLogsController < ApplicationController def check_answers @case_log = CaseLog.find(params[:case_log_id]) form = Form.new(2021, 2022) - current_url = request.env['PATH_INFO'] - subsection = current_url.split('/')[-2] + current_url = request.env["PATH_INFO"] + subsection = current_url.split("/")[-2] subsection_pages = form.pages_for_subsection(subsection) render "form/check_answers", locals: { case_log: @case_log, subsection_pages: subsection_pages } end diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 7bc4cca79..6aceadca2 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -1,14 +1,14 @@ module CheckAnswersHelper def get_answered_questions_total(subsection_pages, case_log) - questions = subsection_pages.values.flat_map do |page| - page["questions"].keys + questions = subsection_pages.values.flat_map do |page| + page["questions"].keys end questions.count { |question| case_log[question].present? } end def get_total_number_of_questions(subsection_pages) - questions = subsection_pages.values.flat_map do |page| - page["questions"].keys + questions = subsection_pages.values.flat_map do |page| + page["questions"].keys end questions.count end @@ -19,13 +19,13 @@ module CheckAnswersHelper end def create_next_missing_question_link(case_log_id, subsection_pages, case_log) - pages_to_fill_in = [] - subsection_pages.each do |page_title, page_info| - page_info["questions"].any? { |q| case_log["q"].blank?} - pages_to_fill_in << page_title - end - url = "/case_logs/#{case_log_id}/#{pages_to_fill_in.first}" - link_to('Answer the missing questions', url, class: "govuk-link").html_safe + pages_to_fill_in = [] + subsection_pages.each do |page_title, page_info| + page_info["questions"].any? { |_q| case_log["q"].blank? } + pages_to_fill_in << page_title + end + url = "/case_logs/#{case_log_id}/#{pages_to_fill_in.first}" + link_to("Answer the missing questions", url, class: "govuk-link").html_safe end def display_answered_questions_summary(subsection_pages, case_log) @@ -33,8 +33,8 @@ module CheckAnswersHelper "
You answered all the questions
".html_safe else "You answered #{get_answered_questions_total(subsection_pages, case_log)} of #{get_total_number_of_questions(subsection_pages)} questions
- #{create_next_missing_question_link(case_log["id"], subsection_pages, case_log)}".html_safe + #{create_next_missing_question_link(case_log['id'], subsection_pages, case_log)}".html_safe end - end + end end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 82d161ee8..fa3cfbbf1 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -104,13 +104,13 @@ RSpec.describe "Test Features" do context "when the user needs to check their answers for a subsection" do def fill_in_number_question(case_log_id, question, value) visit("/case_logs/#{case_log_id}/#{question}") - fill_in("#{question}", with: value) + fill_in(question.to_s, with: value) click_button("Save and continue") end def answer_all_questions_in_income_subsection visit("/case_logs/#{empty_case_log.id}/net_income") - fill_in("net_income", with: 18000) + fill_in("net_income", with: 18_000) choose("net-income-frequency-yearly-field") click_button("Save and continue") choose("net-income-uc-proportion-all-field") @@ -151,7 +151,7 @@ RSpec.describe "Test Features" do visit("case_logs/#{empty_case_log.id}/#{subsection}/check_answers") assert_selector "a", text: /Answer\z/, count: 7 assert_selector "a", text: "Change", count: 0 - expect(page).to have_link('Answer', href: "/case_logs/#{empty_case_log.id}/tenant_age") + expect(page).to have_link("Answer", href: "/case_logs/#{empty_case_log.id}/tenant_age") end it "should have a change link for answered questions" do @@ -159,28 +159,28 @@ RSpec.describe "Test Features" do visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers") assert_selector "a", text: /Answer\z/, count: 6 assert_selector "a", text: "Change", count: 1 - expect(page).to have_link('Change', href: "/case_logs/#{empty_case_log.id}/tenant_age") + expect(page).to have_link("Change", href: "/case_logs/#{empty_case_log.id}/tenant_age") end it "should have a link pointing to the first question if no questions are answered" do visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers") - expect(page).to have_content('You answered 0 of 7 questions') - expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/tenant_code") + expect(page).to have_content("You answered 0 of 7 questions") + expect(page).to have_link("Answer the missing questions", href: "/case_logs/#{empty_case_log.id}/tenant_code") end it "should have a link pointing to the next empty question if some questions are answered" do - fill_in_number_question(empty_case_log.id, "net_income", 18000) + fill_in_number_question(empty_case_log.id, "net_income", 18_000) visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers") - expect(page).to have_content('You answered 1 of 4 questions') - expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/net_income") + expect(page).to have_content("You answered 1 of 4 questions") + expect(page).to have_link("Answer the missing questions", href: "/case_logs/#{empty_case_log.id}/net_income") end it "should not display the missing answer questions link if all questions are answered" do answer_all_questions_in_income_subsection - expect(page).to have_content('You answered all the questions') + expect(page).to have_content("You answered all the questions") assert_selector "a", text: "Answer the missing questions", count: 0 - end + end end end end diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index b85640bad..348159566 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -22,7 +22,7 @@ RSpec.describe CheckAnswersHelper do subsection_pages = @form.pages_for_subsection("income_and_benefits") it "returns the total number of questions for a subsection" do - expect(get_total_number_of_questions(subsection_pages)).to eq(4) + expect(get_total_number_of_questions(subsection_pages)).to eq(4) end end end