aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/notifications_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/notifications_test.rb')
-rw-r--r--activesupport/test/notifications_test.rb47
1 files changed, 43 insertions, 4 deletions
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index 545811a376..67c3527e23 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -6,7 +6,7 @@ module Notifications
ActiveSupport::Notifications.notifier = nil
@notifier = ActiveSupport::Notifications.notifier
@events = []
- @notifier.subscribe { |*args| @events << event(*args) }
+ @subscription = @notifier.subscribe { |*args| @events << event(*args) }
end
private
@@ -19,6 +19,23 @@ module Notifications
end
end
+ class UnsubscribeTest < TestCase
+ def test_unsubscribing_removes_a_subscription
+ @notifier.publish :foo
+ @notifier.wait
+ assert_equal [[:foo]], @events
+ @notifier.unsubscribe(@subscription)
+ @notifier.publish :foo
+ @notifier.wait
+ assert_equal [[:foo]], @events
+ end
+
+ private
+ def event(*args)
+ args
+ end
+ end
+
class SyncPubSubTest < TestCase
def test_events_are_published_to_a_listener
@notifier.publish :foo
@@ -26,7 +43,29 @@ module Notifications
assert_equal [[:foo]], @events
end
- def test_subscriber_with_pattern
+ def test_publishing_multiple_times_works
+ @notifier.publish :foo
+ @notifier.publish :foo
+ @notifier.wait
+ assert_equal [[:foo], [:foo]], @events
+ end
+
+ def test_publishing_after_a_new_subscribe_works
+ @notifier.publish :foo
+ @notifier.publish :foo
+
+ @notifier.subscribe("not_existant") do |*args|
+ @events << ActiveSupport::Notifications::Event.new(*args)
+ end
+
+ @notifier.publish :foo
+ @notifier.publish :foo
+ @notifier.wait
+
+ assert_equal [[:foo]] * 4, @events
+ end
+
+ def test_log_subscriber_with_pattern
events = []
@notifier.subscribe('1') { |*args| events << args }
@@ -38,7 +77,7 @@ module Notifications
assert_equal [['1'], ['1.a']], events
end
- def test_subscriber_with_pattern_as_regexp
+ def test_log_subscriber_with_pattern_as_regexp
events = []
@notifier.subscribe(/\d/) { |*args| events << args }
@@ -50,7 +89,7 @@ module Notifications
assert_equal [['1'], ['a.1'], ['1.a']], events
end
- def test_multiple_subscribers
+ def test_multiple_log_subscribers
@another = []
@notifier.subscribe { |*args| @another << args }
@notifier.publish :foo