diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-08-12 18:42:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-08-12 18:42:33 -0700 |
commit | 1ce64095e418f19f0792fa84156430921cb6c1f1 (patch) | |
tree | 31ce42a29f7a386345c533a9e86958596b29f4c8 | |
parent | bf646b364fd9b499214c9fcab852c2864331d7c9 (diff) | |
parent | 6fe36ba585d7d60d127b3ba75f923a48c132b3bb (diff) | |
download | rails-1ce64095e418f19f0792fa84156430921cb6c1f1.tar.gz rails-1ce64095e418f19f0792fa84156430921cb6c1f1.tar.bz2 rails-1ce64095e418f19f0792fa84156430921cb6c1f1.zip |
Merge pull request #7338 from sax/master
Evented notifications should take priority over Timed
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 6 | ||||
-rw-r--r-- | activesupport/test/notifications/evented_notification_test.rb | 20 |
2 files changed, 23 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 6ffc091233..2e5bcf4639 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -59,10 +59,10 @@ module ActiveSupport module Subscribers # :nodoc: def self.new(pattern, listener) - if listener.respond_to?(:call) - subscriber = Timed.new pattern, listener - else + if listener.respond_to?(:start) and listener.respond_to?(:finish) subscriber = Evented.new pattern, listener + else + subscriber = Timed.new pattern, listener end unless pattern diff --git a/activesupport/test/notifications/evented_notification_test.rb b/activesupport/test/notifications/evented_notification_test.rb index f77a0eb3fa..f690ad43fc 100644 --- a/activesupport/test/notifications/evented_notification_test.rb +++ b/activesupport/test/notifications/evented_notification_test.rb @@ -19,6 +19,12 @@ module ActiveSupport end end + class ListenerWithTimedSupport < Listener + def call(name, start, finish, id, payload) + @events << [:call, name, start, finish, id, payload] + end + end + def test_evented_listener notifier = Fanout.new listener = Listener.new @@ -62,6 +68,20 @@ module ActiveSupport [:finish, 'hello', 1, {}], ], listener.events end + + def test_evented_listener_priority + notifier = Fanout.new + listener = ListenerWithTimedSupport.new + notifier.subscribe 'hi', listener + + notifier.start 'hi', 1, {} + notifier.finish 'hi', 1, {} + + assert_equal [ + [:start, 'hi', 1, {}], + [:finish, 'hi', 1, {}] + ], listener.events + end end end end |