File tree 2 files changed +29
-6
lines changed
2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 1
1
class ErrorsController < ApplicationController
2
2
def not_found
3
- render ( status : 404 )
3
+ respond_to do |format |
4
+ format . json { render json : { message : 'Page not found' } , status : 404 }
5
+ format . html { render status : 404 }
6
+ format . any { render plain : 'Page not found' , status : 404 }
7
+ end
4
8
end
5
9
6
10
def internal_server_error
7
- render ( status : 500 )
11
+ respond_to do |format |
12
+ format . json { render json : { message : 'Internal Server Error' } , status : 500 }
13
+ format . html { render status : 500 }
14
+ format . any { render plain : 'Internal Server Error' , status : 500 }
15
+ end
8
16
end
9
17
end
Original file line number Diff line number Diff line change 1
1
require 'rails_helper'
2
2
3
3
RSpec . describe ErrorsController , type : :request do
4
- it '/404' do
5
- get '/dasdasdasd'
6
- expect ( response . status ) . to eq ( 404 )
7
- expect ( response . body ) . to include ( 'looking for doesn\'t exist.' )
4
+ context '/404' do
5
+ it 'html format' do
6
+ get '/dasdasdasd'
7
+ expect ( response . status ) . to eq ( 404 )
8
+ expect ( response . body ) . to include ( 'looking for doesn\'t exist.' )
9
+ end
10
+
11
+ it 'json format' do
12
+ get '/not_a_valid_url.json'
13
+ expect ( response . status ) . to eq ( 404 )
14
+ response_json = JSON . parse ( response . body )
15
+ expect ( response_json [ 'message' ] ) . to eq ( 'Page not found' )
16
+ end
17
+
18
+ it 'other format' do
19
+ get '/not_a_valid_url.test'
20
+ expect ( response . status ) . to eq ( 404 )
21
+ expect ( response . body ) . to include ( 'Page not found' )
22
+ end
8
23
end
9
24
end
You can’t perform that action at this time.
0 commit comments