blob: 37c7738301e8b6a85780090004827252eb364638 (
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
51
52
53
|
require 'active_record_unit'
require 'active_record/railties/controller_runtime'
require 'fixtures/project'
require 'rails/subscriber/test_helper'
require 'action_controller/railties/subscriber'
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
module ControllerRuntimeSubscriberTest
class SubscriberController < ActionController::Base
def show
render :inline => "<%= Project.all %>"
end
end
def self.included(base)
base.tests SubscriberController
end
def setup
@old_logger = ActionController::Base.logger
Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
super
end
def teardown
super
Rails::Subscriber.subscribers.clear
ActionController::Base.logger = @old_logger
end
def set_logger(logger)
ActionController::Base.logger = logger
end
def test_log_with_active_record
get :show
wait
assert_equal 2, @logger.logged(:info).size
assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1]
end
class SyncSubscriberTest < ActionController::TestCase
include Rails::Subscriber::SyncTestHelper
include ControllerRuntimeSubscriberTest
end
class AsyncSubscriberTest < ActionController::TestCase
include Rails::Subscriber::AsyncTestHelper
include ControllerRuntimeSubscriberTest
end
end
|