Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
260c384b
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,发现更多精彩内容 >>
提交
260c384b
编写于
6月 01, 2014
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15432 from sgrif/sg-coder-type-casting
Don't change values in `@raw_attributes` during serialization
上级
75f75a87
93734629
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
14 addition
and
23 deletion
+14
-23
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+1
-1
activerecord/lib/active_record/attribute_methods/serialization.rb
...cord/lib/active_record/attribute_methods/serialization.rb
+1
-1
activerecord/test/cases/store_test.rb
activerecord/test/cases/store_test.rb
+0
-14
activerecord/test/cases/yaml_serialization_test.rb
activerecord/test/cases/yaml_serialization_test.rb
+12
-7
未找到文件。
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
260c384b
...
@@ -289,7 +289,7 @@ def attributes
...
@@ -289,7 +289,7 @@ def attributes
# Placeholder so it can be overriden when needed by serialization
# Placeholder so it can be overriden when needed by serialization
def
attributes_for_coder
# :nodoc:
def
attributes_for_coder
# :nodoc:
attributes
attributes
_before_type_cast
end
end
# Returns an <tt>#inspect</tt>-like string for the value of the
# Returns an <tt>#inspect</tt>-like string for the value of the
...
...
activerecord/lib/active_record/attribute_methods/serialization.rb
浏览文件 @
260c384b
...
@@ -138,7 +138,7 @@ def attributes_for_coder
...
@@ -138,7 +138,7 @@ def attributes_for_coder
attrs
[
name
]
=
if
self
.
class
.
serialized_attributes
.
include?
(
name
)
attrs
[
name
]
=
if
self
.
class
.
serialized_attributes
.
include?
(
name
)
@raw_attributes
[
name
].
serialized_value
@raw_attributes
[
name
].
serialized_value
else
else
read_attribute
(
name
)
read_attribute
_before_type_cast
(
name
)
end
end
end
end
end
end
...
...
activerecord/test/cases/store_test.rb
浏览文件 @
260c384b
...
@@ -183,20 +183,6 @@ class StoreTest < ActiveRecord::TestCase
...
@@ -183,20 +183,6 @@ class StoreTest < ActiveRecord::TestCase
assert_equal
({},
@john
.
params
)
assert_equal
({},
@john
.
params
)
end
end
test
"attributes_for_coder should return stored fields already serialized"
do
attributes
=
{
"id"
=>
@john
.
id
,
"name"
=>
@john
.
name
,
"settings"
=>
"--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
\n
color: black
\n
"
,
"preferences"
=>
"--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
\n
remember_login: true
\n
"
,
"json_data"
=>
"{
\"
height
\"
:
\"
tall
\"
}"
,
"json_data_empty"
=>
"{
\"
is_a_good_guy
\"
:true}"
,
"params"
=>
"--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess {}
\n
"
,
"account_id"
=>
@john
.
account_id
}
assert_equal
attributes
,
@john
.
attributes_for_coder
end
test
"dump, load and dump again a model"
do
test
"dump, load and dump again a model"
do
dumped
=
YAML
.
dump
(
@john
)
dumped
=
YAML
.
dump
(
@john
)
loaded
=
YAML
.
load
(
dumped
)
loaded
=
YAML
.
load
(
dumped
)
...
...
activerecord/test/cases/yaml_serialization_test.rb
浏览文件 @
260c384b
...
@@ -23,13 +23,6 @@ def test_roundtrip_serialized_column
...
@@ -23,13 +23,6 @@ def test_roundtrip_serialized_column
assert_equal
({
:omg
=>
:lol
},
YAML
.
load
(
YAML
.
dump
(
topic
)).
content
)
assert_equal
({
:omg
=>
:lol
},
YAML
.
load
(
YAML
.
dump
(
topic
)).
content
)
end
end
def
test_encode_with_coder
topic
=
Topic
.
first
coder
=
{}
topic
.
encode_with
coder
assert_equal
({
'attributes'
=>
topic
.
attributes
},
coder
)
end
def
test_psych_roundtrip
def
test_psych_roundtrip
topic
=
Topic
.
first
topic
=
Topic
.
first
assert
topic
assert
topic
...
@@ -47,4 +40,16 @@ def test_psych_roundtrip_new_object
...
@@ -47,4 +40,16 @@ def test_psych_roundtrip_new_object
def
test_active_record_relation_serialization
def
test_active_record_relation_serialization
[
Topic
.
all
].
to_yaml
[
Topic
.
all
].
to_yaml
end
end
def
test_raw_types_are_not_changed_on_round_trip
topic
=
Topic
.
new
(
parent_id:
"123"
)
assert_equal
"123"
,
topic
.
parent_id_before_type_cast
assert_equal
"123"
,
YAML
.
load
(
YAML
.
dump
(
topic
)).
parent_id_before_type_cast
end
def
test_cast_types_are_not_changed_on_round_trip
topic
=
Topic
.
new
(
parent_id:
"123"
)
assert_equal
123
,
topic
.
parent_id
assert_equal
123
,
YAML
.
load
(
YAML
.
dump
(
topic
)).
parent_id
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录