mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d2824a347f
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.
40 lines
734 B
Ruby
40 lines
734 B
Ruby
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
|