2011-11-22 03:24:05 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
module ShowExceptions
|
2011-11-22 05:34:13 -05:00
|
|
|
class ShowExceptionsController < ActionController::Base
|
2011-12-16 03:29:37 -05:00
|
|
|
use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
|
2011-12-01 14:46:18 -05:00
|
|
|
use ActionDispatch::DebugExceptions
|
2011-11-22 03:24:05 -05:00
|
|
|
|
2011-12-15 13:43:49 -05:00
|
|
|
before_filter :only => :another_boom do
|
|
|
|
request.env["action_dispatch.show_detailed_exceptions"] = true
|
|
|
|
end
|
|
|
|
|
2011-11-22 03:24:05 -05:00
|
|
|
def boom
|
|
|
|
raise 'boom!'
|
|
|
|
end
|
2011-12-15 13:43:49 -05:00
|
|
|
|
|
|
|
def another_boom
|
|
|
|
raise 'boom!'
|
|
|
|
end
|
2011-12-16 04:38:17 -05:00
|
|
|
|
|
|
|
def show_detailed_exceptions?
|
|
|
|
request.local?
|
|
|
|
end
|
2011-11-22 03:24:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class ShowExceptionsTest < ActionDispatch::IntegrationTest
|
|
|
|
test 'show error page from a remote ip' do
|
|
|
|
@app = ShowExceptionsController.action(:boom)
|
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
get '/'
|
|
|
|
assert_equal "500 error fixture\n", body
|
|
|
|
end
|
|
|
|
|
2011-12-16 04:38:17 -05:00
|
|
|
test 'show diagnostics from a local ip if show_detailed_exceptions? is set to request.local?' do
|
2011-11-22 03:24:05 -05:00
|
|
|
@app = ShowExceptionsController.action(:boom)
|
|
|
|
['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address|
|
|
|
|
self.remote_addr = ip_address
|
|
|
|
get '/'
|
2011-11-23 10:10:34 -05:00
|
|
|
assert_match(/boom/, body)
|
2011-11-22 03:24:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-15 13:43:49 -05:00
|
|
|
test 'show diagnostics from a remote ip when env is already set' do
|
|
|
|
@app = ShowExceptionsController.action(:another_boom)
|
2011-11-22 03:24:05 -05:00
|
|
|
self.remote_addr = '208.77.188.166'
|
|
|
|
get '/'
|
2011-11-23 10:10:34 -05:00
|
|
|
assert_match(/boom/, body)
|
2011-11-22 03:24:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ShowExceptionsOverridenController < ShowExceptionsController
|
|
|
|
private
|
|
|
|
|
|
|
|
def show_detailed_exceptions?
|
|
|
|
params['detailed'] == '1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ShowExceptionsOverridenTest < ActionDispatch::IntegrationTest
|
|
|
|
test 'show error page' do
|
|
|
|
@app = ShowExceptionsOverridenController.action(:boom)
|
|
|
|
get '/', {'detailed' => '0'}
|
|
|
|
assert_equal "500 error fixture\n", body
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'show diagnostics message' do
|
|
|
|
@app = ShowExceptionsOverridenController.action(:boom)
|
|
|
|
get '/', {'detailed' => '1'}
|
2011-11-23 10:10:34 -05:00
|
|
|
assert_match(/boom/, body)
|
2011-11-22 03:24:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|