diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-16 21:13:34 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-16 21:13:34 -0300 |
commit | fd119467b66d98de98d8d128382ba551c5d7a3fa (patch) | |
tree | 1693368a6ef286dad309488aff18b174d4fb3f0b /activesupport/test/subscriber_test.rb | |
parent | a9ebfc0f6a1b7a54a425887b9d1a37b08633666b (diff) | |
parent | b50468d13dfc5d9ba1abe9b097d80b0191f6933f (diff) | |
download | rails-fd119467b66d98de98d8d128382ba551c5d7a3fa.tar.gz rails-fd119467b66d98de98d8d128382ba551c5d7a3fa.tar.bz2 rails-fd119467b66d98de98d8d128382ba551c5d7a3fa.zip |
Merge pull request #15037 from roccoblues/fix_duplicate_activesupport_subscribers
Fixed duplicate subscribers in ActiveSupport::Subscriber
Conflicts:
activesupport/CHANGELOG.md
Diffstat (limited to 'activesupport/test/subscriber_test.rb')
-rw-r--r-- | activesupport/test/subscriber_test.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb index 253411aa3d..8be8c51f07 100644 --- a/activesupport/test/subscriber_test.rb +++ b/activesupport/test/subscriber_test.rb @@ -4,20 +4,27 @@ require 'active_support/subscriber' class TestSubscriber < ActiveSupport::Subscriber attach_to :doodle - cattr_reader :event + cattr_reader :events def self.clear - @@event = nil + @@events = [] end def open_party(event) - @@event = event + events << event end private def private_party(event) - @@event = event + events << event + end +end + +# Monkey patch subscriber to test that only one subscriber per method is added. +class TestSubscriber + def open_party(event) + events << event end end @@ -29,12 +36,18 @@ class SubscriberTest < ActiveSupport::TestCase def test_attaches_subscribers ActiveSupport::Notifications.instrument("open_party.doodle") - assert_equal "open_party.doodle", TestSubscriber.event.name + assert_equal "open_party.doodle", TestSubscriber.events.first.name + end + + def test_attaches_only_one_subscriber + ActiveSupport::Notifications.instrument("open_party.doodle") + + assert_equal 1, TestSubscriber.events.size end def test_does_not_attach_private_methods ActiveSupport::Notifications.instrument("private_party.doodle") - assert_nil TestSubscriber.event + assert_equal TestSubscriber.events, [] end end |