mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 07:48:50 +01:00
Vendoring Rails 2.3.5
This commit is contained in:
parent
3e83d19299
commit
f8779795ce
943 changed files with 56503 additions and 61351 deletions
|
|
@ -1,43 +1,29 @@
|
|||
require 'abstract_unit'
|
||||
|
||||
uses_mocha 'dispatcher tests' do
|
||||
|
||||
require 'action_controller/dispatcher'
|
||||
|
||||
class DispatcherTest < Test::Unit::TestCase
|
||||
Dispatcher = ActionController::Dispatcher
|
||||
Reloader = ActionController::Reloader
|
||||
|
||||
def setup
|
||||
@output = StringIO.new
|
||||
ENV['REQUEST_METHOD'] = 'GET'
|
||||
|
||||
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
|
||||
Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
||||
Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
||||
Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
||||
|
||||
reset_dispatcher
|
||||
Dispatcher.stubs(:require_dependency)
|
||||
|
||||
@dispatcher = Dispatcher.new(@output)
|
||||
end
|
||||
|
||||
def teardown
|
||||
ENV.delete 'REQUEST_METHOD'
|
||||
reset_dispatcher
|
||||
end
|
||||
|
||||
def test_clears_dependencies_after_dispatch_if_in_loading_mode
|
||||
ActiveSupport::Dependencies.expects(:clear).once
|
||||
dispatch(@output, false)
|
||||
# Close the response so dependencies kicks in
|
||||
dispatch(false).last.close
|
||||
end
|
||||
|
||||
def test_reloads_routes_before_dispatch_if_in_loading_mode
|
||||
ActionController::Routing::Routes.expects(:reload).once
|
||||
dispatch(@output, false)
|
||||
end
|
||||
|
||||
def test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode
|
||||
ActionView::Helpers::AssetTagHelper::AssetTag::Cache.expects(:clear).once
|
||||
dispatch(@output, false)
|
||||
dispatch(false)
|
||||
end
|
||||
|
||||
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
|
||||
|
|
@ -47,18 +33,51 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
dispatch
|
||||
end
|
||||
|
||||
def test_builds_middleware_stack_only_during_initialization_if_not_in_loading_mode
|
||||
dispatcher = create_dispatcher
|
||||
assert_not_nil dispatcher.instance_variable_get(:"@app")
|
||||
dispatcher.instance_variable_set(:"@app", lambda { |env| })
|
||||
dispatcher.expects(:build_middleware_stack).never
|
||||
dispatcher.call(nil)
|
||||
dispatcher.call(nil)
|
||||
end
|
||||
|
||||
def test_rebuilds_middleware_stack_on_every_request_if_in_loading_mode
|
||||
dispatcher = create_dispatcher(false)
|
||||
dispatcher.instance_variable_set(:"@app", lambda { |env| })
|
||||
dispatcher.expects(:build_middleware_stack).twice
|
||||
dispatcher.call(nil)
|
||||
Reloader.default_lock.unlock
|
||||
dispatcher.call(nil)
|
||||
end
|
||||
|
||||
def test_doesnt_wrap_call_in_reloader_if_not_in_loading_mode
|
||||
Reloader.expects(:run).never
|
||||
dispatch
|
||||
end
|
||||
|
||||
def test_wraps_call_in_reloader_if_in_loading_mode
|
||||
Reloader.expects(:run).once
|
||||
dispatch(false)
|
||||
end
|
||||
|
||||
# Stub out dispatch error logger
|
||||
class << Dispatcher
|
||||
def log_failsafe_exception(status, exception); end
|
||||
end
|
||||
|
||||
def test_failsafe_response
|
||||
CGI.expects(:new).raises('some multipart parsing failure')
|
||||
Dispatcher.expects(:log_failsafe_exception)
|
||||
Dispatcher.any_instance.expects(:dispatch).raises('b00m')
|
||||
ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
|
||||
|
||||
assert_nothing_raised { dispatch }
|
||||
|
||||
assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n<html><body><h1>400 Bad Request</h1></body></html>", @output.string
|
||||
response = nil
|
||||
assert_nothing_raised do
|
||||
response = dispatch
|
||||
end
|
||||
assert_equal 3, response.size
|
||||
assert_equal 500, response[0]
|
||||
assert_equal({"Content-Type" => "text/html"}, response[1])
|
||||
assert_match /500 Internal Server Error/, response[2].join
|
||||
end
|
||||
|
||||
def test_prepare_callbacks
|
||||
|
|
@ -71,7 +90,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
assert_nil a || b || c
|
||||
|
||||
# Run callbacks
|
||||
@dispatcher.send :run_callbacks, :prepare_dispatch
|
||||
Dispatcher.run_prepare_callbacks
|
||||
|
||||
assert_equal 1, a
|
||||
assert_equal 2, b
|
||||
|
|
@ -79,7 +98,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
|
||||
# Make sure they are only run once
|
||||
a = b = c = nil
|
||||
@dispatcher.send :dispatch
|
||||
dispatch
|
||||
assert_nil a || b || c
|
||||
end
|
||||
|
||||
|
|
@ -88,26 +107,38 @@ class DispatcherTest < Test::Unit::TestCase
|
|||
Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 }
|
||||
Dispatcher.to_prepare(:unique_id) { |*args| a = 2 }
|
||||
|
||||
@dispatcher.send :run_callbacks, :prepare_dispatch
|
||||
Dispatcher.run_prepare_callbacks
|
||||
assert_equal 2, a
|
||||
assert_equal nil, b
|
||||
end
|
||||
|
||||
private
|
||||
def dispatch(output = @output, cache_classes = true)
|
||||
controller = mock
|
||||
controller.stubs(:process).returns(controller)
|
||||
controller.stubs(:out).with(output).returns('response')
|
||||
|
||||
ActionController::Routing::Routes.stubs(:recognize).returns(controller)
|
||||
|
||||
def dispatch(cache_classes = true)
|
||||
ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response'])
|
||||
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
||||
Dispatcher.dispatch(nil, {}, output)
|
||||
Dispatcher.new.call({'rack.input' => StringIO.new('')})
|
||||
end
|
||||
|
||||
def create_dispatcher(cache_classes = true)
|
||||
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
||||
Dispatcher.new
|
||||
end
|
||||
|
||||
def reset_dispatcher
|
||||
Dispatcher.middleware = ActionController::MiddlewareStack.new do |middleware|
|
||||
middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/middlewares.rb"))
|
||||
middleware.instance_eval(File.read(middlewares))
|
||||
end
|
||||
|
||||
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
|
||||
Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
||||
Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
||||
Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
||||
|
||||
Dispatcher.define_dispatcher_callbacks(true)
|
||||
end
|
||||
|
||||
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
|
||||
assert_equal howmany, klass.subclasses.size, message
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue