aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-14 19:53:07 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-15 12:24:30 +0100
commit8c8942ed4f2da52aa42ccd46560acb0b5fd37cb8 (patch)
tree976072122a45b4d050a0d6e798ae55ac3fea67a7 /actionpack/test/controller
parent5a8e7287c542cbe82d3127cae83dab8571ab9114 (diff)
downloadrails-8c8942ed4f2da52aa42ccd46560acb0b5fd37cb8.tar.gz
rails-8c8942ed4f2da52aa42ccd46560acb0b5fd37cb8.tar.bz2
rails-8c8942ed4f2da52aa42ccd46560acb0b5fd37cb8.zip
Move Dispatcher setup to Railties and add instrumentation hook.
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/dispatcher_test.rb80
1 files changed, 33 insertions, 47 deletions
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index 64f1ad7610..7e19bce3b7 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -1,73 +1,59 @@
require 'abstract_unit'
-class DispatcherTest < Test::Unit::TestCase
- Dispatcher = ActionController::Dispatcher
-
- class Foo
- cattr_accessor :a, :b
- end
+# Ensure deprecated dispatcher works
+class DeprecatedDispatcherTest < ActiveSupport::TestCase
+ class DummyApp
+ def call(env)
+ [200, {}, 'response']
+ end
+ end
def setup
- ENV['REQUEST_METHOD'] = 'GET'
-
- # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
ActionDispatch::Callbacks.reset_callbacks(:prepare)
ActionDispatch::Callbacks.reset_callbacks(:call)
-
- ActionController::Routing::Routes.stubs(:call).returns([200, {}, 'response'])
- Dispatcher.stubs(:require_dependency)
end
- def teardown
- ENV.delete 'REQUEST_METHOD'
- end
+ def test_assert_deprecated_to_prepare
+ a = nil
+
+ assert_deprecated do
+ ActionController::Dispatcher.to_prepare { a = 1 }
+ end
- def test_clears_dependencies_after_dispatch_if_in_loading_mode
- ActiveSupport::Dependencies.expects(:clear).once
- dispatch(false)
+ assert_nil a
+ dispatch
+ assert_equal 1, a
end
- def test_prepare_callbacks
- a = b = c = nil
- ActionDispatch::Callbacks.to_prepare { |*args| a = b = c = 1 }
- ActionDispatch::Callbacks.to_prepare { |*args| b = c = 2 }
- ActionDispatch::Callbacks.to_prepare { |*args| c = 3 }
+ def test_assert_deprecated_before_dispatch
+ a = nil
- # Ensure to_prepare callbacks are not run when defined
- assert_nil a || b || c
+ assert_deprecated do
+ ActionController::Dispatcher.before_dispatch { a = 1 }
+ end
- # Run callbacks
+ assert_nil a
dispatch
-
assert_equal 1, a
- assert_equal 2, b
- assert_equal 3, c
-
- # Make sure they are only run once
- a = b = c = nil
- dispatch
- assert_nil a || b || c
end
- def test_to_prepare_with_identifier_replaces
- ActionDispatch::Callbacks.to_prepare(:unique_id) { |*args| Foo.a, Foo.b = 1, 1 }
- ActionDispatch::Callbacks.to_prepare(:unique_id) { |*args| Foo.a = 2 }
+ def test_assert_deprecated_after_dispatch
+ a = nil
+
+ assert_deprecated do
+ ActionController::Dispatcher.after_dispatch { a = 1 }
+ end
+ assert_nil a
dispatch
- assert_equal 2, Foo.a
- assert_equal nil, Foo.b
+ assert_equal 1, a
end
private
- def dispatch(cache_classes = true)
- ActionController::Dispatcher.prepare_each_request = false
- Dispatcher.define_dispatcher_callbacks(cache_classes)
- @dispatcher ||= ActionDispatch::Callbacks.new(ActionController::Routing::Routes)
- @dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false})
+ def dispatch(cache_classes = true)
+ @dispatcher ||= ActionDispatch::Callbacks.new(DummyApp.new, !cache_classes)
+ @dispatcher.call({'rack.input' => StringIO.new('')})
end
- def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
- assert_equal howmany, klass.subclasses.size, message
- end
end