diff options
author | Daniel Schierbeck <dasch@zendesk.com> | 2013-09-19 11:03:58 +0200 |
---|---|---|
committer | Daniel Schierbeck <dasch@zendesk.com> | 2013-09-20 10:14:28 +0200 |
commit | d2824a347fd827bb0af3c16ffed5a3608b358ffc (patch) | |
tree | f30fee6a3f57ebfaf02dfaf81f7f90da50783e21 /activesupport/test/subscriber_test.rb | |
parent | 76d36458eadcb32c233f44065fccfbbef9a58119 (diff) | |
download | rails-d2824a347fd827bb0af3c16ffed5a3608b358ffc.tar.gz rails-d2824a347fd827bb0af3c16ffed5a3608b358ffc.tar.bz2 rails-d2824a347fd827bb0af3c16ffed5a3608b358ffc.zip |
Allow attaching to AS::Notifications namespace up front
Before, you were required to attach *after* adding the methods to the
class, since the attachment process needed the methods to be present.
With this change, any new method will also be attached to the configured
namespace.
Diffstat (limited to 'activesupport/test/subscriber_test.rb')
-rw-r--r-- | activesupport/test/subscriber_test.rb | 40 |
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 |