aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/errors_controller.rb6
-rw-r--r--config/routes.rb10
-rw-r--r--spec/controllers/errors_controller_spec.rb41
3 files changed, 48 insertions, 9 deletions
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
index accf119a3..94e0d7b4c 100644
--- a/app/controllers/errors_controller.rb
+++ b/app/controllers/errors_controller.rb
@@ -1,14 +1,14 @@
class ErrorsController < ApplicationController
def not_found
- render template: 'errors/not_found', status: 404, formats: [:html]
+ render status: 404
end
def server_error
- render template: 'errors/server_error', status: 500, formats: [:html]
+ render status: 500
end
def not_allowed
- render template: 'errors/not_found', status: 403, formats: [:html]
+ render status: 403
end
end
diff --git a/config/routes.rb b/config/routes.rb
index 538c069ed..5b9cf0ea8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -213,11 +213,9 @@ ChouetteIhm::Application.routes.draw do
get '/help/(*slug)' => 'help#show'
- if Rails.env.production?
- get '404', to: 'errors#not_found'
- get '403', to: 'errors#not_allowed'
- get '422', to: 'errors#server_error'
- get '500', to: 'errors#server_error'
- end
+ match '/404', to: 'errors#not_found', via: :all
+ match '/403', to: 'errors#not_allowed', via: :all
+ match '/422', to: 'errors#server_error', via: :all
+ match '/500', to: 'errors#server_error', via: :all
end
diff --git a/spec/controllers/errors_controller_spec.rb b/spec/controllers/errors_controller_spec.rb
new file mode 100644
index 000000000..558fd0aa4
--- /dev/null
+++ b/spec/controllers/errors_controller_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+RSpec.describe ErrorsController, type: :controller do
+ login_user
+
+ describe 'GET not_found' do
+ before(:each) { get 'not_found' }
+
+ it 'renders the not_found template' do
+ expect(response).to render_template('not_found')
+ end
+
+ it 'returns 404 status code' do
+ expect(response).to have_http_status(404)
+ end
+ end
+
+ describe 'GET not_allowed' do
+ before(:each) { get 'not_allowed' }
+
+ it 'renders the not_allowed template' do
+ expect(response).to render_template('not_allowed')
+ end
+
+ it 'returns 403 status code' do
+ expect(response).to have_http_status(403)
+ end
+ end
+
+ describe 'GET server_error' do
+ before(:each) { get 'server_error' }
+
+ it 'renders the server_error template' do
+ expect(response).to render_template('server_error')
+ end
+
+ it 'returns 500 status code' do
+ expect(response).to have_http_status(500)
+ end
+ end
+end