Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
aa457920
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 搜索 >>
未验证
提交
aa457920
编写于
11月 10, 2019
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #37496
Closes #37496
上级
ba8f380f
21f907bb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
0 deletion
+51
-0
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+4
-0
activesupport/lib/active_support/testing/time_helpers.rb
activesupport/lib/active_support/testing/time_helpers.rb
+24
-0
activesupport/test/time_travel_test.rb
activesupport/test/time_travel_test.rb
+23
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
aa457920
*
Add block support to
`ActiveSupport::Testing::TimeHelpers#travel_back`
.
*Tim Masliuchenko*
*
Update
`ActiveSupport::Messages::Metadata#fresh?`
to work for cookies with expiry set when
`ActiveSupport.parse_json_times = true`
.
...
...
activesupport/lib/active_support/testing/time_helpers.rb
浏览文件 @
aa457920
...
...
@@ -39,6 +39,10 @@ def stubbing(object, method_name)
@stubs
[
object
.
object_id
][
method_name
]
end
def
stubbed?
!
@stubs
.
empty?
end
private
def
unstub_object
(
stub
)
singleton_class
=
stub
.
object
.
singleton_class
...
...
@@ -160,12 +164,32 @@ def travel_to(date_or_time)
# +travel+, +travel_to+, and +freeze_time+.
#
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
#
# travel_to Time.zone.local(2004, 11, 24, 01, 04, 44)
# Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
#
# travel_back
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
#
# This method also accepts a block, which brings the stubs back at the end of the block:
#
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
#
# travel_to Time.zone.local(2004, 11, 24, 01, 04, 44)
# Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
#
# travel_back do
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
# end
#
# Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
def
travel_back
stubbed_time
=
Time
.
current
if
block_given?
&&
simple_stubs
.
stubbed?
simple_stubs
.
unstub_all!
yield
if
block_given?
ensure
travel_to
stubbed_time
if
stubbed_time
end
alias_method
:unfreeze_time
,
:travel_back
...
...
activesupport/test/time_travel_test.rb
浏览文件 @
aa457920
...
...
@@ -102,6 +102,29 @@ def test_time_helper_travel_back
end
end
def
test_time_helper_travel_back_with_block
Time
.
stub
(
:now
,
Time
.
now
)
do
expected_time
=
Time
.
new
(
2004
,
11
,
24
,
01
,
04
,
44
)
travel_to
expected_time
assert_equal
expected_time
,
Time
.
now
assert_equal
Date
.
new
(
2004
,
11
,
24
),
Date
.
today
assert_equal
expected_time
.
to_datetime
,
DateTime
.
now
travel_back
do
assert_not_equal
expected_time
,
Time
.
now
assert_not_equal
Date
.
new
(
2004
,
11
,
24
),
Date
.
today
assert_not_equal
expected_time
.
to_datetime
,
DateTime
.
now
end
assert_equal
expected_time
,
Time
.
now
assert_equal
Date
.
new
(
2004
,
11
,
24
),
Date
.
today
assert_equal
expected_time
.
to_datetime
,
DateTime
.
now
ensure
travel_back
end
end
def
test_time_helper_travel_to_with_nested_calls_with_blocks
Time
.
stub
(
:now
,
Time
.
now
)
do
outer_expected_time
=
Time
.
new
(
2004
,
11
,
24
,
01
,
04
,
44
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录