Skip to content

Commit

Permalink
Merge pull request #7470 from ministryofjustice/ap-5524/let-rails-han…
Browse files Browse the repository at this point in the history
…dle-application-not-found

AP-5524: Let rails handle application not found
jsugarman authored Dec 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 268f0ae + a8bce97 commit ff23422
Showing 5 changed files with 33 additions and 15 deletions.
8 changes: 2 additions & 6 deletions app/controllers/concerns/providers/application_dependable.rb
Original file line number Diff line number Diff line change
@@ -16,24 +16,20 @@ 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

private

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
5 changes: 3 additions & 2 deletions spec/policies/provider_access_spec.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 18 additions & 1 deletion spec/requests/errors_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }

Original file line number Diff line number Diff line change
@@ -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,15 +85,17 @@
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
expect(CitizenEmailService).not_to receive(:new)

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

2 changes: 1 addition & 1 deletion spec/requests/providers/check_merits_answers_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ff23422

Please sign in to comment.