aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/activerecord/controller_runtime_test.rb
blob: 0f534da14bf81da4b20a1facd2761857b661c956 (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
require 'active_record_unit'
require 'active_record/railties/controller_runtime'
require 'fixtures/project'

ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime

class ARLoggingController < ActionController::Base
  def show
    render :inline => "<%= Project.all %>"
  end
end

class ARLoggingTest < ActionController::TestCase
  tests ARLoggingController

  def setup
    super
    set_logger
  end

  def wait
    ActiveSupport::Notifications.notifier.wait
  end

  def test_log_with_active_record
    get :show
    wait
    assert_match /ActiveRecord runtime/, logs[3]
  end

  private
    def set_logger
      @controller.logger = MockLogger.new
    end

    def logs
      @logs ||= @controller.logger.logged.compact.map {|l| l.to_s.strip}
    end
end