-
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.
Create custom error page for Pundit errors
- Loading branch information
Nat York
committed
Apr 4, 2017
1 parent
304a1ed
commit 4073dc8
Showing
7 changed files
with
57 additions
and
0 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,5 @@ | ||
class ErrorsController < ApplicationController | ||
def forbidden | ||
render status: 403 | ||
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,7 @@ | ||
<div class='main'> | ||
<h1>Woops!</h1> | ||
<p>You do not have access to this page.</p> | ||
<% if !current_person %> | ||
<p> This is most likely being caused because you are not <%= link_to 'signed in', '/auth/google_oauth2' %>.</p> | ||
<% end %> | ||
</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
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,10 @@ | ||
class CustomPublicExceptions < ActionDispatch::PublicExceptions | ||
def call(env) | ||
status = env["PATH_INFO"][1..-1] | ||
if status == '403' | ||
Rails.application.routes.call(env) | ||
else | ||
super | ||
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,9 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ErrorsController, type: :controller do | ||
describe 'GET #forbidden' do | ||
subject { get :forbidden } | ||
it { is_expected.to render_template :forbidden } | ||
it { is_expected.to have_http_status(403) } | ||
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,19 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CustomPublicExceptions do | ||
describe '#call' do | ||
subject { described_class.new(Rails.public_path).call(env) } | ||
|
||
context 'the status is 403' do | ||
let(:env) { Rack::MockRequest.env_for('/403') } | ||
it { is_expected.to be_instance_of(Array) } | ||
it { is_expected.to start_with 403 } | ||
end | ||
|
||
context 'the status is not 403' do | ||
let(:env) { Rack::MockRequest.env_for('/500') } | ||
it { is_expected.to be_instance_of(Array) } | ||
it { is_expected.to start_with 500 } | ||
end | ||
end | ||
end |