aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-04-29 01:24:27 -0700
committerJosé Valim <jose.valim@gmail.com>2012-04-29 01:24:27 -0700
commitffc861c101c3d7284a512c1ac407a4027a0f175e (patch)
tree4fd0534663b94cb8d5e7752212fbe98f97cce2bf
parente73f54763568f06588c227c7ca759178102b914d (diff)
parent34599c4f57121bf693886b39f9a9724d41998514 (diff)
downloadrails-ffc861c101c3d7284a512c1ac407a4027a0f175e.tar.gz
rails-ffc861c101c3d7284a512c1ac407a4027a0f175e.tar.bz2
rails-ffc861c101c3d7284a512c1ac407a4027a0f175e.zip
Merge pull request #5986 from carlosantoniodasilva/deprecation-behavior-silence
Add a "silence" behavior to completely turn off deprecation warnings.
-rw-r--r--activesupport/CHANGELOG.md2
-rw-r--r--activesupport/lib/active_support/deprecation/behaviors.rb12
-rw-r--r--activesupport/test/deprecation_test.rb20
3 files changed, 32 insertions, 2 deletions
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 94f8d7133e..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
@@ -41,8 +48,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
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 }