From 75fb228bbbcca600860212bcefcc08796571d00b Mon Sep 17 00:00:00 2001 From: Katherine Martin <78093815+martikat@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:49:48 +0100 Subject: [PATCH] Update route to handle unmatched routes (#844) --- config/routes.rb | 11 ++++++++--- spec/system/page_tier_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 8723cfd6..c3ab9f98 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,9 +15,14 @@ resources :settings, only: %i[create] - get ':section', to: 'pages#index' - get ':section/:slug', to: 'pages#show' - get ':section/:overview/:slug', to: 'pages#show' + get ':section', to: 'pages#index', format: 'html' + get ':section/:slug', to: 'pages#show', format: 'html' + get ':section/:overview/:slug', to: 'pages#show', format: 'html' + + # Handle unmatched route + get '/*unmatched_route', to: 'errors#not_found', via: :get, format: 'html' + get '/*unmatched_route/*unmatched_route', to: 'errors#not_found', via: :get, format: 'html' + get '/*unmatched_route/*unmatched_route/*unmatched_route', to: 'errors#not_found', via: :get, format: 'html' post 'change', to: 'hook#change' post 'release', to: 'hook#release' diff --git a/spec/system/page_tier_spec.rb b/spec/system/page_tier_spec.rb index fec4be0e..602c06ad 100644 --- a/spec/system/page_tier_spec.rb +++ b/spec/system/page_tier_spec.rb @@ -109,4 +109,34 @@ end end end + + describe 'First tier when route is in incorrect format' do + before do + visit '/randompage.yml' + end + + it 'has a heading' do + expect(page).to have_text('Page not found') + end + end + + describe 'Second tier when route is in incorrect format' do + before do + visit '/route/randompage.yml' + end + + it 'has a heading' do + expect(page).to have_text('Page not found') + end + end + + describe 'Third tier when route is in incorrect format' do + before do + visit '/route/route/randompage.yml' + end + + it 'has a heading' do + expect(page).to have_text('Page not found') + end + end end