diff --git a/app/controllers/concerns/providers/application_dependable.rb b/app/controllers/concerns/providers/application_dependable.rb index 6291accf75..2461969205 100644 --- a/app/controllers/concerns/providers/application_dependable.rb +++ b/app/controllers/concerns/providers/application_dependable.rb @@ -16,8 +16,9 @@ def legal_aid_application_not_required? before_action :encode_upload_header before_action :set_legal_aid_application + # Let ActiveRecord::RecordNotFound bubble up for handling by exceptions_app as a 404 def legal_aid_application - @legal_aid_application ||= LegalAidApplication.find_by(id: params[:legal_aid_application_id]) + @legal_aid_application ||= LegalAidApplication.find(params[:legal_aid_application_id]) end delegate :applicant, to: :legal_aid_application @@ -25,15 +26,10 @@ def legal_aid_application def set_legal_aid_application return if self.class.legal_aid_application_not_required? - return process_invalid_application if legal_aid_application.blank? legal_aid_application.update!(provider_step:, provider_step_params:) unless provider_step == :delete end - def process_invalid_application - redirect_to error_path(:page_not_found) - end - def provider_step_params params.except(:action, :controller, :legal_aid_application_id) end diff --git a/spec/policies/provider_access_spec.rb b/spec/policies/provider_access_spec.rb index df86b2ca1a..5db85c9e4f 100644 --- a/spec/policies/provider_access_spec.rb +++ b/spec/policies/provider_access_spec.rb @@ -27,11 +27,12 @@ expect(response).to redirect_to(error_path(:access_denied)) end - it "allows missing application to be caught by not found" do + it "allows missing application to be caught by not found", :show_exceptions do login_as other_provider get providers_legal_aid_application_correspondence_address_lookup_path(SecureRandom.uuid) - expect(response).to redirect_to(error_path(:page_not_found)) + expect(response).to have_http_status(:not_found) + expect(response).to render_template("errors/show/_page_not_found") end end diff --git a/spec/requests/errors_controller_spec.rb b/spec/requests/errors_controller_spec.rb index 2426acb112..447c89f462 100644 --- a/spec/requests/errors_controller_spec.rb +++ b/spec/requests/errors_controller_spec.rb @@ -57,7 +57,7 @@ let(:get_invalid_id) { get feedback_path(SecureRandom.uuid) } context "with default locale" do - it "responds with http status" do + it "responds with expected http status" do get_invalid_id expect(response).to have_http_status(:not_found) end @@ -77,6 +77,23 @@ end end + context "when page not found due to legal_aid_application not found" do + let(:get_invalid_id) { get providers_legal_aid_application_previous_references_path(legal_aid_application_id: SecureRandom.uuid) } + let(:provider) { create(:provider) } + + before { sign_in provider } + + it "responds with expected http status" do + get_invalid_id + expect(response).to have_http_status(:not_found) + end + + it "renders page not found" do + get_invalid_id + expect(response).to render_template("errors/show/_page_not_found") + end + end + context "when internal server error/500 due to code fault" do let(:get_invalid_id) { get feedback_path(SecureRandom.uuid) } diff --git a/spec/requests/providers/about_the_financial_assessments_controller_spec.rb b/spec/requests/providers/about_the_financial_assessments_controller_spec.rb index fd8dbd71f1..0ed05781ec 100644 --- a/spec/requests/providers/about_the_financial_assessments_controller_spec.rb +++ b/spec/requests/providers/about_the_financial_assessments_controller_spec.rb @@ -33,11 +33,13 @@ expect(unescaped_response_body).to include(I18n.t("providers.about_the_financial_assessments.show.title")) end - context "when the application does not exist" do + context "when the application does not exist", :show_exceptions do let(:application_id) { SecureRandom.uuid } - it "redirects to an error" do - expect(response).to redirect_to(error_path(:page_not_found)) + it "renders page not found page" do + expect(response) + .to have_http_status(:not_found) + .and render_template("errors/show/_page_not_found") end end @@ -83,7 +85,7 @@ login_as application.provider end - context "when the application does not exist" do + context "when the application does not exist", :show_exceptions do let(:application_id) { SecureRandom.uuid } it "redirects to and error page without calling the email service" do @@ -91,7 +93,9 @@ submit_patch - expect(response).to redirect_to(error_path(:page_not_found)) + expect(response) + .to have_http_status(:not_found) + .and render_template("errors/show/_page_not_found") end end diff --git a/spec/requests/providers/check_merits_answers_spec.rb b/spec/requests/providers/check_merits_answers_spec.rb index ce1ceb13a4..ec4c3af82c 100644 --- a/spec/requests/providers/check_merits_answers_spec.rb +++ b/spec/requests/providers/check_merits_answers_spec.rb @@ -228,7 +228,7 @@ context "when there are required document categories" do before do allow(LegalFramework::MeritsTasksService).to receive(:call).with(application).and_return(smtl) - allow(LegalAidApplication).to receive(:find_by).and_return(application) + allow(LegalAidApplication).to receive(:find).and_return(application) allow(application).to receive(:evidence_is_required?).and_return(true) end