1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/controller/show_exceptions_test.rb

60 lines
1.7 KiB
Ruby
Raw Normal View History

2011-11-22 03:24:05 -05:00
require 'abstract_unit'
module ShowExceptions
class ShowExceptionsController < ActionController::Base
2011-11-22 03:24:05 -05:00
use ActionDispatch::ShowExceptions
def boom
raise 'boom!'
end
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
test 'show diagnostics from a local ip' do
@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 '/'
assert_match(/boom/, body)
2011-11-22 03:24:05 -05:00
end
end
test 'show diagnostics from a remote ip when consider_all_requests_local is true' do
ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true)
2011-11-22 03:24:05 -05:00
@app = ShowExceptionsController.action(:boom)
self.remote_addr = '208.77.188.166'
get '/'
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'}
assert_match(/boom/, body)
2011-11-22 03:24:05 -05:00
end
end
end