Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fab8d079
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,发现更多精彩内容 >>
提交
fab8d079
编写于
6月 01, 2014
作者:
G
Guillermo Iguaran
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15444 from sgrif/sg-yaml-new-record
New records should remain new after yaml serialization
上级
87cc918d
e08494a9
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
28 addition
and
2 deletion
+28
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+2
-1
activerecord/lib/active_record/persistence.rb
activerecord/lib/active_record/persistence.rb
+5
-1
activerecord/test/cases/yaml_serialization_test.rb
activerecord/test/cases/yaml_serialization_test.rb
+17
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
fab8d079
*
New records remain new after YAML serialization.
*Sean Griffin*
*
PostgreSQL support default values for enum types. Fixes #7814.
*Yves Senn*
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
fab8d079
...
...
@@ -284,7 +284,7 @@ def init_with(coder)
init_internals
@new_record
=
false
@new_record
=
coder
[
'new_record'
]
self
.
class
.
define_attribute_methods
...
...
@@ -354,6 +354,7 @@ def initialize_dup(other) # :nodoc:
# coder # => {"attributes" => {"id" => nil, ... }}
def
encode_with
(
coder
)
coder
[
'attributes'
]
=
@raw_attributes
coder
[
'new_record'
]
=
new_record?
end
# Returns true if +comparison_object+ is the same exact object, or +comparison_object+
...
...
activerecord/lib/active_record/persistence.rb
浏览文件 @
fab8d079
...
...
@@ -49,7 +49,11 @@ def create(attributes = nil, &block)
def
instantiate
(
attributes
,
column_types
=
{})
klass
=
discriminate_class_for_record
(
attributes
)
column_types
=
klass
.
decorate_columns
(
column_types
.
dup
)
klass
.
allocate
.
init_with
(
'attributes'
=>
attributes
,
'column_types'
=>
column_types
)
klass
.
allocate
.
init_with
(
'attributes'
=>
attributes
,
'column_types'
=>
column_types
,
'new_record'
=>
false
,
)
end
private
...
...
activerecord/test/cases/yaml_serialization_test.rb
浏览文件 @
fab8d079
...
...
@@ -52,4 +52,21 @@ def test_cast_types_are_not_changed_on_round_trip
assert_equal
123
,
topic
.
parent_id
assert_equal
123
,
YAML
.
load
(
YAML
.
dump
(
topic
)).
parent_id
end
def
test_new_records_remain_new_after_round_trip
topic
=
Topic
.
new
assert
topic
.
new_record?
,
"Sanity check that new records are new"
assert
YAML
.
load
(
YAML
.
dump
(
topic
)).
new_record?
,
"Record should be new after deserialization"
topic
.
save!
assert_not
topic
.
new_record?
,
"Saved records are not new"
assert_not
YAML
.
load
(
YAML
.
dump
(
topic
)).
new_record?
,
"Saved record should not be new after deserialization"
topic
=
Topic
.
select
(
'title'
).
last
assert_not
topic
.
new_record?
,
"Loaded records without ID are not new"
assert_not
YAML
.
load
(
YAML
.
dump
(
topic
)).
new_record?
,
"Record should not be new after deserialization"
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录