diff options
author | sushant <sushant@bigbinary.com> | 2019-04-04 10:57:57 +0530 |
---|---|---|
committer | sushant <sushant@bigbinary.com> | 2019-04-04 10:57:57 +0530 |
commit | ca19b7f5d86aa590077766cbe8006f952b6d4296 (patch) | |
tree | 1cd0d9c08401b35a60f22c44470239759262ab69 /activesupport/test | |
parent | d8d6bd5e63a9a4a6c06a4dde3c7137ee2be105fd (diff) | |
download | rails-ca19b7f5d86aa590077766cbe8006f952b6d4296.tar.gz rails-ca19b7f5d86aa590077766cbe8006f952b6d4296.tar.bz2 rails-ca19b7f5d86aa590077766cbe8006f952b6d4296.zip |
Added 'detach_from' to 'ActiveSupport::Subscriber' to detach a subscriber from a namespace.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/subscriber_test.rb | 23 |
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 |