Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ef172251
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,发现更多精彩内容 >>
提交
ef172251
编写于
1月 26, 2014
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consolidate JSON encoding tests in one file
上级
4cfc4675
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
46 deletion
+48
-46
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+0
-35
activesupport/test/json/encoding_test.rb
activesupport/test/json/encoding_test.rb
+48
-11
未找到文件。
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
ef172251
require
'abstract_unit'
require
'active_support/time'
require
'active_support/json'
class
TimeWithZoneTest
<
ActiveSupport
::
TestCase
...
...
@@ -66,33 +65,6 @@ def test_zone
assert_equal
'EDT'
,
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2000
,
6
),
@time_zone
).
zone
#dst
end
def
test_to_json_with_use_standard_json_time_format_config_set_to_false
with_standard_json_time_format
(
false
)
do
assert_equal
"
\"
1999/12/31 19:00:00 -0500
\"
"
,
ActiveSupport
::
JSON
.
encode
(
@twz
)
end
end
def
test_to_json_with_use_standard_json_time_format_config_set_to_true
with_standard_json_time_format
(
true
)
do
assert_equal
"
\"
1999-12-31T19:00:00.000-05:00
\"
"
,
ActiveSupport
::
JSON
.
encode
(
@twz
)
end
end
def
test_to_json_with_custom_subsecond_resolution
with_standard_json_time_format
(
true
)
do
ActiveSupport
::
JSON
::
Encoding
.
subsecond_fraction_digits
=
0
assert_equal
"
\"
1999-12-31T19:00:00-05:00
\"
"
,
ActiveSupport
::
JSON
.
encode
(
@twz
)
end
ensure
ActiveSupport
::
JSON
::
Encoding
.
subsecond_fraction_digits
=
nil
end
def
test_to_json_when_wrapping_a_date_time
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
DateTime
.
civil
(
2000
),
@time_zone
)
assert_equal
'"1999-12-31T19:00:00.000-05:00"'
,
ActiveSupport
::
JSON
.
encode
(
twz
)
end
def
test_nsec
local
=
Time
.
local
(
2011
,
6
,
7
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
))
with_zone
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
ActiveSupport
::
TimeZone
[
"Hawaii"
],
local
)
...
...
@@ -822,13 +794,6 @@ def with_env_tz(new_tz = 'US/Eastern')
ensure
old_tz
?
ENV
[
'TZ'
]
=
old_tz
:
ENV
.
delete
(
'TZ'
)
end
def
with_standard_json_time_format
(
boolean
=
true
)
old
,
ActiveSupport
.
use_standard_json_time_format
=
ActiveSupport
.
use_standard_json_time_format
,
boolean
yield
ensure
ActiveSupport
.
use_standard_json_time_format
=
old
end
end
class
TimeWithZoneMethodsForTimeAndDateTimeTest
<
ActiveSupport
::
TestCase
...
...
activesupport/test/json/encoding_test.rb
浏览文件 @
ef172251
...
...
@@ -3,6 +3,7 @@
require
'abstract_unit'
require
'active_support/core_ext/string/inflections'
require
'active_support/json'
require
'active_support/time'
class
TestJSONEncoding
<
ActiveSupport
::
TestCase
class
Foo
...
...
@@ -226,21 +227,17 @@ def test_hash_should_allow_key_filtering_with_except
end
def
test_time_to_json_includes_local_offset
prev
=
ActiveSupport
.
use_standard_json_time_format
ActiveSupport
.
use_standard_json_time_format
=
true
with_env_tz
'US/Eastern'
do
assert_equal
%("2005-02-01T15:15:10.000-05:00")
,
ActiveSupport
::
JSON
.
encode
(
Time
.
local
(
2005
,
2
,
1
,
15
,
15
,
10
))
with_standard_json_time_format
(
true
)
do
with_env_tz
'US/Eastern'
do
assert_equal
%("2005-02-01T15:15:10.000-05:00")
,
ActiveSupport
::
JSON
.
encode
(
Time
.
local
(
2005
,
2
,
1
,
15
,
15
,
10
))
end
end
ensure
ActiveSupport
.
use_standard_json_time_format
=
prev
end
def
test_hash_with_time_to_json
prev
=
ActiveSupport
.
use_standard_json_time_format
ActiveSupport
.
use_standard_json_time_format
=
false
assert_equal
'{"time":"2009/01/01 00:00:00 +0000"}'
,
{
:time
=>
Time
.
utc
(
2009
)
}.
to_json
ensure
ActiveSupport
.
use_standard_json_time_format
=
prev
with_standard_json_time_format
(
false
)
do
assert_equal
'{"time":"2009/01/01 00:00:00 +0000"}'
,
{
:time
=>
Time
.
utc
(
2009
)
}.
to_json
end
end
def
test_nested_hash_with_float
...
...
@@ -453,6 +450,39 @@ def test_json_gem_pretty_generate_by_passing_active_support_encoder
assert_nil
h
.
as_json_called
end
def
test_twz_to_json_with_use_standard_json_time_format_config_set_to_false
with_standard_json_time_format
(
false
)
do
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
time
=
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2000
),
zone
)
assert_equal
"
\"
1999/12/31 19:00:00 -0500
\"
"
,
ActiveSupport
::
JSON
.
encode
(
time
)
end
end
def
test_twz_to_json_with_use_standard_json_time_format_config_set_to_true
with_standard_json_time_format
(
true
)
do
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
time
=
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2000
),
zone
)
assert_equal
"
\"
1999-12-31T19:00:00.000-05:00
\"
"
,
ActiveSupport
::
JSON
.
encode
(
time
)
end
end
def
test_twz_to_json_with_custom_subsecond_resolution
with_standard_json_time_format
(
true
)
do
ActiveSupport
::
JSON
::
Encoding
.
subsecond_fraction_digits
=
0
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
time
=
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2000
),
zone
)
assert_equal
"
\"
1999-12-31T19:00:00-05:00
\"
"
,
ActiveSupport
::
JSON
.
encode
(
time
)
end
ensure
ActiveSupport
::
JSON
::
Encoding
.
subsecond_fraction_digits
=
nil
end
def
test_twz_to_json_when_wrapping_a_date_time
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
time
=
ActiveSupport
::
TimeWithZone
.
new
(
DateTime
.
new
(
2000
),
zone
)
assert_equal
'"1999-12-31T19:00:00.000-05:00"'
,
ActiveSupport
::
JSON
.
encode
(
time
)
end
protected
def
object_keys
(
json_object
)
...
...
@@ -465,4 +495,11 @@ def with_env_tz(new_tz = 'US/Eastern')
ensure
old_tz
?
ENV
[
'TZ'
]
=
old_tz
:
ENV
.
delete
(
'TZ'
)
end
def
with_standard_json_time_format
(
boolean
=
true
)
old
,
ActiveSupport
.
use_standard_json_time_format
=
ActiveSupport
.
use_standard_json_time_format
,
boolean
yield
ensure
ActiveSupport
.
use_standard_json_time_format
=
old
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录