Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4bd2a50f
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,发现更多精彩内容 >>
提交
4bd2a50f
编写于
6月 10, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15609 from sgrif/sg-yaml-virtual-columns
Keep the types of virtual columns after yaml serialization
上级
d5f480c5
47f1c10c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
3 deletion
+32
-3
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+6
-2
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+1
-0
activerecord/lib/active_record/type/serialized.rb
activerecord/lib/active_record/type/serialized.rb
+11
-0
activerecord/test/cases/yaml_serialization_test.rb
activerecord/test/cases/yaml_serialization_test.rb
+14
-1
未找到文件。
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
4bd2a50f
...
...
@@ -13,7 +13,7 @@ module Format
ISO_DATETIME
=
/\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
end
attr_reader
:name
,
:cast_type
,
:
null
,
:
sql_type
,
:default_function
attr_reader
:name
,
:cast_type
,
:sql_type
,
:default_function
delegate
:type
,
:precision
,
:scale
,
:limit
,
:klass
,
:accessor
,
:text?
,
:number?
,
:binary?
,
:serialized?
,
:changed?
,
...
...
@@ -34,7 +34,7 @@ def initialize(name, default, cast_type, sql_type = nil, null = true)
@name
=
name
@cast_type
=
cast_type
@sql_type
=
sql_type
@null
=
null
@null
able
=
null
@original_default
=
default
@default_function
=
nil
end
...
...
@@ -61,6 +61,10 @@ def with_type(type)
clone
.
instance_variable_set
(
'@cast_type'
,
type
)
end
end
def
null
@nullable
end
end
class
NullColumn
<
Column
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
4bd2a50f
...
...
@@ -356,6 +356,7 @@ def initialize_dup(other) # :nodoc:
def
encode_with
(
coder
)
coder
[
'raw_attributes'
]
=
@raw_attributes
coder
[
'attributes'
]
=
@attributes
coder
[
'column_types'
]
=
@column_types_override
coder
[
'new_record'
]
=
new_record?
end
...
...
activerecord/lib/active_record/type/serialized.rb
浏览文件 @
4bd2a50f
...
...
@@ -36,6 +36,17 @@ def accessor
ActiveRecord
::
Store
::
IndifferentHashAccessor
end
def
init_with
(
coder
)
@subtype
=
coder
[
'subtype'
]
@coder
=
coder
[
'coder'
]
__setobj__
(
@subtype
)
end
def
encode_with
(
coder
)
coder
[
'subtype'
]
=
@subtype
coder
[
'coder'
]
=
@coder
end
private
def
is_default_value?
(
value
)
...
...
activerecord/test/cases/yaml_serialization_test.rb
浏览文件 @
4bd2a50f
require
'cases/helper'
require
'models/topic'
require
'models/post'
require
'models/author'
class
YamlSerializationTest
<
ActiveRecord
::
TestCase
fixtures
:topics
fixtures
:topics
,
:authors
,
:posts
def
test_to_yaml_with_time_with_zone_should_not_raise_exception
with_timezone_config
aware_attributes:
true
,
zone:
"Pacific Time (US & Canada)"
do
...
...
@@ -69,4 +71,15 @@ def test_new_records_remain_new_after_round_trip
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
def
test_types_of_virtual_columns_are_not_changed_on_round_trip
author
=
Author
.
select
(
'authors.*, count(posts.id) as posts_count'
)
.
joins
(
:posts
)
.
group
(
'authors.id'
)
.
first
dumped
=
YAML
.
load
(
YAML
.
dump
(
author
))
assert_equal
5
,
author
.
posts_count
assert_equal
5
,
dumped
.
posts_count
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录