Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a5922f13
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 搜索 >>
未验证
提交
a5922f13
编写于
12月 14, 2017
作者:
S
Sean Griffin
提交者:
GitHub
12月 14, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #31452 from yahonda/deprecated_bigdecimal_new_activemodel
Suppress `warning: BigDecimal.new is deprecated` in Active Model
上级
f67892b6
bd4211ea
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
23 deletion
+23
-23
activemodel/test/cases/attributes_test.rb
activemodel/test/cases/attributes_test.rb
+1
-1
activemodel/test/cases/type/decimal_test.rb
activemodel/test/cases/type/decimal_test.rb
+8
-8
activemodel/test/cases/validations/numericality_validation_test.rb
...el/test/cases/validations/numericality_validation_test.rb
+14
-14
未找到文件。
activemodel/test/cases/attributes_test.rb
浏览文件 @
a5922f13
...
...
@@ -33,7 +33,7 @@ class GrandchildModelForAttributesTest < ChildModelForAttributesTest
assert_equal
2
,
data
.
integer_field
assert_equal
"Rails FTW"
,
data
.
string_field
assert_equal
BigDecimal
.
new
(
"12.3"
),
data
.
decimal_field
assert_equal
BigDecimal
(
"12.3"
),
data
.
decimal_field
assert_equal
"default string"
,
data
.
string_with_default
assert_equal
Date
.
new
(
2016
,
1
,
1
),
data
.
date_field
assert_equal
false
,
data
.
boolean_field
...
...
activemodel/test/cases/type/decimal_test.rb
浏览文件 @
a5922f13
...
...
@@ -7,22 +7,22 @@ module Type
class
DecimalTest
<
ActiveModel
::
TestCase
def
test_type_cast_decimal
type
=
Decimal
.
new
assert_equal
BigDecimal
.
new
(
"0"
),
type
.
cast
(
BigDecimal
.
new
(
"0"
))
assert_equal
BigDecimal
.
new
(
"123"
),
type
.
cast
(
123.0
)
assert_equal
BigDecimal
.
new
(
"1"
),
type
.
cast
(
:"1"
)
assert_equal
BigDecimal
(
"0"
),
type
.
cast
(
BigDecimal
(
"0"
))
assert_equal
BigDecimal
(
"123"
),
type
.
cast
(
123.0
)
assert_equal
BigDecimal
(
"1"
),
type
.
cast
(
:"1"
)
end
def
test_type_cast_decimal_from_invalid_string
type
=
Decimal
.
new
assert_nil
type
.
cast
(
""
)
assert_equal
BigDecimal
.
new
(
"1"
),
type
.
cast
(
"1ignore"
)
assert_equal
BigDecimal
.
new
(
"0"
),
type
.
cast
(
"bad1"
)
assert_equal
BigDecimal
.
new
(
"0"
),
type
.
cast
(
"bad"
)
assert_equal
BigDecimal
(
"1"
),
type
.
cast
(
"1ignore"
)
assert_equal
BigDecimal
(
"0"
),
type
.
cast
(
"bad1"
)
assert_equal
BigDecimal
(
"0"
),
type
.
cast
(
"bad"
)
end
def
test_type_cast_decimal_from_float_with_large_precision
type
=
Decimal
.
new
(
precision:
::
Float
::
DIG
+
2
)
assert_equal
BigDecimal
.
new
(
"123.0"
),
type
.
cast
(
123.0
)
assert_equal
BigDecimal
(
"123.0"
),
type
.
cast
(
123.0
)
end
def
test_type_cast_from_float_with_unspecified_precision
...
...
@@ -48,7 +48,7 @@ def test_type_cast_decimal_from_rational_without_precision_defaults_to_18_36
def
test_type_cast_decimal_from_object_responding_to_d
value
=
Object
.
new
def
value
.
to_d
BigDecimal
.
new
(
"1"
)
BigDecimal
(
"1"
)
end
type
=
Decimal
.
new
assert_equal
BigDecimal
(
"1"
),
type
.
cast
(
value
)
...
...
activemodel/test/cases/validations/numericality_validation_test.rb
浏览文件 @
a5922f13
...
...
@@ -20,7 +20,7 @@ def teardown
INTEGER_STRINGS
=
%w(0 +0 -0 10 +10 -10 0090 -090)
FLOATS
=
[
0.0
,
10.0
,
10.5
,
-
10.5
,
-
0.0001
]
+
FLOAT_STRINGS
INTEGERS
=
[
0
,
10
,
-
10
]
+
INTEGER_STRINGS
BIGDECIMAL
=
BIGDECIMAL_STRINGS
.
collect!
{
|
bd
|
BigDecimal
.
new
(
bd
)
}
BIGDECIMAL
=
BIGDECIMAL_STRINGS
.
collect!
{
|
bd
|
BigDecimal
(
bd
)
}
JUNK
=
[
"not a number"
,
"42 not a number"
,
"0xdeadbeef"
,
"0xinvalidhex"
,
"0Xdeadbeef"
,
"00-1"
,
"--3"
,
"+-3"
,
"+3-1"
,
"-+019.0"
,
"12.12.13.12"
,
"123
\n
not a number"
]
INFINITY
=
[
1.0
/
0.0
]
...
...
@@ -81,10 +81,10 @@ def test_validates_numericality_with_greater_than
end
def
test_validates_numericality_with_greater_than_using_differing_numeric_types
Topic
.
validates_numericality_of
:approved
,
greater_than:
BigDecimal
.
new
(
"97.18"
)
Topic
.
validates_numericality_of
:approved
,
greater_than:
BigDecimal
(
"97.18"
)
invalid!
([
-
97.18
,
BigDecimal
.
new
(
"97.18"
),
BigDecimal
(
"-97.18"
)],
"must be greater than 97.18"
)
valid!
([
97.19
,
98
,
BigDecimal
.
new
(
"98"
),
BigDecimal
.
new
(
"97.19"
)])
invalid!
([
-
97.18
,
BigDecimal
(
"97.18"
),
BigDecimal
(
"-97.18"
)],
"must be greater than 97.18"
)
valid!
([
97.19
,
98
,
BigDecimal
(
"98"
),
BigDecimal
(
"97.19"
)])
end
def
test_validates_numericality_with_greater_than_using_string_value
...
...
@@ -102,10 +102,10 @@ def test_validates_numericality_with_greater_than_or_equal
end
def
test_validates_numericality_with_greater_than_or_equal_using_differing_numeric_types
Topic
.
validates_numericality_of
:approved
,
greater_than_or_equal_to:
BigDecimal
.
new
(
"97.18"
)
Topic
.
validates_numericality_of
:approved
,
greater_than_or_equal_to:
BigDecimal
(
"97.18"
)
invalid!
([
-
97.18
,
97.17
,
97
,
BigDecimal
.
new
(
"97.17"
),
BigDecimal
.
new
(
"-97.18"
)],
"must be greater than or equal to 97.18"
)
valid!
([
97.18
,
98
,
BigDecimal
.
new
(
"97.19"
)])
invalid!
([
-
97.18
,
97.17
,
97
,
BigDecimal
(
"97.17"
),
BigDecimal
(
"-97.18"
)],
"must be greater than or equal to 97.18"
)
valid!
([
97.18
,
98
,
BigDecimal
(
"97.19"
)])
end
def
test_validates_numericality_with_greater_than_or_equal_using_string_value
...
...
@@ -123,10 +123,10 @@ def test_validates_numericality_with_equal_to
end
def
test_validates_numericality_with_equal_to_using_differing_numeric_types
Topic
.
validates_numericality_of
:approved
,
equal_to:
BigDecimal
.
new
(
"97.18"
)
Topic
.
validates_numericality_of
:approved
,
equal_to:
BigDecimal
(
"97.18"
)
invalid!
([
-
97.18
],
"must be equal to 97.18"
)
valid!
([
BigDecimal
.
new
(
"97.18"
)])
valid!
([
BigDecimal
(
"97.18"
)])
end
def
test_validates_numericality_with_equal_to_using_string_value
...
...
@@ -144,10 +144,10 @@ def test_validates_numericality_with_less_than
end
def
test_validates_numericality_with_less_than_using_differing_numeric_types
Topic
.
validates_numericality_of
:approved
,
less_than:
BigDecimal
.
new
(
"97.18"
)
Topic
.
validates_numericality_of
:approved
,
less_than:
BigDecimal
(
"97.18"
)
invalid!
([
97.18
,
BigDecimal
.
new
(
"97.18"
)],
"must be less than 97.18"
)
valid!
([
-
97.0
,
97.0
,
-
97
,
97
,
BigDecimal
.
new
(
"-97"
),
BigDecimal
.
new
(
"97"
)])
invalid!
([
97.18
,
BigDecimal
(
"97.18"
)],
"must be less than 97.18"
)
valid!
([
-
97.0
,
97.0
,
-
97
,
97
,
BigDecimal
(
"-97"
),
BigDecimal
(
"97"
)])
end
def
test_validates_numericality_with_less_than_using_string_value
...
...
@@ -165,10 +165,10 @@ def test_validates_numericality_with_less_than_or_equal_to
end
def
test_validates_numericality_with_less_than_or_equal_to_using_differing_numeric_types
Topic
.
validates_numericality_of
:approved
,
less_than_or_equal_to:
BigDecimal
.
new
(
"97.18"
)
Topic
.
validates_numericality_of
:approved
,
less_than_or_equal_to:
BigDecimal
(
"97.18"
)
invalid!
([
97.19
,
98
],
"must be less than or equal to 97.18"
)
valid!
([
-
97.18
,
BigDecimal
.
new
(
"-97.18"
),
BigDecimal
.
new
(
"97.18"
)])
valid!
([
-
97.18
,
BigDecimal
(
"-97.18"
),
BigDecimal
(
"97.18"
)])
end
def
test_validates_numericality_with_less_than_or_equal_using_string_value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录