Skip to content

Instantly share code, notes, and snippets.

@spastorino
Created January 4, 2011 12:27
Show Gist options
  • Save spastorino/764721 to your computer and use it in GitHub Desktop.
Save spastorino/764721 to your computer and use it in GitHub Desktop.
require 'test_helper'
class ExceptionController < ActionController::Base
respond_to :html, :xml, :json
include Exceptron::Helpers
def not_found
respond_with exception
end
def internal_server_error
respond_with exception
end
end
class ExceptronTest < ActionDispatch::IntegrationTest
Boomer = lambda do |env|
req = ActionDispatch::Request.new(env)
case req.path
when "/not_found"
raise ActionController::UnknownAction
when "/method_not_allowed"
raise ActionController::MethodNotAllowed
when "/not_implemented"
raise ActionController::NotImplemented
when "/unprocessable_entity"
raise ActionController::InvalidAuthenticityToken
when "/not_found_original_exception"
raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new)
else
raise "puke!"
end
end
ProductionApp = Exceptron::Middleware.new(Boomer, false)
DevelopmentApp = Exceptron::Middleware.new(Boomer, true)
test "rescue in public from a remote ip" do
@app = ProductionApp
self.remote_addr = '208.77.188.166'
get "/"
assert_response 500
assert_equal 'text/html', response.content_type.to_s
assert_equal FAILSAFE_RESPONSE, body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment