diff options
author | Xavier Noria <fxn@hashref.com> | 2011-11-05 12:02:54 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-11-05 12:02:54 -0700 |
commit | d287e90870a9832c9d7e9d222881d3a6102bd04d (patch) | |
tree | 821bf391b755f8aaf624e72562674d4414350eb9 /activesupport/test/notifications_test.rb | |
parent | b33232f1b2c3f92c7116adc4b4879a8afc07e70c (diff) | |
download | rails-d287e90870a9832c9d7e9d222881d3a6102bd04d.tar.gz rails-d287e90870a9832c9d7e9d222881d3a6102bd04d.tar.bz2 rails-d287e90870a9832c9d7e9d222881d3a6102bd04d.zip |
implements AS::Notifications.subscribed, which provides subscriptions to events while a block runs
Diffstat (limited to 'activesupport/test/notifications_test.rb')
-rw-r--r-- | activesupport/test/notifications_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 884ee61547..fc9fa90d07 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -24,6 +24,26 @@ module Notifications end end + class SubscribedTest < TestCase + def test_subscribed + name = "foo" + name2 = name * 2 + expected = [name, name] + + events = [] + callback = lambda {|*_| events << _.first} + ActiveSupport::Notifications.subscribed(callback, name) do + ActiveSupport::Notifications.instrument(name) + ActiveSupport::Notifications.instrument(name2) + ActiveSupport::Notifications.instrument(name) + end + assert_equal expected, events + + ActiveSupport::Notifications.instrument(name) + assert_equal expected, events + end + end + class UnsubscribeTest < TestCase def test_unsubscribing_removes_a_subscription @notifier.publish :foo |