Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fdb7f84e
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,发现更多精彩内容 >>
提交
fdb7f84e
编写于
6月 24, 2010
作者:
E
Emilio Tagua
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove deprecated block usage in composed_of.
上级
7710a8cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
2 addition
and
32 deletion
+2
-32
activerecord/lib/active_record/aggregations.rb
activerecord/lib/active_record/aggregations.rb
+2
-4
activerecord/test/cases/aggregations_test.rb
activerecord/test/cases/aggregations_test.rb
+0
-28
未找到文件。
activerecord/lib/active_record/aggregations.rb
浏览文件 @
fdb7f84e
...
@@ -190,7 +190,7 @@ module ClassMethods
...
@@ -190,7 +190,7 @@ module ClassMethods
# :constructor => Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
# :constructor => Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
# :converter => Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
# :converter => Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
#
#
def
composed_of
(
part_id
,
options
=
{}
,
&
block
)
def
composed_of
(
part_id
,
options
=
{})
options
.
assert_valid_keys
(
:class_name
,
:mapping
,
:allow_nil
,
:constructor
,
:converter
)
options
.
assert_valid_keys
(
:class_name
,
:mapping
,
:allow_nil
,
:constructor
,
:converter
)
name
=
part_id
.
id2name
name
=
part_id
.
id2name
...
@@ -199,9 +199,7 @@ def composed_of(part_id, options = {}, &block)
...
@@ -199,9 +199,7 @@ def composed_of(part_id, options = {}, &block)
mapping
=
[
mapping
]
unless
mapping
.
first
.
is_a?
(
Array
)
mapping
=
[
mapping
]
unless
mapping
.
first
.
is_a?
(
Array
)
allow_nil
=
options
[
:allow_nil
]
||
false
allow_nil
=
options
[
:allow_nil
]
||
false
constructor
=
options
[
:constructor
]
||
:new
constructor
=
options
[
:constructor
]
||
:new
converter
=
options
[
:converter
]
||
block
converter
=
options
[
:converter
]
ActiveSupport
::
Deprecation
.
warn
(
'The conversion block has been deprecated, use the :converter option instead.'
,
caller
)
if
block_given?
reader_method
(
name
,
class_name
,
mapping
,
allow_nil
,
constructor
)
reader_method
(
name
,
class_name
,
mapping
,
allow_nil
,
constructor
)
writer_method
(
name
,
class_name
,
mapping
,
allow_nil
,
converter
)
writer_method
(
name
,
class_name
,
mapping
,
allow_nil
,
converter
)
...
...
activerecord/test/cases/aggregations_test.rb
浏览文件 @
fdb7f84e
...
@@ -121,34 +121,6 @@ def test_custom_converter
...
@@ -121,34 +121,6 @@ def test_custom_converter
end
end
end
end
class
DeprecatedAggregationsTest
<
ActiveRecord
::
TestCase
class
Person
<
ActiveRecord
::
Base
;
end
def
test_conversion_block_is_deprecated
assert_deprecated
'conversion block has been deprecated'
do
Person
.
composed_of
(
:balance
,
:class_name
=>
"Money"
,
:mapping
=>
%w(balance amount)
)
{
|
balance
|
balance
.
to_money
}
end
end
def
test_conversion_block_used_when_converter_option_is_nil
assert_deprecated
'conversion block has been deprecated'
do
Person
.
composed_of
(
:balance
,
:class_name
=>
"Money"
,
:mapping
=>
%w(balance amount)
)
{
|
balance
|
balance
.
to_money
}
end
assert_raise
(
NoMethodError
)
{
Person
.
new
.
balance
=
5
}
end
def
test_converter_option_overrides_conversion_block
assert_deprecated
'conversion block has been deprecated'
do
Person
.
composed_of
(
:balance
,
:class_name
=>
"Money"
,
:mapping
=>
%w(balance amount)
,
:converter
=>
Proc
.
new
{
|
balance
|
Money
.
new
(
balance
)
})
{
|
balance
|
balance
.
to_money
}
end
person
=
Person
.
new
assert_nothing_raised
{
person
.
balance
=
5
}
assert_equal
5
,
person
.
balance
.
amount
assert_kind_of
Money
,
person
.
balance
end
end
class
OverridingAggregationsTest
<
ActiveRecord
::
TestCase
class
OverridingAggregationsTest
<
ActiveRecord
::
TestCase
class
Name
;
end
class
Name
;
end
class
DifferentName
;
end
class
DifferentName
;
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录