aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-04-04 15:12:54 -0400
committerGitHub <noreply@github.com>2019-04-04 15:12:54 -0400
commitdd972f9efe832e882c559ebc92274e3e5ccc294d (patch)
tree61487055d38b1710442f3e21d25735474b8bb3b5 /activesupport/test
parent3809e3e5e9edc2fcc1eac2f8266ad1d24a754618 (diff)
parentca19b7f5d86aa590077766cbe8006f952b6d4296 (diff)
downloadrails-dd972f9efe832e882c559ebc92274e3e5ccc294d.tar.gz
rails-dd972f9efe832e882c559ebc92274e3e5ccc294d.tar.bz2
rails-dd972f9efe832e882c559ebc92274e3e5ccc294d.zip
Merge pull request #35691 from sushantmittal/add_deattach_from_in_active_support_subscriber
Adds 'detach_from' to 'ActiveSupport::Subscriber' to detach a subscriber from a namespace.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/subscriber_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb
index 6b012e43af..bc8d8f1c13 100644
--- a/activesupport/test/subscriber_test.rb
+++ b/activesupport/test/subscriber_test.rb
@@ -23,6 +23,21 @@ class TestSubscriber < ActiveSupport::Subscriber
end
end
+class TestSubscriber2 < ActiveSupport::Subscriber
+ attach_to :doodle
+ detach_from :doodle
+
+ cattr_reader :events
+
+ def self.clear
+ @@events = []
+ end
+
+ def open_party(event)
+ events << event
+ end
+end
+
# Monkey patch subscriber to test that only one subscriber per method is added.
class TestSubscriber
remove_method :open_party
@@ -34,6 +49,7 @@ end
class SubscriberTest < ActiveSupport::TestCase
def setup
TestSubscriber.clear
+ TestSubscriber2.clear
end
def test_attaches_subscribers
@@ -53,4 +69,11 @@ class SubscriberTest < ActiveSupport::TestCase
assert_equal [], TestSubscriber.events
end
+
+ def test_detaches_subscribers
+ ActiveSupport::Notifications.instrument("open_party.doodle")
+
+ assert_equal [], TestSubscriber2.events
+ assert_equal 1, TestSubscriber.events.size
+ end
end