diff options
author | David Chelimsky <dchelimsky@gmail.com> | 2010-04-24 21:12:02 -0500 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-04-24 22:06:24 -0700 |
commit | 864bd9c21fdc8ce265c48fdfa2d4d7917032e717 (patch) | |
tree | aff882b58a30b4c7b02e521564dba3ce672fa8a8 /activesupport/test | |
parent | df886c4c89f3b8a95ef2456d6893393376b330a9 (diff) | |
download | rails-864bd9c21fdc8ce265c48fdfa2d4d7917032e717.tar.gz rails-864bd9c21fdc8ce265c48fdfa2d4d7917032e717.tar.bz2 rails-864bd9c21fdc8ce265c48fdfa2d4d7917032e717.zip |
allow unsubscribe by name or subscription [#4433 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/notifications_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 92fbe5b92f..c2e1c588f0 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -6,7 +6,9 @@ module Notifications ActiveSupport::Notifications.notifier = nil @notifier = ActiveSupport::Notifications.notifier @events = [] + @named_events = [] @subscription = @notifier.subscribe { |*args| @events << event(*args) } + @named_subscription = @notifier.subscribe("named.subscription") { |*args| @named_events << event(*args) } end private @@ -30,6 +32,26 @@ module Notifications assert_equal [[:foo]], @events end + def test_unsubscribing_by_name_removes_a_subscription + @notifier.publish "named.subscription", :foo + @notifier.wait + assert_equal [["named.subscription", :foo]], @named_events + @notifier.unsubscribe("named.subscription") + @notifier.publish "named.subscription", :foo + @notifier.wait + assert_equal [["named.subscription", :foo]], @named_events + end + + def test_unsubscribing_by_name_leaves_the_other_subscriptions + @notifier.publish "named.subscription", :foo + @notifier.wait + assert_equal [["named.subscription", :foo]], @events + @notifier.unsubscribe("named.subscription") + @notifier.publish "named.subscription", :foo + @notifier.wait + assert_equal [["named.subscription", :foo], ["named.subscription", :foo]], @events + end + private def event(*args) args |