diff options
author | José Valim <jose.valim@gmail.com> | 2010-07-20 21:20:19 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-20 21:21:14 +0200 |
commit | d4151d7f0ac4a0823e788c0beed9ec2476e72386 (patch) | |
tree | 79576edab9209c77bfb118296ee40f4bad9b7a64 | |
parent | e1df4b956882f0c10a310088c1c13dcaa655a3b1 (diff) | |
download | rails-d4151d7f0ac4a0823e788c0beed9ec2476e72386.tar.gz rails-d4151d7f0ac4a0823e788c0beed9ec2476e72386.tar.bz2 rails-d4151d7f0ac4a0823e788c0beed9ec2476e72386.zip |
Fix a failing test in Railtie and properly define all severity levels in MockLogger for LogSubscriber.
3 files changed, 21 insertions, 22 deletions
diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index 2a207bed8a..91ba852ecd 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -22,7 +22,6 @@ class LogSubscriberTest < ActiveRecord::TestCase end def test_basic_query_logging - @logger.debugging = true Developer.all wait assert_equal 1, @logger.logged(:debug).size @@ -31,7 +30,6 @@ class LogSubscriberTest < ActiveRecord::TestCase end def test_cached_queries - @logger.debugging = true ActiveRecord::Base.cache do Developer.all Developer.all @@ -43,14 +41,14 @@ class LogSubscriberTest < ActiveRecord::TestCase end def test_basic_query_doesnt_log_when_level_is_not_debug - @logger.debugging = false + @logger.level = 1 Developer.all wait assert_equal 0, @logger.logged(:debug).size end def test_cached_queries_doesnt_log_when_level_is_not_debug - @logger.debugging = false + @logger.level = 1 ActiveRecord::Base.cache do Developer.all Developer.all diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index 0f5fc3554b..9e52cb97a9 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -1,4 +1,5 @@ require 'active_support/log_subscriber' +require 'active_support/buffered_logger' module ActiveSupport class LogSubscriber @@ -47,13 +48,14 @@ module ActiveSupport end class MockLogger + include ActiveSupport::BufferedLogger::Severity + attr_reader :flush_count - attr_accessor :debugging - alias :debug? :debugging + attr_accessor :level - def initialize + def initialize(level = DEBUG) @flush_count = 0 - @debugging = false + @level = level @logged = Hash.new { |h,k| h[k] = [] } end @@ -68,6 +70,14 @@ module ActiveSupport def flush @flush_count += 1 end + + ActiveSupport::BufferedLogger::Severity.constants.each do |severity| + class_eval <<-EOT, __FILE__, __LINE__ + 1 + def #{severity.downcase}? + #{severity} >= @level + end + EOT + end end # Wait notifications to be published. diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb index fc8548af1f..7e035be764 100644 --- a/railties/test/application/initializers/notifications_test.rb +++ b/railties/test/application/initializers/notifications_test.rb @@ -1,17 +1,6 @@ require "isolation/abstract_unit" module ApplicationTests - class MockLogger - def method_missing(*args) - @logged ||= [] - @logged << args.last - end - - def logged - @logged.compact.map { |l| l.to_s.strip } - end - end - class NotificationsTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation @@ -34,15 +23,17 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" + require "active_support/log_subscriber/test_helper" - ActiveRecord::Base.logger = logger = MockLogger.new + logger = ActiveSupport::LogSubscriber::TestHelper::MockLogger.new + ActiveRecord::Base.logger = logger # Mimic Active Record notifications instrument "sql.active_record", :name => "SQL", :sql => "SHOW tables" wait - assert_equal 1, logger.logged.size - assert_match /SHOW tables/, logger.logged.last + assert_equal 1, logger.logged(:debug).size + assert_match /SHOW tables/, logger.logged(:debug).last end end end |