2008-01-05 13:32:06 +00:00
|
|
|
require 'abstract_unit'
|
2007-09-23 02:11:44 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
# Ensure deprecated dispatcher works
|
|
|
|
class DeprecatedDispatcherTest < ActiveSupport::TestCase
|
|
|
|
class DummyApp
|
|
|
|
def call(env)
|
|
|
|
[200, {}, 'response']
|
|
|
|
end
|
|
|
|
end
|
2009-09-20 13:09:08 +00:00
|
|
|
|
2005-06-24 11:57:40 +00:00
|
|
|
def setup
|
2009-09-20 13:09:08 +00:00
|
|
|
ActionDispatch::Callbacks.reset_callbacks(:prepare)
|
|
|
|
ActionDispatch::Callbacks.reset_callbacks(:call)
|
2005-06-24 11:57:40 +00:00
|
|
|
end
|
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
def test_assert_deprecated_to_prepare
|
|
|
|
a = nil
|
|
|
|
|
|
|
|
assert_deprecated do
|
|
|
|
ActionController::Dispatcher.to_prepare { a = 1 }
|
|
|
|
end
|
2005-06-24 11:57:40 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
assert_nil a
|
|
|
|
dispatch
|
|
|
|
assert_equal 1, a
|
2008-10-20 18:21:59 +00:00
|
|
|
end
|
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
def test_assert_deprecated_before_dispatch
|
|
|
|
a = nil
|
2007-09-26 01:24:07 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
assert_deprecated do
|
|
|
|
ActionController::Dispatcher.before_dispatch { a = 1 }
|
|
|
|
end
|
2007-09-26 01:24:07 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
assert_nil a
|
2009-05-17 18:39:44 +00:00
|
|
|
dispatch
|
2006-08-06 02:51:53 +00:00
|
|
|
assert_equal 1, a
|
|
|
|
end
|
2007-09-23 02:11:44 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
def test_assert_deprecated_after_dispatch
|
|
|
|
a = nil
|
|
|
|
|
|
|
|
assert_deprecated do
|
|
|
|
ActionController::Dispatcher.after_dispatch { a = 1 }
|
|
|
|
end
|
2007-09-26 01:24:07 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
assert_nil a
|
2009-05-17 18:39:44 +00:00
|
|
|
dispatch
|
2010-01-14 18:53:07 +00:00
|
|
|
assert_equal 1, a
|
2006-08-06 02:51:53 +00:00
|
|
|
end
|
2005-11-02 01:20:36 +00:00
|
|
|
|
2005-06-24 11:57:40 +00:00
|
|
|
private
|
2009-05-17 18:39:44 +00:00
|
|
|
|
2010-01-14 18:53:07 +00:00
|
|
|
def dispatch(cache_classes = true)
|
|
|
|
@dispatcher ||= ActionDispatch::Callbacks.new(DummyApp.new, !cache_classes)
|
|
|
|
@dispatcher.call({'rack.input' => StringIO.new('')})
|
2006-08-29 16:16:59 +00:00
|
|
|
end
|
|
|
|
|
2007-03-01 23:29:56 +00:00
|
|
|
end
|