From 76cd1ca08dc31babd7e9e527a8a9c86321ed905a Mon Sep 17 00:00:00 2001 From: Adam Hawkins Date: Sun, 15 Apr 2012 16:21:06 +0300 Subject: Add a "silence" behavior to completely turn off deprecation warnings. --- activesupport/lib/active_support/deprecation/behaviors.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 94f8d7133e..8d92c50679 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -41,8 +41,9 @@ module ActiveSupport }, :notify => Proc.new { |message, callstack| ActiveSupport::Notifications.instrument("deprecation.rails", - :message => message, :callstack => callstack) - } + :message => message, :callstack => callstack) + }, + :silence => Proc.new { |message, callstack| } } end end -- cgit v1.2.3 From 9608395923899e3f91e0d07ac2ed52efc17bcc40 Mon Sep 17 00:00:00 2001 From: twinturbo Date: Tue, 17 Apr 2012 22:01:06 +0200 Subject: Document #behavior= and update CHANGELOG --- activesupport/CHANGELOG.md | 2 ++ activesupport/lib/active_support/deprecation/behaviors.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index b6c3e91db8..77fa753ab3 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 4.0.0 (unreleased) ## +* Add ActiveSupport::Deprecations.behavior = :slience to to completely ignore *twinturbo* + * Make Module#delegate stop using `send` - can no longer delegate to private methods. *dasch* * AS::Callbacks: deprecate `:rescuable` option. *Bogdan Gusiev* diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 8d92c50679..73b6a42505 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -13,6 +13,13 @@ module ActiveSupport # Sets the behavior to the specified value. Can be a single value or an array. # + # Available behaviors: + # + # [+:stderr+] Print deprecations to +$stderror+ + # [+:log+] Send to +Rails.logger+ + # [+:notify+] Instrument using +ActiveSupport::Notifications+ + # [+:silence+] Do nothing + # # Examples # # ActiveSupport::Deprecation.behavior = :stderr -- cgit v1.2.3 From 34599c4f57121bf693886b39f9a9724d41998514 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 28 Apr 2012 18:22:11 -0300 Subject: Add test for default silence and stderr deprecation behaviors --- activesupport/test/deprecation_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index e821a285d7..e21f3efe36 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -93,6 +93,26 @@ class DeprecationTest < ActiveSupport::TestCase assert_match(/foo=nil/, @b) end + def test_default_stderr_behavior + ActiveSupport::Deprecation.behavior = :stderr + behavior = ActiveSupport::Deprecation.behavior.first + + content = capture(:stderr) { + assert_nil behavior.call('Some error!', ['call stack!']) + } + assert_match(/Some error!/, content) + assert_match(/call stack!/, content) + end + + def test_default_silence_behavior + ActiveSupport::Deprecation.behavior = :silence + behavior = ActiveSupport::Deprecation.behavior.first + + assert_blank capture(:stderr) { + assert_nil behavior.call('Some error!', ['call stack!']) + } + end + def test_deprecated_instance_variable_proxy assert_not_deprecated { @dtc.request.size } -- cgit v1.2.3