Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
007bb117
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 搜索 >>
提交
007bb117
编写于
12月 19, 2015
作者:
A
Akshay Vishnoi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix - to_s(:db) on Numeric range
上级
468df261
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
1 deletion
+31
-1
activesupport/lib/active_support/core_ext/numeric/conversions.rb
...upport/lib/active_support/core_ext/numeric/conversions.rb
+5
-1
activesupport/test/core_ext/numeric_ext_test.rb
activesupport/test/core_ext/numeric_ext_test.rb
+20
-0
activesupport/test/core_ext/range_ext_test.rb
activesupport/test/core_ext/range_ext_test.rb
+6
-0
未找到文件。
activesupport/lib/active_support/core_ext/numeric/conversions.rb
浏览文件 @
007bb117
...
@@ -120,7 +120,11 @@ def to_s(*args)
...
@@ -120,7 +120,11 @@ def to_s(*args)
when
:human_size
when
:human_size
return
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
self
,
options
)
return
ActiveSupport
::
NumberHelper
.
number_to_human_size
(
self
,
options
)
else
else
super
if
is_a?
(
Float
)
||
format
.
is_a?
(
Symbol
)
super
()
else
super
end
end
end
end
end
...
...
activesupport/test/core_ext/numeric_ext_test.rb
浏览文件 @
007bb117
...
@@ -406,6 +406,26 @@ def test_to_formatted_s_is_deprecated
...
@@ -406,6 +406,26 @@ def test_to_formatted_s_is_deprecated
end
end
end
end
def
test_to_s_with_invalid_formatter
assert_equal
'123'
,
123
.
to_s
(
:invalid
)
assert_equal
'2.5'
,
2.5
.
to_s
(
:invalid
)
assert_equal
'100000000000000000000'
,
(
100
**
10
).
to_s
(
:invalid
)
assert_equal
'1000010.0'
,
BigDecimal
(
"1000010"
).
to_s
(
:invalid
)
end
def
test_default_to_s
assert_equal
'123'
,
123
.
to_s
assert_equal
'1111011'
,
123
.
to_s
(
2
)
assert_equal
'2.5'
,
2.5
.
to_s
assert_equal
'100000000000000000000'
,
(
100
**
10
).
to_s
assert_equal
'1010110101111000111010111100010110101100011000100000000000000000000'
,
(
100
**
10
).
to_s
(
2
)
assert_equal
'1000010.0'
,
BigDecimal
(
"1000010"
).
to_s
assert_equal
'10000 10.0'
,
BigDecimal
(
"1000010"
).
to_s
(
'5F'
)
end
def
test_in_milliseconds
def
test_in_milliseconds
assert_equal
10_000
,
10
.
seconds
.
in_milliseconds
assert_equal
10_000
,
10
.
seconds
.
in_milliseconds
end
end
...
...
activesupport/test/core_ext/range_ext_test.rb
浏览文件 @
007bb117
require
'abstract_unit'
require
'abstract_unit'
require
'active_support/time'
require
'active_support/time'
require
'active_support/core_ext/numeric'
require
'active_support/core_ext/range'
require
'active_support/core_ext/range'
class
RangeTest
<
ActiveSupport
::
TestCase
class
RangeTest
<
ActiveSupport
::
TestCase
...
@@ -13,6 +14,11 @@ def test_to_s_from_times
...
@@ -13,6 +14,11 @@ def test_to_s_from_times
assert_equal
"BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'"
,
date_range
.
to_s
(
:db
)
assert_equal
"BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'"
,
date_range
.
to_s
(
:db
)
end
end
def
test_to_s_with_numeric
number_range
=
(
1
..
100
)
assert_equal
"BETWEEN '1' AND '100'"
,
number_range
.
to_s
(
:db
)
end
def
test_date_range
def
test_date_range
assert_instance_of
Range
,
DateTime
.
new
..
DateTime
.
new
assert_instance_of
Range
,
DateTime
.
new
..
DateTime
.
new
assert_instance_of
Range
,
DateTime
::
Infinity
.
new
..
DateTime
::
Infinity
.
new
assert_instance_of
Range
,
DateTime
::
Infinity
.
new
..
DateTime
::
Infinity
.
new
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录