Skip to content

Instantly share code, notes, and snippets.

@tpendragon
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpendragon/ca2eab654e8c8e69c8f2 to your computer and use it in GitHub Desktop.
Save tpendragon/ca2eab654e8c8e69c8f2 to your computer and use it in GitHub Desktop.
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