diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index b6c3e91db82b37b6ae3e43a5ad23458befc9e200..77fa753ab318376f6729c8ae9719268a11f6e9b6 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 94f8d7133ef7ffb7a34ce70cb3fa2ec0aaf46418..73b6a42505ad830ce29f5ceb316d45ce2f58e00b 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -13,6 +13,13 @@ def behavior # 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 @@ -41,8 +48,9 @@ def behavior=(behavior) }, :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 diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index e821a285d7c21c0fd6d01ba9e675ddb851ee8c77..e21f3efe36d9085c323bdc6b84824922a1f7b5bb 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -93,6 +93,26 @@ def test_several_behaviors 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 }