Browse Source

Add question number to success message (#2344)

pull/2351/head
kosiakkatrina 9 months ago committed by GitHub
parent
commit
6ccb5854d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      app/controllers/form_controller.rb
  2. 10
      spec/requests/form_controller_spec.rb

6
app/controllers/form_controller.rb

@ -13,7 +13,11 @@ class FormController < ApplicationController
mandatory_questions_with_no_response = mandatory_questions_with_no_response(responses_for_page) mandatory_questions_with_no_response = mandatory_questions_with_no_response(responses_for_page)
if mandatory_questions_with_no_response.empty? && @log.update(responses_for_page.merge(updated_by: current_user)) if mandatory_questions_with_no_response.empty? && @log.update(responses_for_page.merge(updated_by: current_user))
flash[:notice] = "You have successfully updated #{@page.questions.map(&:check_answer_label).reject { |label| label.to_s.empty? }.first&.downcase}" if previous_interruption_screen_page_id.present? if previous_interruption_screen_page_id.present?
updated_question = @page.questions.reject { |question| question.check_answer_label.blank? }.first
updated_question_string = [updated_question&.question_number_string, updated_question&.check_answer_label.to_s.downcase].compact.join(": ")
flash[:notice] = "You have successfully updated #{updated_question_string}"
end
redirect_to(successful_redirect_path) redirect_to(successful_redirect_path)
else else
mandatory_questions_with_no_response.map do |question| mandatory_questions_with_no_response.map do |question|

10
spec/requests/form_controller_spec.rb

@ -760,25 +760,27 @@ RSpec.describe FormController, type: :request do
{ {
id: lettings_log.id, id: lettings_log.id,
lettings_log: { lettings_log: {
page: page_id, page: "lead_tenant_age",
age1: 20, age1: 20,
interruption_page_id: "retirement_value_check", interruption_page_id: "age_lead_tenant_over_retirement_value_check",
}, },
} }
end end
before do before do
lettings_log.update!(startdate: Time.zone.local(2023, 4, 1))
post "/lettings-logs/#{lettings_log.id}/lead-tenant-age?referrer=interruption_screen", params: post "/lettings-logs/#{lettings_log.id}/lead-tenant-age?referrer=interruption_screen", params:
end end
it "redirects back to the soft validation page" do it "redirects back to the soft validation page" do
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/retirement-value-check") expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/age-lead-tenant-over-retirement-value-check")
end end
it "displays a success banner" do it "displays a success banner" do
follow_redirect! follow_redirect!
follow_redirect! follow_redirect!
expect(response.body).to include("You have successfully updated lead tenant’s age")
expect(response.body).to include("You have successfully updated Q32: lead tenant’s age")
end end
end end

Loading…
Cancel
Save