Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d9314b4c
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,体验更适合开发者的 AI 搜索 >>
提交
d9314b4c
编写于
8月 07, 2013
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Coerce strings when reading attributes.
上级
96759cf6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
7 deletion
+50
-7
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+11
-0
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+8
-2
activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
...d/lib/active_record/connection_adapters/postgresql/oid.rb
+13
-5
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+18
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
d9314b4c
*
Coerce strings when reading attributes.
Fixes #10485.
Example:
book = Book.new(title: 12345)
book.save!
book.title # => "12345"
*Yves Senn*
*
Deprecate half-baked support for PostgreSQL range values with excluding beginnings.
We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
possible because the Ruby range does not support excluded beginnings.
...
...
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
d9314b4c
...
...
@@ -87,7 +87,7 @@ def type_cast_for_write(value)
end
end
# Casts value
(which is a String)
to an appropriate instance.
# Casts value to an appropriate instance.
def
type_cast
(
value
)
return
nil
if
value
.
nil?
return
coder
.
load
(
value
)
if
encoded?
...
...
@@ -95,7 +95,13 @@ def type_cast(value)
klass
=
self
.
class
case
type
when
:string
,
:text
then
value
when
:string
,
:text
case
value
when
TrueClass
;
"1"
when
FalseClass
;
"0"
else
value
.
to_s
end
when
:integer
then
klass
.
value_to_integer
(
value
)
when
:float
then
value
.
to_f
when
:decimal
then
klass
.
value_to_decimal
(
value
)
...
...
activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
浏览文件 @
d9314b4c
...
...
@@ -18,6 +18,14 @@ def type_cast(value)
end
end
class
Text
<
Type
def
type_cast
(
value
)
return
if
value
.
nil?
value
.
to_s
end
end
class
Bit
<
Type
def
type_cast
(
value
)
if
String
===
value
...
...
@@ -329,7 +337,7 @@ def self.registered_type?(name)
alias_type
'oid'
,
'int2'
register_type
'numeric'
,
OID
::
Decimal
.
new
register_type
'text'
,
OID
::
Identity
.
new
register_type
'text'
,
OID
::
Text
.
new
alias_type
'varchar'
,
'text'
alias_type
'char'
,
'text'
alias_type
'bpchar'
,
'text'
...
...
@@ -355,13 +363,13 @@ def self.registered_type?(name)
register_type
'date'
,
OID
::
Date
.
new
register_type
'time'
,
OID
::
Time
.
new
register_type
'path'
,
OID
::
Identity
.
new
register_type
'path'
,
OID
::
Text
.
new
register_type
'point'
,
OID
::
Point
.
new
register_type
'polygon'
,
OID
::
Identity
.
new
register_type
'circle'
,
OID
::
Identity
.
new
register_type
'polygon'
,
OID
::
Text
.
new
register_type
'circle'
,
OID
::
Text
.
new
register_type
'hstore'
,
OID
::
Hstore
.
new
register_type
'json'
,
OID
::
Json
.
new
register_type
'ltree'
,
OID
::
Identity
.
new
register_type
'ltree'
,
OID
::
Text
.
new
register_type
'cidr'
,
OID
::
Cidr
.
new
alias_type
'inet'
,
'cidr'
...
...
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
d9314b4c
...
...
@@ -555,6 +555,24 @@ def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_els
end
end
def
test_converted_values_are_returned_after_assignment
developer
=
Developer
.
new
(
name:
1337
,
salary:
"50000"
)
assert_equal
"50000"
,
developer
.
salary_before_type_cast
assert_equal
1337
,
developer
.
name_before_type_cast
assert_equal
50000
,
developer
.
salary
assert_equal
"1337"
,
developer
.
name
developer
.
save!
assert_equal
"50000"
,
developer
.
salary_before_type_cast
assert_equal
1337
,
developer
.
name_before_type_cast
assert_equal
50000
,
developer
.
salary
assert_equal
"1337"
,
developer
.
name
end
def
test_write_nil_to_time_attributes
in_time_zone
"Pacific Time (US & Canada)"
do
record
=
@target
.
new
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录