Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a7ef0982
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,发现更多精彩内容 >>
提交
a7ef0982
编写于
4月 02, 2013
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10063 from SamSaffron/master
Per #9999 revert blank? to empty?
上级
aec0e68e
0a57f346
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
15 deletion
+29
-15
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+4
-4
activerecord/test/cases/column_test.rb
activerecord/test/cases/column_test.rb
+25
-11
未找到文件。
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
a7ef0982
...
...
@@ -161,7 +161,7 @@ def binary_to_string(value)
def
value_to_date
(
value
)
if
value
.
is_a?
(
String
)
return
nil
if
value
.
blank
?
return
nil
if
value
.
empty
?
fast_string_to_date
(
value
)
||
fallback_string_to_date
(
value
)
elsif
value
.
respond_to?
(
:to_date
)
value
.
to_date
...
...
@@ -172,14 +172,14 @@ def value_to_date(value)
def
string_to_time
(
string
)
return
string
unless
string
.
is_a?
(
String
)
return
nil
if
string
.
blank
?
return
nil
if
string
.
empty
?
fast_string_to_time
(
string
)
||
fallback_string_to_time
(
string
)
end
def
string_to_dummy_time
(
string
)
return
string
unless
string
.
is_a?
(
String
)
return
nil
if
string
.
blank
?
return
nil
if
string
.
empty
?
dummy_time_string
=
"2000-01-01
#{
string
}
"
...
...
@@ -192,7 +192,7 @@ def string_to_dummy_time(string)
# convert something to a boolean
def
value_to_boolean
(
value
)
if
value
.
is_a?
(
String
)
&&
value
.
blank
?
if
value
.
is_a?
(
String
)
&&
value
.
empty
?
nil
else
TRUE_VALUES
.
include?
(
value
)
...
...
activerecord/test/cases/column_test.rb
浏览文件 @
a7ef0982
...
...
@@ -6,6 +6,9 @@ module ConnectionAdapters
class
ColumnTest
<
ActiveRecord
::
TestCase
def
test_type_cast_boolean
column
=
Column
.
new
(
"field"
,
nil
,
"boolean"
)
assert
column
.
type_cast
(
''
).
nil?
assert
column
.
type_cast
(
nil
).
nil?
assert
column
.
type_cast
(
true
)
assert
column
.
type_cast
(
1
)
assert
column
.
type_cast
(
'1'
)
...
...
@@ -15,15 +18,21 @@ def test_type_cast_boolean
assert
column
.
type_cast
(
'TRUE'
)
assert
column
.
type_cast
(
'on'
)
assert
column
.
type_cast
(
'ON'
)
assert
!
column
.
type_cast
(
false
)
assert
!
column
.
type_cast
(
0
)
assert
!
column
.
type_cast
(
'0'
)
assert
!
column
.
type_cast
(
'f'
)
assert
!
column
.
type_cast
(
'F'
)
assert
!
column
.
type_cast
(
'false'
)
assert
!
column
.
type_cast
(
'FALSE'
)
assert
!
column
.
type_cast
(
'off'
)
assert
!
column
.
type_cast
(
'OFF'
)
# explicitly check for false vs nil
assert_equal
false
,
column
.
type_cast
(
false
)
assert_equal
false
,
column
.
type_cast
(
0
)
assert_equal
false
,
column
.
type_cast
(
'0'
)
assert_equal
false
,
column
.
type_cast
(
'f'
)
assert_equal
false
,
column
.
type_cast
(
'F'
)
assert_equal
false
,
column
.
type_cast
(
'false'
)
assert_equal
false
,
column
.
type_cast
(
'FALSE'
)
assert_equal
false
,
column
.
type_cast
(
'off'
)
assert_equal
false
,
column
.
type_cast
(
'OFF'
)
assert_equal
false
,
column
.
type_cast
(
' '
)
assert_equal
false
,
column
.
type_cast
(
"
\u
3000
\r\n
"
)
assert_equal
false
,
column
.
type_cast
(
"
\u
0000"
)
assert_equal
false
,
column
.
type_cast
(
'SOMETHING RANDOM'
)
end
def
test_type_cast_integer
...
...
@@ -65,8 +74,9 @@ def test_type_cast_nan_and_infinity_to_integer
def
test_type_cast_time
column
=
Column
.
new
(
"field"
,
nil
,
"time"
)
assert_equal
nil
,
column
.
type_cast
(
nil
)
assert_equal
nil
,
column
.
type_cast
(
''
)
assert_equal
nil
,
column
.
type_cast
(
'
'
)
assert_equal
nil
,
column
.
type_cast
(
'
ABC
'
)
time_string
=
Time
.
now
.
utc
.
strftime
(
"%T"
)
assert_equal
time_string
,
column
.
type_cast
(
time_string
).
strftime
(
"%T"
)
...
...
@@ -74,8 +84,10 @@ def test_type_cast_time
def
test_type_cast_datetime_and_timestamp
[
Column
.
new
(
"field"
,
nil
,
"datetime"
),
Column
.
new
(
"field"
,
nil
,
"timestamp"
)].
each
do
|
column
|
assert_equal
nil
,
column
.
type_cast
(
nil
)
assert_equal
nil
,
column
.
type_cast
(
''
)
assert_equal
nil
,
column
.
type_cast
(
' '
)
assert_equal
nil
,
column
.
type_cast
(
'ABC'
)
datetime_string
=
Time
.
now
.
utc
.
strftime
(
"%FT%T"
)
assert_equal
datetime_string
,
column
.
type_cast
(
datetime_string
).
strftime
(
"%FT%T"
)
...
...
@@ -84,8 +96,10 @@ def test_type_cast_datetime_and_timestamp
def
test_type_cast_date
column
=
Column
.
new
(
"field"
,
nil
,
"date"
)
assert_equal
nil
,
column
.
type_cast
(
nil
)
assert_equal
nil
,
column
.
type_cast
(
''
)
assert_equal
nil
,
column
.
type_cast
(
' '
)
assert_equal
nil
,
column
.
type_cast
(
' '
)
assert_equal
nil
,
column
.
type_cast
(
'ABC'
)
date_string
=
Time
.
now
.
utc
.
strftime
(
"%F"
)
assert_equal
date_string
,
column
.
type_cast
(
date_string
).
strftime
(
"%F"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录