Maintenance: Ensure Content-Type 'text/html' for error pages.
This commit is contained in:
parent
4f6aed1856
commit
c9774c8b45
2 changed files with 13 additions and 3 deletions
|
@ -73,7 +73,7 @@ module ApplicationController::HandlesErrors
|
||||||
@message = errors[:error_human] || errors[:error] || param[:message]
|
@message = errors[:error_human] || errors[:error] || param[:message]
|
||||||
@traceback = !Rails.env.production?
|
@traceback = !Rails.env.production?
|
||||||
file = File.open(Rails.root.join('public', "#{status_code}.html"), 'r')
|
file = File.open(Rails.root.join('public', "#{status_code}.html"), 'r')
|
||||||
render inline: file.read, status: status # rubocop:disable Rails/RenderInline
|
render inline: file.read, status: status, content_type: 'text/html' # rubocop:disable Rails/RenderInline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,7 @@ RSpec.describe 'Error handling', type: :request do
|
||||||
let(:as) { :html }
|
let(:as) { :html }
|
||||||
|
|
||||||
it { expect(response).to have_http_status(http_status) }
|
it { expect(response).to have_http_status(http_status) }
|
||||||
|
it { expect(response.content_type).to eq('text/html') }
|
||||||
it { expect(response.body).to include('<html') }
|
it { expect(response.body).to include('<html') }
|
||||||
it { expect(response.body).to include("<title>#{title}</title>") }
|
it { expect(response.body).to include("<title>#{title}</title>") }
|
||||||
it { expect(response.body).to include("<h1>#{headline}</h1>") }
|
it { expect(response.body).to include("<h1>#{headline}</h1>") }
|
||||||
|
@ -37,10 +38,11 @@ RSpec.describe 'Error handling', type: :request do
|
||||||
context 'URL route does not exist' do
|
context 'URL route does not exist' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
get '/not_existing_url', as: as
|
get url, as: as
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:message) { 'No route matches [GET] /not_existing_url' }
|
let(:url) { '/not_existing_url' }
|
||||||
|
let(:message) { "No route matches [GET] #{url}" }
|
||||||
let(:http_status) { :not_found }
|
let(:http_status) { :not_found }
|
||||||
|
|
||||||
context 'requesting JSON' do
|
context 'requesting JSON' do
|
||||||
|
@ -52,6 +54,14 @@ RSpec.describe 'Error handling', type: :request do
|
||||||
let(:headline) { '404: Requested resource was not found' }
|
let(:headline) { '404: Requested resource was not found' }
|
||||||
|
|
||||||
include_examples 'HTML response format'
|
include_examples 'HTML response format'
|
||||||
|
|
||||||
|
context 'when request ends with URL' do
|
||||||
|
|
||||||
|
let(:url) { "//////#{message}" }
|
||||||
|
let(:message) { 'this__website__is__closed__visit__our__new__site:_someother.com' }
|
||||||
|
|
||||||
|
include_examples 'HTML response format'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue