-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ErrorsController to support ContentBlockManager
This adds override templates to ContentBlockManager for the error pages, if the request path starts with the ContentBlockManager router prefix, we prepend the view path, so the overridden views are picked up. Additionally, we also need to do this for the `forbidden!` helper, as there isn’t a specific error we can raise that will result in a `forbidden` error
- Loading branch information
Showing
9 changed files
with
143 additions
and
18 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
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
10 changes: 10 additions & 0 deletions
10
lib/engines/content_block_manager/app/views/admin/errors/bad_request.html.erb
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,10 @@ | ||
<% content_for :product_name, ContentBlockManager.product_name %> | ||
<% content_for :page_title, "Something went wrong" %> | ||
<% content_for :title, "Something went wrong" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-body">Please try again by selecting the browser’s back button or <%= link_to "raise a support request", ContentBlockManager.support_url, class: "govuk-link govuk-link--no-visited-state" %></p> | ||
</div> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
lib/engines/content_block_manager/app/views/admin/errors/down_for_maintenance.html.erb
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,10 @@ | ||
<% content_for :product_name, ContentBlockManager.product_name %> | ||
<% content_for :page_title, "Down for maintenance" %> | ||
<% content_for :title, "Down for maintenance" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-body"><%= ContentBlockManager.product_name %> is currently down for maintenance. We'll be back soon.</p> | ||
</div> | ||
</div> |
19 changes: 19 additions & 0 deletions
19
lib/engines/content_block_manager/app/views/admin/errors/forbidden.html.erb
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,19 @@ | ||
<% content_for :product_name, ContentBlockManager.product_name %> | ||
<% content_for :page_title, "Permissions error" %> | ||
<% content_for :title, "Permissions error" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-body">You do not have permission to access this page.</p> | ||
<p class="govuk-body">If you need to:</p> | ||
|
||
<%= render "govuk_publishing_components/components/list", { | ||
visible_counters: true, | ||
items: [ | ||
"view the page, request the preview link", | ||
sanitize("edit the page, raise a #{link_to "support ticket", ContentBlockManager.support_url, class: "govuk-link govuk-link--no-visited-state"}"), | ||
], | ||
} %> | ||
</div> | ||
</div> |
19 changes: 19 additions & 0 deletions
19
lib/engines/content_block_manager/app/views/admin/errors/internal_server_error.html.erb
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,19 @@ | ||
<% content_for :product_name, ContentBlockManager.product_name %> | ||
<% content_for :page_title, "Server error" %> | ||
<% content_for :title, "Server error" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-body">The error has been logged in our system.</p> | ||
<p class="govuk-body">You can also raise a <a href="<%= ContentBlockManager.support_url %>" class="govuk-link">support ticket</a> with the following information:</p> | ||
|
||
<%= render "govuk_publishing_components/components/list", { | ||
visible_counters: true, | ||
items: [ | ||
"the url of this page", | ||
"the time of the error", | ||
], | ||
} %> | ||
</div> | ||
</div> |
11 changes: 11 additions & 0 deletions
11
lib/engines/content_block_manager/app/views/admin/errors/not_found.html.erb
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 @@ | ||
<% content_for :product_name, ContentBlockManager.product_name %> | ||
<% content_for :page_title, "There is a mistake in the URL" %> | ||
<% content_for :title, "There is a mistake in the URL" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-body">If you typed the URL, check it is correct.</p> | ||
<p class="govuk-body">If you pasted the URL, check you copied the entire address.</p> | ||
</div> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
lib/engines/content_block_manager/app/views/admin/errors/unprocessable_entity.html.erb
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,10 @@ | ||
<% content_for :product_name, ContentBlockManager.product_name %> | ||
<% content_for :page_title, "Something went wrong" %> | ||
<% content_for :title, "Something went wrong" %> | ||
<% content_for :title_margin_bottom, 6 %> | ||
|
||
<div class="govuk-grid-row govuk-!-margin-bottom-0"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-body">Please try again by selecting the browser’s back button or <%= link_to "raise a support request", ContentBlockManager.support_url, class: "govuk-link govuk-link--no-visited-state" %>.</p> | ||
</div> | ||
</div> |
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,32 +1,69 @@ | ||
require "test_helper" | ||
require "capybara/rails" | ||
|
||
class Admin::ErrorsControllerTest < ActionDispatch::IntegrationTest | ||
include Capybara::DSL | ||
extend Minitest::Spec::DSL | ||
|
||
setup do | ||
login_as_admin | ||
end | ||
|
||
test "should show the bad request page" do | ||
get "/400" | ||
assert_template :bad_request | ||
end | ||
ERROR_LOOKUPS = { | ||
"400": :bad_request, | ||
"403": :forbidden, | ||
"404": :not_found, | ||
"422": :unprocessable_entity, | ||
"500": :internal_server_error, | ||
}.freeze | ||
|
||
test "should show the forbidden page" do | ||
get "/403" | ||
assert_template :forbidden | ||
end | ||
ERROR_LOOKUPS.each do |error_code, error| | ||
it "should show the #{error} page" do | ||
get "/#{error_code}" | ||
|
||
test "should show the not found page" do | ||
get "/404" | ||
assert_template :not_found | ||
end | ||
assert_template error | ||
end | ||
|
||
it "should render the correct headers" do | ||
get "/#{error_code}" | ||
|
||
assert_select ".govuk-header__product-name", text: Whitehall.product_name | ||
refute_select ".govuk-phase-banner__content__tag" | ||
end | ||
|
||
it "should render the product name in the title" do | ||
get "/#{error_code}" | ||
|
||
test "should show the unprocessable entity page" do | ||
get "/422" | ||
assert_template :unprocessable_entity | ||
assert_select "title", text: /#{Whitehall.product_name}/ | ||
end | ||
end | ||
|
||
test "should show the internal server error page" do | ||
get "/500" | ||
assert_template :internal_server_error | ||
describe "when request comes from ContentBlockManager" do | ||
before do | ||
path = "some-path" | ||
ActionDispatch::Request.any_instance.stubs(:path).returns(path) | ||
path.stubs(:start_with?).with(ContentBlockManager.router_prefix).returns(true) | ||
end | ||
|
||
ERROR_LOOKUPS.each do |error_code, error| | ||
it "should show the #{error} page" do | ||
get "/#{error_code}" | ||
|
||
assert_template error | ||
end | ||
|
||
it "should render the correct headers" do | ||
get "/#{error_code}" | ||
|
||
assert_select ".govuk-header__product-name", text: ContentBlockManager.product_name | ||
assert_select ".govuk-phase-banner__content__tag", text: "Alpha" | ||
end | ||
|
||
it "should render the product name in the title" do | ||
get "/#{error_code}" | ||
|
||
assert_select "title", text: /#{ContentBlockManager.product_name}/ | ||
end | ||
end | ||
end | ||
end |