提交 ffc861c1 编写于 作者: J José Valim

Merge pull request #5986 from carlosantoniodasilva/deprecation-behavior-silence

Add a "silence" behavior to completely turn off deprecation warnings.
## 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*
......
......@@ -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
......@@ -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 }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册