From ed2fea908a9f8540ac2ea949e3e258ab88769cb1 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 14 Sep 2012 18:52:15 +0400 Subject: [PATCH] Deprecate ActiveSupport::Benchmarkable#silence. Due to its lack of thread safety, we're deprecating this, and it will be removed in Rails 4.1. Fixes #4060. --- activerecord/test/cases/base_test.rb | 30 +++++++++++-------- activesupport/CHANGELOG.md | 4 +++ .../lib/active_support/benchmarkable.rb | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index b9d480d9ce..b25d169038 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1619,26 +1619,32 @@ class BasicsTest < ActiveRecord::TestCase def test_silence_sets_log_level_to_error_in_block original_logger = ActiveRecord::Base.logger - log = StringIO.new - ActiveRecord::Base.logger = ActiveSupport::Logger.new(log) - ActiveRecord::Base.logger.level = Logger::DEBUG - ActiveRecord::Base.silence do - ActiveRecord::Base.logger.warn "warn" - ActiveRecord::Base.logger.error "error" + + assert_deprecated do + log = StringIO.new + ActiveRecord::Base.logger = ActiveSupport::Logger.new(log) + ActiveRecord::Base.logger.level = Logger::DEBUG + ActiveRecord::Base.silence do + ActiveRecord::Base.logger.warn "warn" + ActiveRecord::Base.logger.error "error" + end + assert_equal "error\n", log.string end - assert_equal "error\n", log.string ensure ActiveRecord::Base.logger = original_logger end def test_silence_sets_log_level_back_to_level_before_yield original_logger = ActiveRecord::Base.logger - log = StringIO.new - ActiveRecord::Base.logger = ActiveSupport::Logger.new(log) - ActiveRecord::Base.logger.level = Logger::WARN - ActiveRecord::Base.silence do + + assert_deprecated do + log = StringIO.new + ActiveRecord::Base.logger = ActiveSupport::Logger.new(log) + ActiveRecord::Base.logger.level = Logger::WARN + ActiveRecord::Base.silence do + end + assert_equal Logger::WARN, ActiveRecord::Base.logger.level end - assert_equal Logger::WARN, ActiveRecord::Base.logger.level ensure ActiveRecord::Base.logger = original_logger end diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index c36df796a8..c10a0b390b 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* ActiveSupport::Benchmarkable#silence has been deprecated due to its lack of + thread safety. It will be removed without replacement in Rails 4.1. *Steve + Klabnik* + * An optional block can be passed to `Hash#deep_merge`. The block will be invoked for each duplicated key and used to resolve the conflict. *Pranas Kiziela* diff --git a/activesupport/lib/active_support/benchmarkable.rb b/activesupport/lib/active_support/benchmarkable.rb index f149a7f0ed..1b391697e6 100644 --- a/activesupport/lib/active_support/benchmarkable.rb +++ b/activesupport/lib/active_support/benchmarkable.rb @@ -46,6 +46,7 @@ module ActiveSupport # Silence the logger during the execution of the block. # def silence + ActiveSupport::Deprecation.warn "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1." old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger yield ensure