diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 70b6f892b..d376adf48 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -31,6 +31,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 13d711c20..4f6ac9b91 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -719,6 +719,34 @@ 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 + 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) }