2009-05-03 00:02:22 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
class ShowExceptions
|
|
|
|
private
|
|
|
|
def public_path
|
|
|
|
"#{FIXTURE_LOAD_PATH}/public"
|
|
|
|
end
|
2009-05-17 13:24:42 -04:00
|
|
|
|
|
|
|
# Silence logger
|
|
|
|
def logger
|
|
|
|
nil
|
|
|
|
end
|
2009-05-03 00:02:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ShowExceptionsTest < ActionController::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
|
|
|
|
else
|
|
|
|
raise "puke!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ProductionApp = ActionDispatch::ShowExceptions.new(Boomer, false)
|
|
|
|
DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer, true)
|
|
|
|
|
|
|
|
test "rescue in public from a remote ip" do
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = ProductionApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_response 500
|
|
|
|
assert_equal "500 error fixture\n", body
|
|
|
|
|
|
|
|
get "/not_found"
|
|
|
|
assert_response 404
|
|
|
|
assert_equal "404 error fixture\n", body
|
|
|
|
|
|
|
|
get "/method_not_allowed"
|
|
|
|
assert_response 405
|
|
|
|
assert_equal "", body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "rescue locally from a local request" do
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = ProductionApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '127.0.0.1'
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_response 500
|
|
|
|
assert_match /puke/, body
|
|
|
|
|
|
|
|
get "/not_found"
|
|
|
|
assert_response 404
|
2009-05-26 18:03:09 -04:00
|
|
|
assert_match /#{ActionController::UnknownAction.name}/, body
|
2009-05-03 00:02:22 -04:00
|
|
|
|
|
|
|
get "/method_not_allowed"
|
|
|
|
assert_response 405
|
|
|
|
assert_match /ActionController::MethodNotAllowed/, body
|
|
|
|
end
|
|
|
|
|
|
|
|
test "localize public rescue message" do
|
|
|
|
# Change locale
|
2009-09-19 14:22:09 -04:00
|
|
|
old_locale, I18n.locale = I18n.locale, :da
|
2009-05-03 00:02:22 -04:00
|
|
|
|
|
|
|
begin
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = ProductionApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_response 500
|
|
|
|
assert_equal "500 localized error fixture\n", body
|
|
|
|
|
|
|
|
get "/not_found"
|
|
|
|
assert_response 404
|
|
|
|
assert_equal "404 error fixture\n", body
|
|
|
|
ensure
|
|
|
|
I18n.locale = old_locale
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "always rescue locally in development mode" do
|
2009-09-26 21:51:05 -04:00
|
|
|
@app = DevelopmentApp
|
2009-05-03 00:02:22 -04:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_response 500
|
|
|
|
assert_match /puke/, body
|
|
|
|
|
|
|
|
get "/not_found"
|
|
|
|
assert_response 404
|
2009-05-26 18:03:09 -04:00
|
|
|
assert_match /#{ActionController::UnknownAction.name}/, body
|
2009-05-03 00:02:22 -04:00
|
|
|
|
|
|
|
get "/method_not_allowed"
|
|
|
|
assert_response 405
|
|
|
|
assert_match /ActionController::MethodNotAllowed/, body
|
|
|
|
end
|
|
|
|
end
|