diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-17 11:17:42 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-17 11:29:51 +0100 |
commit | 0334f9f6cfa4c4c746de7e19250a13366b616c55 (patch) | |
tree | 9e2ff5d7efac90c26f3256d26d0789c14424ab7e /actionpack/test/dispatch | |
parent | afd0c06dfa8d3e04e85f9f0ea65c9beb376cb79f (diff) | |
download | rails-0334f9f6cfa4c4c746de7e19250a13366b616c55.tar.gz rails-0334f9f6cfa4c4c746de7e19250a13366b616c55.tar.bz2 rails-0334f9f6cfa4c4c746de7e19250a13366b616c55.zip |
Add ActionDispatch::Notifications middleware.
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r-- | actionpack/test/dispatch/callbacks_test.rb | 12 | ||||
-rw-r--r-- | actionpack/test/dispatch/notifications_test.rb | 69 | ||||
-rw-r--r-- | actionpack/test/dispatch/show_exceptions_test.rb | 23 |
3 files changed, 69 insertions, 35 deletions
diff --git a/actionpack/test/dispatch/callbacks_test.rb b/actionpack/test/dispatch/callbacks_test.rb index f3ea5209f4..9df882ce75 100644 --- a/actionpack/test/dispatch/callbacks_test.rb +++ b/actionpack/test/dispatch/callbacks_test.rb @@ -85,18 +85,6 @@ class DispatcherTest < Test::Unit::TestCase assert_equal 4, Foo.b end - def test_should_send_an_instrumentation_callback_for_async_processing - ActiveSupport::Notifications.expects(:instrument).with("action_dispatch.callback") - dispatch - end - - def test_should_send_an_instrumentation_callback_for_async_processing_even_on_failure - ActiveSupport::Notifications.notifier.expects(:publish) - assert_raise RuntimeError do - dispatch { |env| raise "OMG" } - end - end - private def dispatch(cache_classes = true, &block) diff --git a/actionpack/test/dispatch/notifications_test.rb b/actionpack/test/dispatch/notifications_test.rb new file mode 100644 index 0000000000..d834a734ef --- /dev/null +++ b/actionpack/test/dispatch/notifications_test.rb @@ -0,0 +1,69 @@ +require 'abstract_unit' + +class NotificationsMiddlewareTest < ActionController::IntegrationTest + Boomer = lambda do |env| + req = ActionDispatch::Request.new(env) + case req.path + when "/" + [200, {}, []] + else + raise "puke!" + end + end + + App = ActionDispatch::Notifications.new(Boomer) + + def setup + @queue = ActiveSupport::Notifications::Fanout.new + @notifier = ActiveSupport::Notifications::Notifier.new(@queue) + ActiveSupport::Notifications.notifier = @notifier + + @events = [] + ActiveSupport::Notifications.subscribe do |*args| + @events << args + end + + @app = App + end + + test "publishes notifications" do + get "/" + ActiveSupport::Notifications.notifier.wait + + assert_equal 2, @events.size + before, after = @events + + assert_equal 'action_dispatch.before_dispatch', before[0] + assert_kind_of Hash, before[4][:env] + assert_equal 'GET', before[4][:env]["REQUEST_METHOD"] + + assert_equal 'action_dispatch.after_dispatch', after[0] + assert_kind_of Hash, after[4][:env] + assert_equal 'GET', after[4][:env]["REQUEST_METHOD"] + end + + test "publishes notifications on failure" do + begin + get "/puke" + rescue + end + + ActiveSupport::Notifications.notifier.wait + + assert_equal 3, @events.size + before, after, exception = @events + + assert_equal 'action_dispatch.before_dispatch', before[0] + assert_kind_of Hash, before[4][:env] + assert_equal 'GET', before[4][:env]["REQUEST_METHOD"] + + assert_equal 'action_dispatch.after_dispatch', after[0] + assert_kind_of Hash, after[4][:env] + assert_equal 'GET', after[4][:env]["REQUEST_METHOD"] + + assert_equal 'action_dispatch.exception', exception[0] + assert_kind_of Hash, exception[4][:env] + assert_equal 'GET', exception[4][:env]["REQUEST_METHOD"] + assert_kind_of RuntimeError, exception[4][:exception] + end +end
\ No newline at end of file diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 951fb4a22e..9f6a93756c 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -104,27 +104,4 @@ class ShowExceptionsTest < ActionController::IntegrationTest assert_response 405 assert_match /ActionController::MethodNotAllowed/, body end - - test "publishes notifications" do - # Wait pending notifications to be published - ActiveSupport::Notifications.notifier.wait - - @app, event = ProductionApp, nil - self.remote_addr = '127.0.0.1' - - ActiveSupport::Notifications.subscribe('action_dispatch.show_exception') do |*args| - event = args - end - - get "/" - assert_response 500 - assert_match /puke/, body - - ActiveSupport::Notifications.notifier.wait - - assert_equal 'action_dispatch.show_exception', event.first - assert_kind_of Hash, event.last[:env] - assert_equal 'GET', event.last[:env]["REQUEST_METHOD"] - assert_kind_of RuntimeError, event.last[:exception] - end end |