Browse Source

Display all errors for the page

pull/2840/head
Kat 8 months ago
parent
commit
0b9b37574b
  1. 1
      app/controllers/form_controller.rb
  2. 28
      spec/requests/form_controller_spec.rb

1
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

28
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) }

Loading…
Cancel
Save