Skip to content

Commit

Permalink
AuthorizationRequestFormsController not found redirect with an alert
Browse files Browse the repository at this point in the history
  • Loading branch information
skelz0r committed Dec 23, 2024
1 parent 4cb313a commit 8db23bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/authorization_request_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class AuthorizationRequestFormsController < AuthenticatedUserController
helper AuthorizationRequestsHelpers
include AuthorizationRequestsFlashes

rescue_from StaticApplicationRecord::EntryNotFound do
redirect_to root_path, alert: t('.form_not_found')
end

allow_unauthenticated_access only: [:new]

before_action :extract_authorization_request_form
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ fr:
cta: Débuter ma demande

authorization_request_forms:
form_not_found: Le formulaire demandé n'existe pas
new:
back_to_dashboard: Retour à l’accueil
title: *start_new_habilitation_title
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/authorization_request_forms_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
RSpec.describe AuthorizationRequestFormsController, type: :controller do
describe 'GET #new' do
subject(:new_authorization_request_form) { get :new, params: { form_uid: } }

context 'with invalid form uid' do
let(:form_uid) { 'invalid' }

it 'redirects to root path with an error message' do
new_authorization_request_form

expect(response).to redirect_to(root_path)
expect(flash[:alert]).to eq("Le formulaire demandé n'existe pas")
end
end
end
end

0 comments on commit 8db23bd

Please sign in to comment.