-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from uclibs/217-make-error-pages-load-dynamic…
…ally 217 part 1: make error pages load dynamically
- Loading branch information
Showing
15 changed files
with
219 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# app/controllers/errors_controller.rb | ||
class ErrorsController < ApplicationController | ||
def not_found | ||
render template: 'errors/404', layout: 'application', status: :not_found | ||
end | ||
|
||
def unprocessable_entity | ||
render template: 'errors/422', layout: 'application', status: :unprocessable_entity | ||
end | ||
|
||
def internal_server_error | ||
render template: 'errors/500', layout: 'application', status: :internal_server_error | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.routes.draw do | ||
resources :colleges | ||
# Resource routes | ||
resources :artworks | ||
resources :books | ||
resources :book_chapters | ||
resources :books | ||
resources :colleges | ||
resources :digital_projects | ||
resources :editings | ||
resources :films | ||
resources :journal_articles | ||
resources :musical_scores | ||
resources :other_publications | ||
resources :photographies | ||
resources :physical_media | ||
resources :plays | ||
resources :public_performances | ||
resources :other_publications | ||
resources :submitters | ||
|
||
# Admin-related routes | ||
get 'citations', to: 'admin#citations' | ||
get 'toggle_links', to: 'admin#toggle_links' | ||
get 'publications', to: 'publications#index' | ||
get 'publications/:id', to: 'publications#index' | ||
get 'manage', to: 'admin#login' | ||
post 'manage/validate', to: 'admin#validate' | ||
get '/csv/:controller_name', to: 'admin#csv', as: 'controller_name' | ||
|
||
# Publications and submission routes | ||
get 'publications', to: 'publications#index' | ||
get 'publications/:id', to: 'publications#index' | ||
get 'finished', to: 'submitters#finished' | ||
|
||
# Dynamic pages | ||
get '/pages/:page' => 'pages#show' | ||
get '/csv/:controller_name', to: 'admin#csv', as: 'controller_name' | ||
|
||
# Root URL | ||
root 'submitters#new' | ||
|
||
# Custom Error Pages | ||
match '/404', to: 'errors#not_found', via: :all | ||
match '/500', to: 'errors#internal_server_error', via: :all | ||
match '/422', to: 'errors#unprocessable_entity', via: :all | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/controllers/errors_controller_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ErrorsController, type: :controller do | ||
describe 'GET #not_found' do | ||
before do | ||
get :not_found | ||
end | ||
it 'renders the not_found template' do | ||
expect(response).to render_template('errors/404') | ||
expect(response).to render_template('layouts/application') | ||
end | ||
|
||
it 'returns HTTP status 404' do | ||
expect(response).to have_http_status(404) | ||
end | ||
end | ||
|
||
describe 'GET #unprocessable_entity' do | ||
before do | ||
get :unprocessable_entity | ||
end | ||
|
||
it 'renders the unprocessable_entity template' do | ||
expect(response).to render_template('errors/422') | ||
expect(response).to render_template('layouts/application') | ||
end | ||
|
||
it 'returns HTTP status 422' do | ||
expect(response).to have_http_status(422) | ||
end | ||
end | ||
|
||
describe 'GET #internal_server_error' do | ||
before do | ||
get :internal_server_error | ||
end | ||
it 'renders the internal_server_error template' do | ||
expect(response).to render_template('errors/500') | ||
expect(response).to render_template('layouts/application') | ||
end | ||
|
||
it 'returns HTTP status 500' do | ||
expect(response).to have_http_status(500) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/routes/admin_routes_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Admin Routes', type: :routing do | ||
describe 'GET #citations' do | ||
it 'routes to admin#citations' do | ||
expect(get: '/citations').to route_to('admin#citations') | ||
end | ||
end | ||
|
||
describe 'GET #toggle_links' do | ||
it 'routes to admin#toggle_links' do | ||
expect(get: '/toggle_links').to route_to('admin#toggle_links') | ||
end | ||
end | ||
|
||
describe 'GET #manage' do | ||
it 'routes to admin#login' do | ||
expect(get: '/manage').to route_to('admin#login') | ||
end | ||
end | ||
|
||
describe 'POST #manage/validate' do | ||
it 'routes to admin#validate' do | ||
expect(post: '/manage/validate').to route_to('admin#validate') | ||
end | ||
end | ||
|
||
describe 'GET #csv/:controller_name' do | ||
it 'routes to admin#csv' do | ||
expect(get: '/csv/example_controller').to route_to('admin#csv', controller_name: 'example_controller') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe PagesController, type: :routing do | ||
describe 'routing' do | ||
it 'routes to #show with about as parameter' do | ||
expect(get: '/pages/about').to route_to('pages#show', page: 'about') | ||
end | ||
|
||
it 'routes to #show with contact as parameter' do | ||
expect(get: '/pages/contact').to route_to('pages#show', page: 'contact') | ||
end | ||
|
||
it 'routes to #show with faq as parameter' do | ||
expect(get: '/pages/faq').to route_to('pages#show', page: 'faq') | ||
end | ||
|
||
it 'does not route to #show without a page parameter' do | ||
expect(get: '/pages/').not_to be_routable | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/routing/error_pages_routing_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Error Pages', type: :routing do | ||
%w[get post put patch delete].each do |http_method| | ||
it "routes /404 to errors#not_found for #{http_method.upcase}" do | ||
expect({ http_method.to_s => '/404' }).to route_to(controller: 'errors', action: 'not_found') | ||
end | ||
|
||
it "routes /500 to errors#internal_server_error for #{http_method.upcase}" do | ||
expect({ http_method.to_s => '/500' }).to route_to(controller: 'errors', action: 'internal_server_error') | ||
end | ||
|
||
it "routes /422 to errors#unprocessable_entity for #{http_method.upcase}" do | ||
expect({ http_method.to_s => '/422' }).to route_to(controller: 'errors', action: 'unprocessable_entity') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/routes/publications_and_submitters_routes_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Publications and Submitters Routes', type: :routing do | ||
describe 'GET #publications' do | ||
it 'routes to publications#index' do | ||
expect(get: '/publications').to route_to('publications#index') | ||
end | ||
end | ||
|
||
describe 'GET #publications/:id' do | ||
it 'routes to publications#index with an ID' do | ||
expect(get: '/publications/1').to route_to('publications#index', id: '1') | ||
end | ||
end | ||
|
||
describe 'GET #finished' do | ||
it 'routes to submitters#finished' do | ||
expect(get: '/finished').to route_to('submitters#finished') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/routing/root_routing_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Root route', type: :routing do | ||
it 'routes the root URL to submitters#new' do | ||
expect(get: '/').to route_to(controller: 'submitters', action: 'new') | ||
end | ||
end |