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