aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/subscriber_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2013-09-20 08:18:01 -0700
committerJosé Valim <jose.valim@plataformatec.com.br>2013-09-20 08:18:01 -0700
commit34088572270a1dd5a2164b6aa5fc3642cb0479cb (patch)
treec3544acc1a380c8b09cd2bf422344640beef9b68 /activesupport/test/subscriber_test.rb
parent218c089ae7fd997fda23cc604f18df95c58d31b0 (diff)
parentd2824a347fd827bb0af3c16ffed5a3608b358ffc (diff)
downloadrails-34088572270a1dd5a2164b6aa5fc3642cb0479cb.tar.gz
rails-34088572270a1dd5a2164b6aa5fc3642cb0479cb.tar.bz2
rails-34088572270a1dd5a2164b6aa5fc3642cb0479cb.zip
Merge pull request #12285 from dasch/dasch/allow-attaching-up-front
Allow attaching to AS::Notifications namespace up front
Diffstat (limited to 'activesupport/test/subscriber_test.rb')
-rw-r--r--activesupport/test/subscriber_test.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb
new file mode 100644
index 0000000000..253411aa3d
--- /dev/null
+++ b/activesupport/test/subscriber_test.rb
@@ -0,0 +1,40 @@
+require 'abstract_unit'
+require 'active_support/subscriber'
+
+class TestSubscriber < ActiveSupport::Subscriber
+ attach_to :doodle
+
+ cattr_reader :event
+
+ def self.clear
+ @@event = nil
+ end
+
+ def open_party(event)
+ @@event = event
+ end
+
+ private
+
+ def private_party(event)
+ @@event = event
+ end
+end
+
+class SubscriberTest < ActiveSupport::TestCase
+ def setup
+ TestSubscriber.clear
+ end
+
+ def test_attaches_subscribers
+ ActiveSupport::Notifications.instrument("open_party.doodle")
+
+ assert_equal "open_party.doodle", TestSubscriber.event.name
+ end
+
+ def test_does_not_attach_private_methods
+ ActiveSupport::Notifications.instrument("private_party.doodle")
+
+ assert_nil TestSubscriber.event
+ end
+end