From ed9ce2e137e392edb4ca0647909600c4b24bc092 Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Tue, 28 Sep 2021 09:39:50 +0100 Subject: [PATCH] Get a second passing test in place Co-authored-by: Daniel Baark --- app/controllers/case_logs_controller.rb | 9 ++++++++- app/models/form.rb | 2 +- spec/factories/case_log.rb | 10 ---------- spec/features/case_log_spec.rb | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 6545b9a9c..e1e2d8890 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -28,7 +28,14 @@ class CaseLogsController < ApplicationController answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) } @case_log.update!(answers_for_page) next_page = form.next_page(previous_page) - redirect_to(send("case_log_#{next_page}_path", @case_log)) + 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 + + redirect_to(send(redirect_path, @case_log)) end def check_answers diff --git a/app/models/form.rb b/app/models/form.rb index 1be383ea0..00c3503af 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -50,7 +50,7 @@ class Form def next_page(previous_page) subsection = subsection_for_page(previous_page) previous_page_idx = pages_for_subsection(subsection).keys.index(previous_page) - pages_for_subsection(subsection).keys[previous_page_idx + 1] || previous_page # Placeholder until we have a check answers page + pages_for_subsection(subsection).keys[previous_page_idx + 1] || :check_answers end def previous_page(current_page) diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 48c6c33a5..e2f132c53 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -11,16 +11,6 @@ FactoryBot.define do tenant_code { "BZ737" } postcode { "NW1 7TY" } end - trait :near_check_answers_household_characteristics do - status { 0 } - tenant_code { "AB123" } - postcode { "LE11 2DW" } - tenant_age { 25 } - tenant_gender { "Male" } - tenant_ethnic_group { "White: English/Scottish/Welsh/Northern Irish/British" } - tenant_nationality { "UK national resident in UK" } - tenant_economic_status { "Part-time - Less than 30 hours" } - end created_at { Time.zone.now } updated_at { Time.zone.now } end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 3c7ccd498..bc76a9231 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -1,7 +1,6 @@ require "rails_helper" RSpec.describe "Test Features" do let!(:case_log) { FactoryBot.create(:case_log, :in_progress) } - let!(:check_answers_case_log) { FactoryBot.create(:case_log, :near_check_answers_household_characteristics) } let(:id) { case_log.id } let(:status) { case_log.status } @@ -101,18 +100,19 @@ RSpec.describe "Test Features" do describe "check answers page" do let(:subsection) { "household_characteristics" } - context "only one questions remains to be answered for the household characteristics section" do - # it "redirects to the check answers page when answering the last question and clicking save and continue" do - # visit("/case_logs/#{check_answers_case_log.id}/household_number_of_other_members") - # fill_in("household_number_of_other_members", with: 0) - # click_button("Save and continue") - # expect(page).to have_current_path("/case_logs/#{check_answers_case_log.id}/check-answers") - # end - + context "when the user needs to check their answers for a subsection" do it "can be visited by URL" do - visit("case_logs/#{case_log.id}/#{subsection}/check_answers") + visit("case_logs/#{id}/#{subsection}/check_answers") expect(page).to have_content("Check the answers you gave for #{subsection.tr('_', ' ')}") end + + let(:last_question_for_subsection) { "household_number_of_other_members" } + it "redirects to the check answers page when answering the last question and clicking save and continue" do + visit("/case_logs/#{id}/#{last_question_for_subsection}") + fill_in(last_question_for_subsection, with: 0) + click_button("Save and continue") + expect(page).to have_current_path("/case_logs/#{id}/#{subsection}/check_answers") + end end end end