diff options
author | Aaron Patterson <tenderlove@github.com> | 2019-02-11 17:42:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-11 17:42:17 -0800 |
commit | 87a5b5d023cf785d89cf0abd3e78e3084b6af02d (patch) | |
tree | 2e01b11de9ba371280d370e0eca6436bde74982f /activesupport/test | |
parent | 819b06f494d2b934b3124808526debe0aa81b57a (diff) | |
parent | 94f8e8c8f73b7034a9cc3e7f6bf040350aa9701f (diff) | |
download | rails-87a5b5d023cf785d89cf0abd3e78e3084b6af02d.tar.gz rails-87a5b5d023cf785d89cf0abd3e78e3084b6af02d.tar.bz2 rails-87a5b5d023cf785d89cf0abd3e78e3084b6af02d.zip |
Merge pull request #32861 from zvkemp/asn-unsubscribe-proxy
use ProxyPattern to match for ActiveSupport::Notifications fanout/unsubscribe
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/notifications/evented_notification_test.rb | 33 | ||||
-rw-r--r-- | activesupport/test/notifications_test.rb | 19 |
2 files changed, 52 insertions, 0 deletions
diff --git a/activesupport/test/notifications/evented_notification_test.rb b/activesupport/test/notifications/evented_notification_test.rb index 4beb8194b9..ab2a9b8659 100644 --- a/activesupport/test/notifications/evented_notification_test.rb +++ b/activesupport/test/notifications/evented_notification_test.rb @@ -84,6 +84,39 @@ module ActiveSupport [:finish, "hi", 1, {}] ], listener.events end + + def test_listen_to_regexp + notifier = Fanout.new + listener = Listener.new + notifier.subscribe(/[a-z]*.world/, listener) + notifier.start("hi.world", 1, {}) + notifier.finish("hi.world", 2, {}) + notifier.start("hello.world", 1, {}) + notifier.finish("hello.world", 2, {}) + + assert_equal [ + [:start, "hi.world", 1, {}], + [:finish, "hi.world", 2, {}], + [:start, "hello.world", 1, {}], + [:finish, "hello.world", 2, {}] + ], listener.events + end + + def test_listen_to_regexp_with_exclusions + notifier = Fanout.new + listener = Listener.new + notifier.subscribe(/[a-z]*.world/, listener) + notifier.unsubscribe("hi.world") + notifier.start("hi.world", 1, {}) + notifier.finish("hi.world", 2, {}) + notifier.start("hello.world", 1, {}) + notifier.finish("hello.world", 2, {}) + + assert_equal [ + [:start, "hello.world", 1, {}], + [:finish, "hello.world", 2, {}] + ], listener.events + end end end end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index b5d72d1a42..bb20d26a25 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -128,6 +128,25 @@ module Notifications assert_equal [["named.subscription", :foo], ["named.subscription", :foo]], @events end + def test_unsubscribing_by_name_leaves_regexp_matched_subscriptions + @matched_events = [] + @notifier.subscribe(/subscription/) { |*args| @matched_events << event(*args) } + @notifier.publish("named.subscription", :before) + @notifier.wait + [@events, @named_events, @matched_events].each do |collector| + assert_includes(collector, ["named.subscription", :before]) + end + @notifier.unsubscribe("named.subscription") + @notifier.publish("named.subscription", :after) + @notifier.publish("other.subscription", :after) + @notifier.wait + assert_includes(@events, ["named.subscription", :after]) + assert_includes(@events, ["other.subscription", :after]) + assert_includes(@matched_events, ["other.subscription", :after]) + assert_not_includes(@matched_events, ["named.subscription", :after]) + assert_not_includes(@named_events, ["named.subscription", :after]) + end + private def event(*args) args |