From 9c41d0cca350daac356f5e98fdbf13ca45f702f6 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:01:57 +0000 Subject: [PATCH] CLDC-2041 Display all errors for the page (#2840) * Display all errors for the page * Fix world * Update the test --------- Co-authored-by: Rachael Booth --- app/controllers/form_controller.rb | 1 + spec/requests/form_controller_spec.rb | 29 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index f31662c4f..54988e71d 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -32,6 +32,7 @@ class FormController < ApplicationController pages_requiring_update = pages_requiring_update(shown_page_ids_with_unanswered_questions_before_update) redirect_to(successful_redirect_path(pages_requiring_update)) else + @log.valid? if mandatory_questions_with_no_response.any? mandatory_questions_with_no_response.map do |question| @log.errors.add question.id.to_sym, question.unanswered_error_message, category: :not_answered end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index f6ecfa2b5..2b7d4c65f 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -744,6 +744,35 @@ RSpec.describe FormController, type: :request do end end + context "with invalid multiple question answers" do + let(:page) { Capybara::Node::Simple.new(response.body) } + let(:page_id) { "rent" } + let(:params) do + { + id: lettings_log.id, + lettings_log: { + page: page_id, + "period" => 10, + "supcharg" => 1_000_000, + }, + } + end + + before do + allow(Rails.logger).to receive(:info) + end + + it "shows not answered and invalid answer errors at the same time" do + post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}", params: params + follow_redirect! + expect(page).to have_content("There is a problem") + expect(page).to have_content("Support Charge must be between 0 and 300.") + expect(page).to have_content("You must answer basic rent.") + expect(page).to have_content("You must answer personal service charge.") + expect(page).to have_content("You must answer service charge.") + end + end + context "with invalid organisation answers" do let(:page) { Capybara::Node::Simple.new(response.body) } let(:managing_organisation) { create(:organisation) }