diff options
Diffstat (limited to 'activesupport/test/subscriber_test.rb')
-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 |