Rails 2.3.3.1
Update to latest Rails. A little bit of jiggery-pokery is involved, since they neglected to re-include vendored Rack in this release.
This commit is contained in:
parent
329fafafce
commit
664552ac02
257 changed files with 4346 additions and 1682 deletions
60
vendor/rails/actionpack/test/controller/failsafe_test.rb
vendored
Normal file
60
vendor/rails/actionpack/test/controller/failsafe_test.rb
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
require 'abstract_unit'
|
||||
require 'stringio'
|
||||
require 'logger'
|
||||
|
||||
class FailsafeTest < ActionController::TestCase
|
||||
FIXTURE_PUBLIC = "#{File.dirname(__FILE__)}/../fixtures/failsafe".freeze
|
||||
|
||||
def setup
|
||||
@old_error_file_path = ActionController::Failsafe.error_file_path
|
||||
ActionController::Failsafe.error_file_path = FIXTURE_PUBLIC
|
||||
@app = mock
|
||||
@log_io = StringIO.new
|
||||
@logger = Logger.new(@log_io)
|
||||
@failsafe = ActionController::Failsafe.new(@app)
|
||||
@failsafe.stubs(:failsafe_logger).returns(@logger)
|
||||
end
|
||||
|
||||
def teardown
|
||||
ActionController::Failsafe.error_file_path = @old_error_file_path
|
||||
end
|
||||
|
||||
def app_will_raise_error!
|
||||
@app.expects(:call).then.raises(RuntimeError.new("Printer on fire"))
|
||||
end
|
||||
|
||||
def test_calls_app_and_returns_its_return_value
|
||||
@app.expects(:call).returns([200, { "Content-Type" => "text/html" }, "ok"])
|
||||
assert_equal [200, { "Content-Type" => "text/html" }, "ok"], @failsafe.call({})
|
||||
end
|
||||
|
||||
def test_writes_to_log_file_on_exception
|
||||
app_will_raise_error!
|
||||
@failsafe.call({})
|
||||
assert_match /Printer on fire/, @log_io.string # Logs exception message.
|
||||
assert_match /failsafe_test\.rb/, @log_io.string # Logs backtrace.
|
||||
end
|
||||
|
||||
def test_returns_500_internal_server_error_on_exception
|
||||
app_will_raise_error!
|
||||
response = @failsafe.call({})
|
||||
assert_equal 3, response.size # It is a valid Rack response.
|
||||
assert_equal 500, response[0] # Status is 500.
|
||||
end
|
||||
|
||||
def test_renders_error_page_file_with_erb
|
||||
app_will_raise_error!
|
||||
response = @failsafe.call({})
|
||||
assert_equal 500, response[0]
|
||||
assert_equal "hello my world", response[2].join
|
||||
end
|
||||
|
||||
def test_returns_a_default_message_if_erb_rendering_failed
|
||||
app_will_raise_error!
|
||||
@failsafe.expects(:render_template).raises(RuntimeError.new("Harddisk is crashing"))
|
||||
response = @failsafe.call({})
|
||||
assert_equal 500, response[0]
|
||||
assert_match /500 Internal Server Error/, response[2].join
|
||||
assert_match %r(please read this web application's log file), response[2].join
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue