blob: 253411aa3d98cd152f63842b2caaf8192eeceab9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
|