blob: c861d10c355c4f9b931953a7360efd5ed02533c1 (
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
41
42
43
44
45
46
47
48
49
50
|
require "isolation/abstract_unit"
module ApplicationTests
class NotificationsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
class MyQueue
attr_reader :events, :subscribers
def initialize
@events = []
@subscribers = []
end
def publish(name, payload=nil)
@events << name
end
def subscribe(pattern=nil, &block)
@subscribers << pattern
end
end
def setup
build_app
boot_rails
require "active_support/notifications"
Rails::Initializer.run do |c|
c.notifications.queue = MyQueue.new
c.notifications.subscribe(/listening/) do
puts "Cool"
end
end
end
test "new queue is set" do
ActiveSupport::Notifications.instrument(:foo)
assert_equal :foo, ActiveSupport::Notifications.queue.events.first
end
test "frameworks subscribers are loaded" do
assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == "sql" }
end
test "configuration subscribers are loaded" do
assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ }
end
end
end
|