2009-12-30 07:07:48 -05:00
|
|
|
require 'active_record_unit'
|
2009-12-31 01:14:57 -05:00
|
|
|
require 'active_record/railties/controller_runtime'
|
2009-12-30 07:07:48 -05:00
|
|
|
require 'fixtures/project'
|
2010-06-24 07:23:43 -04:00
|
|
|
require 'active_support/log_subscriber/test_helper'
|
|
|
|
require 'action_controller/log_subscriber'
|
2009-12-30 07:07:48 -05:00
|
|
|
|
2009-12-31 01:14:57 -05:00
|
|
|
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
|
2009-12-30 07:07:48 -05:00
|
|
|
|
2010-02-15 09:44:30 -05:00
|
|
|
class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
|
|
|
|
class LogSubscriberController < ActionController::Base
|
2010-01-12 19:18:23 -05:00
|
|
|
def show
|
|
|
|
render :inline => "<%= Project.all %>"
|
|
|
|
end
|
2009-12-30 07:07:48 -05:00
|
|
|
end
|
2010-02-23 20:31:17 -05:00
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
include ActiveSupport::LogSubscriber::TestHelper
|
2010-02-15 09:44:30 -05:00
|
|
|
tests LogSubscriberController
|
2009-12-30 07:07:48 -05:00
|
|
|
|
|
|
|
def setup
|
2010-03-02 17:40:59 -05:00
|
|
|
super
|
2010-01-12 19:18:23 -05:00
|
|
|
@old_logger = ActionController::Base.logger
|
2010-06-24 07:23:43 -04:00
|
|
|
ActionController::LogSubscriber.attach_to :action_controller
|
2009-12-30 07:07:48 -05:00
|
|
|
end
|
|
|
|
|
2010-01-12 19:18:23 -05:00
|
|
|
def teardown
|
|
|
|
super
|
2010-06-24 07:23:43 -04:00
|
|
|
ActiveSupport::LogSubscriber.log_subscribers.clear
|
2010-01-12 19:18:23 -05:00
|
|
|
ActionController::Base.logger = @old_logger
|
2009-12-30 07:07:48 -05:00
|
|
|
end
|
|
|
|
|
2010-01-12 19:18:23 -05:00
|
|
|
def set_logger(logger)
|
|
|
|
ActionController::Base.logger = logger
|
|
|
|
end
|
2010-02-15 11:20:11 -05:00
|
|
|
|
2009-12-30 07:07:48 -05:00
|
|
|
def test_log_with_active_record
|
|
|
|
get :show
|
|
|
|
wait
|
2010-01-12 19:18:23 -05:00
|
|
|
|
2010-01-19 06:52:10 -05:00
|
|
|
assert_equal 2, @logger.logged(:info).size
|
|
|
|
assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1]
|
2009-12-30 07:07:48 -05:00
|
|
|
end
|
2010-02-23 20:31:17 -05:00
|
|
|
end
|