Last active
August 29, 2015 14:12
-
-
Save tpendragon/ca2eab654e8c8e69c8f2 to your computer and use it in GitHub Desktop.
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
require 'rails_helper' | |
RSpec.describe "Error Handling" do | |
describe "Active Record Not Found" do | |
controller do | |
def index | |
raise ActiveRecord::RecordNotFound | |
end | |
end | |
describe 'handling ActiveRecord::RecordNotFound exceptions' do | |
it 'redirects to the root path' do | |
get :index | |
expect(response).to redirect_to('/') | |
expect(flash[:danger]).to eql 'We kunnen de pagina die je zoekt niet vinden' | |
end | |
it 'shows the appropriate flash message' do | |
get :index | |
expect(flash[:danger]).to eql 'We kunnen de pagina die je zoekt niet vinden' | |
end | |
end | |
end | |
describe "PunditNotAuthorizedError" do | |
controller do | |
def index | |
raise Pundit::NotAuthorizedError | |
end | |
end | |
describe 'handling Pundit::NotAuthorizedError exceptions' do | |
it 'redirects to the root path' do | |
get :index | |
expect(response).to redirect_to('/') | |
end | |
it 'shows the appropriate flash message' do | |
get :index | |
expect(flash[:danger]).to eql 'Je hebt geen toegang tot deze actie' | |
end | |
end | |
end | |
describe "ActionControllerUnknownFormat" do | |
controller(ActionControllerUnknownFormat) do | |
def index | |
raise ActionController::UnknownFormat | |
end | |
end | |
describe 'handling ActionController::UnknownFormat exceptions' do | |
it 'redirects to the root path' do | |
get :index | |
expect(response).to redirect_to('/') | |
end | |
it 'shows the appropriate flash message' do | |
get :index | |
expect(flash[:danger]).to eql 'We kunnen de pagina die je zoekt niet vinden' | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment