1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/log_subscriber_test.rb
Aaron Patterson 1def14309f cleaning up a bunch of parse time warnings in AR [#4186 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
2010-03-15 18:22:31 -07:00

43 lines
1.1 KiB
Ruby

require "cases/helper"
require "models/developer"
require "rails/log_subscriber/test_helper"
require "active_record/railties/log_subscriber"
class LogSubscriberTest < ActiveSupport::TestCase
include Rails::LogSubscriber::TestHelper
def setup
@old_logger = ActiveRecord::Base.logger
super
Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
end
def teardown
super
ActiveRecord::Base.logger = @old_logger
end
def set_logger(logger)
ActiveRecord::Base.logger = logger
end
def test_basic_query_logging
Developer.all
wait
assert_equal 1, @logger.logged(:debug).size
assert_match(/Developer Load/, @logger.logged(:debug).last)
assert_match(/SELECT .*?FROM .?developers.?/, @logger.logged(:debug).last)
end
def test_cached_queries
ActiveRecord::Base.cache do
Developer.all
Developer.all
end
wait
assert_equal 2, @logger.logged(:debug).size
assert_match(/CACHE/, @logger.logged(:debug).last)
assert_match(/SELECT .*?FROM .?developers.?/, @logger.logged(:debug).last)
end
end