Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
74fabdf6
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,发现更多精彩内容 >>
提交
74fabdf6
编写于
1月 25, 2012
作者:
C
Carlos Antonio da Silva
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not mutate given options hash in number helpers
上级
c753e3af
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
32 addition
and
9 deletion
+32
-9
actionpack/lib/action_view/helpers/number_helper.rb
actionpack/lib/action_view/helpers/number_helper.rb
+7
-9
actionpack/test/template/number_helper_test.rb
actionpack/test/template/number_helper_test.rb
+25
-0
未找到文件。
actionpack/lib/action_view/helpers/number_helper.rb
浏览文件 @
74fabdf6
...
...
@@ -57,7 +57,7 @@ def initialize(number)
# # => +1.123.555.1234 x 1343
def
number_to_phone
(
number
,
options
=
{})
return
unless
number
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
parse_float
(
number
,
true
)
if
options
[
:raise
]
...
...
@@ -118,8 +118,7 @@ def number_to_phone(number, options = {})
# # => 1234567890,50 £
def
number_to_currency
(
number
,
options
=
{})
return
unless
number
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
currency
=
translations_for
(
'currency'
,
options
[
:locale
])
currency
[
:negative_format
]
||=
"-"
+
currency
[
:format
]
if
currency
[
:format
]
...
...
@@ -181,8 +180,7 @@ def number_to_currency(number, options = {})
# number_to_percentage("98a", :raise => true) # => InvalidNumberError
def
number_to_percentage
(
number
,
options
=
{})
return
unless
number
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
defaults
=
format_translations
(
'percentage'
,
options
[
:locale
])
options
=
defaults
.
merge!
(
options
)
...
...
@@ -227,7 +225,7 @@ def number_to_percentage(number, options = {})
#
# number_with_delimiter("112a", :raise => true) # => raise InvalidNumberError
def
number_with_delimiter
(
number
,
options
=
{})
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
parse_float
(
number
,
options
[
:raise
])
or
return
number
...
...
@@ -271,7 +269,7 @@ def number_with_delimiter(number, options = {})
# number_with_precision(1111.2345, :precision => 2, :separator => ',', :delimiter => '.')
# # => 1.111,23
def
number_with_precision
(
number
,
options
=
{})
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
number
=
(
parse_float
(
number
,
options
[
:raise
])
or
return
number
)
...
...
@@ -338,7 +336,7 @@ def number_with_precision(number, options = {})
# number_to_human_size(1234567890123, :precision => 5) # => "1.1229 TB"
# number_to_human_size(524288000, :precision => 5) # => "500 MB"
def
number_to_human_size
(
number
,
options
=
{})
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
number
=
(
parse_float
(
number
,
options
[
:raise
])
or
return
number
)
...
...
@@ -448,7 +446,7 @@ def number_to_human_size(number, options = {})
# number_to_human(0.34, :units => :distance) # => "34 centimeters"
#
def
number_to_human
(
number
,
options
=
{})
options
.
symbolize_keys!
options
=
options
.
symbolize_keys
number
=
(
parse_float
(
number
,
options
[
:raise
])
or
return
number
)
...
...
actionpack/test/template/number_helper_test.rb
浏览文件 @
74fabdf6
...
...
@@ -268,6 +268,31 @@ def test_number_helpers_should_return_nil_when_given_nil
assert_nil
number_to_human
(
nil
)
end
def
test_number_helpers_do_not_mutate_options_hash
options
=
{
'raise'
=>
true
}
number_to_phone
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
number_to_currency
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
number_to_percentage
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
number_with_delimiter
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
number_with_precision
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
number_to_human_size
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
number_to_human
(
1
,
options
)
assert_equal
({
'raise'
=>
true
},
options
)
end
def
test_number_helpers_should_return_non_numeric_param_unchanged
assert_equal
(
"+1-x x 123"
,
number_to_phone
(
"x"
,
:country_code
=>
1
,
:extension
=>
123
))
assert_equal
(
"x"
,
number_to_phone
(
"x"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录