Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
833aef43
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
833aef43
编写于
10月 17, 2015
作者:
M
Matthew Draper
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21953 from bdunne/fix_dep_warn
Fix deprecation warning messages on deprecate_methods
上级
cd4575f9
6c98fbd9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
92 addition
and
20 deletion
+92
-20
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+5
-0
activesupport/lib/active_support/deprecation/method_wrappers.rb
...support/lib/active_support/deprecation/method_wrappers.rb
+36
-12
activesupport/lib/active_support/testing/deprecation.rb
activesupport/lib/active_support/testing/deprecation.rb
+9
-8
activesupport/test/deprecation/method_wrappers_test.rb
activesupport/test/deprecation/method_wrappers_test.rb
+34
-0
activesupport/test/deprecation_test.rb
activesupport/test/deprecation_test.rb
+8
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
833aef43
*
Fix
`ActiveSupport::Deprecation#deprecate_methods`
to report using the
current deprecator instance, where applicable.
*Brandon Dunne*
*
`Cache#fetch`
instrumentation marks whether it was a
`:hit`
.
*Robin Clowers*
...
...
activesupport/lib/active_support/deprecation/method_wrappers.rb
浏览文件 @
833aef43
...
...
@@ -9,25 +9,49 @@ module MethodWrapper
# module Fred
# extend self
#
# def foo; end
# def bar; end
# def baz; end
# def aaa; end
# def bbb; end
# def ccc; end
# def ddd; end
# def eee; end
# end
#
# ActiveSupport::Deprecation.deprecate_methods(Fred, :foo, bar: :qux, baz: 'use Bar#baz instead')
# # => [:foo, :bar, :baz]
# Using the default deprecator:
# ActiveSupport::Deprecation.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
# # => [:aaa, :bbb, :ccc]
#
# Fred.foo
# # => "DEPRECATION WARNING: foo is deprecated and will be removed from Rails 4.1."
# Fred.aaa
# # DEPRECATION WARNING: aaa is deprecated and will be removed from Rails 5.0. (called from irb_binding at (irb):10)
# # => nil
#
# Fred.bar
# # => "DEPRECATION WARNING: bar is deprecated and will be removed from Rails 4.1 (use qux instead)."
# Fred.bbb
# # DEPRECATION WARNING: bbb is deprecated and will be removed from Rails 5.0 (use zzz instead). (called from irb_binding at (irb):11)
# # => nil
#
# Fred.baz
# # => "DEPRECATION WARNING: baz is deprecated and will be removed from Rails 4.1 (use Bar#baz instead)."
# Fred.ccc
# # DEPRECATION WARNING: ccc is deprecated and will be removed from Rails 5.0 (use Bar#ccc instead). (called from irb_binding at (irb):12)
# # => nil
#
# Passing in a custom deprecator:
# custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
# ActiveSupport::Deprecation.deprecate_methods(Fred, ddd: :zzz, deprecator: custom_deprecator)
# # => [:ddd]
#
# Fred.ddd
# DEPRECATION WARNING: ddd is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):15)
# # => nil
#
# Using a custom deprecator directly:
# custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
# custom_deprecator.deprecate_methods(Fred, eee: :zzz)
# # => [:eee]
#
# Fred.eee
# DEPRECATION WARNING: eee is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):18)
# # => nil
def
deprecate_methods
(
target_module
,
*
method_names
)
options
=
method_names
.
extract_options!
deprecator
=
options
.
delete
(
:deprecator
)
||
ActiveSupport
::
Deprecation
.
instance
deprecator
=
options
.
delete
(
:deprecator
)
||
self
method_names
+=
options
.
keys
mod
=
Module
.
new
do
...
...
activesupport/lib/active_support/testing/deprecation.rb
浏览文件 @
833aef43
...
...
@@ -3,8 +3,8 @@
module
ActiveSupport
module
Testing
module
Deprecation
#:nodoc:
def
assert_deprecated
(
match
=
nil
,
&
block
)
result
,
warnings
=
collect_deprecations
(
&
block
)
def
assert_deprecated
(
match
=
nil
,
deprecator
=
nil
,
&
block
)
result
,
warnings
=
collect_deprecations
(
deprecator
,
&
block
)
assert
!
warnings
.
empty?
,
"Expected a deprecation warning within the block but received none"
if
match
match
=
Regexp
.
new
(
Regexp
.
escape
(
match
))
unless
match
.
is_a?
(
Regexp
)
...
...
@@ -13,22 +13,23 @@ def assert_deprecated(match = nil, &block)
result
end
def
assert_not_deprecated
(
&
block
)
result
,
deprecations
=
collect_deprecations
(
&
block
)
def
assert_not_deprecated
(
deprecator
=
nil
,
&
block
)
result
,
deprecations
=
collect_deprecations
(
deprecator
,
&
block
)
assert
deprecations
.
empty?
,
"Expected no deprecation warning within the block but received
#{
deprecations
.
size
}
:
\n
#{
deprecations
*
"
\n
"
}
"
result
end
def
collect_deprecations
old_behavior
=
ActiveSupport
::
Deprecation
.
behavior
def
collect_deprecations
(
deprecator
=
nil
)
deprecator
||=
ActiveSupport
::
Deprecation
old_behavior
=
deprecator
.
behavior
deprecations
=
[]
ActiveSupport
::
Deprecation
.
behavior
=
Proc
.
new
do
|
message
,
callstack
|
deprecator
.
behavior
=
Proc
.
new
do
|
message
,
callstack
|
deprecations
<<
message
end
result
=
yield
[
result
,
deprecations
]
ensure
ActiveSupport
::
Deprecation
.
behavior
=
old_behavior
deprecator
.
behavior
=
old_behavior
end
end
end
...
...
activesupport/test/deprecation/method_wrappers_test.rb
0 → 100644
浏览文件 @
833aef43
require
'abstract_unit'
require
'active_support/deprecation'
class
MethodWrappersTest
<
ActiveSupport
::
TestCase
def
setup
@klass
=
Class
.
new
do
def
new_method
;
"abc"
end
alias_method
:old_method
,
:new_method
end
end
def
test_deprecate_methods_warning_default
warning
=
/old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/
ActiveSupport
::
Deprecation
.
deprecate_methods
(
@klass
,
:old_method
=>
:new_method
)
assert_deprecated
(
warning
)
{
assert_equal
"abc"
,
@klass
.
new
.
old_method
}
end
def
test_deprecate_methods_warning_with_optional_deprecator
warning
=
/old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/
deprecator
=
ActiveSupport
::
Deprecation
.
new
(
"next-release"
,
"MyGem"
)
ActiveSupport
::
Deprecation
.
deprecate_methods
(
@klass
,
:old_method
=>
:new_method
,
:deprecator
=>
deprecator
)
assert_deprecated
(
warning
,
deprecator
)
{
assert_equal
"abc"
,
@klass
.
new
.
old_method
}
end
def
test_deprecate_methods_warning_when_deprecated_with_custom_deprecator
warning
=
/old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/
deprecator
=
ActiveSupport
::
Deprecation
.
new
(
"next-release"
,
"MyGem"
)
deprecator
.
deprecate_methods
(
@klass
,
:old_method
=>
:new_method
)
assert_deprecated
(
warning
,
deprecator
)
{
assert_equal
"abc"
,
@klass
.
new
.
old_method
}
end
end
activesupport/test/deprecation_test.rb
浏览文件 @
833aef43
...
...
@@ -163,6 +163,14 @@ def test_deprecated_constant_proxy
assert_not_deprecated
{
assert_equal
Deprecatee
::
B
::
C
.
class
,
Deprecatee
::
A
.
class
}
end
def
test_assert_deprecated_raises_when_method_not_deprecated
assert_raises
(
Minitest
::
Assertion
)
{
assert_deprecated
{
@dtc
.
not
}
}
end
def
test_assert_not_deprecated
assert_raises
(
Minitest
::
Assertion
)
{
assert_not_deprecated
{
@dtc
.
partially
}
}
end
def
test_assert_deprecation_without_match
assert_deprecated
do
@dtc
.
partially
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录