Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d7add535
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,发现更多精彩内容 >>
提交
d7add535
编写于
9月 02, 2014
作者:
A
Abdelkader Boudih
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ActiveJob] TestCase (Will squash before merge)
上级
fccf3d0b
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
31 addition
and
31 deletion
+31
-31
activejob/lib/active_job/queue_adapters/test_adapter.rb
activejob/lib/active_job/queue_adapters/test_adapter.rb
+12
-12
activejob/lib/active_job/test_case.rb
activejob/lib/active_job/test_case.rb
+1
-2
activejob/lib/active_job/test_helper.rb
activejob/lib/active_job/test_helper.rb
+16
-13
activejob/test/cases/test_case_test.rb
activejob/test/cases/test_case_test.rb
+0
-1
activejob/test/cases/test_helper_test.rb
activejob/test/cases/test_helper_test.rb
+2
-3
未找到文件。
activejob/lib/active_job/queue_adapters/test_adapter.rb
浏览文件 @
d7add535
...
...
@@ -6,10 +6,10 @@ class TestAdapter
# Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
def
enqueued_jobs
@
@
enqueued_jobs
||=
[]
@enqueued_jobs
||=
[]
end
# Allows you to over
write the default enqueued jobs store from an array to some
# Allows you to overwrite the default enqueued jobs store from an array to some
# other object. If you just want to clear the store,
# call ActiveJob::QueueAdapters::TestAdapter.enqueued_jobs.clear.
#
...
...
@@ -21,15 +21,15 @@ def enqueued_jobs
# * size
# * and other common Array methods
def
enqueued_jobs
=
(
val
)
@
@
enqueued_jobs
=
val
@enqueued_jobs
=
val
end
# Provides a store of all the performed jobs with the TestAdapter so you can check them.
def
performed_jobs
@
@
performed_jobs
||=
[]
@performed_jobs
||=
[]
end
# Allows you to over
write the default performed jobs store from an array to some
# Allows you to overwrite the default performed jobs store from an array to some
# other object. If you just want to clear the store,
# call ActiveJob::QueueAdapters::TestAdapter.performed_jobs.clear.
#
...
...
@@ -41,7 +41,7 @@ def performed_jobs
# * size
# * and other common Array methods
def
performed_jobs
=
(
val
)
@
@
performed_jobs
=
val
@performed_jobs
=
val
end
def
enqueue
(
job
,
*
args
)
...
...
activejob/lib/active_job/test_case.rb
浏览文件 @
d7add535
# encoding: utf-8
require
'active_support/test_case'
module
ActiveJob
...
...
activejob/lib/active_job/test_helper.rb
浏览文件 @
d7add535
# encoding: utf-8
module
ActiveJob
# Provides helper methods for testing Active Job
module
TestHelper
extend
ActiveSupport
::
Concern
include
ActiveSupport
::
Testing
::
ConstantLookup
included
do
class_attribute
:_job_class
setup
:initialize_queue_test_adapter
def
before_setup
@old_queue_adapter
=
queue_adapter
ActiveJob
::
Base
.
queue_adapter
=
:test
clear_enqueued_jobs
clear_performed_jobs
super
end
def
after_teardown
super
ActiveJob
::
Base
.
queue_adapter
=
@old_queue_adapter
end
# Asserts that the number of enqueued jobs matches the given number.
#
...
...
@@ -40,7 +48,8 @@ def assert_enqueued_jobs(number)
assert_equal
original_count
+
number
,
new_count
,
"
#{
number
}
jobs expected, but
#{
new_count
-
original_count
}
were enqueued"
else
assert_equal
number
,
enqueued_jobs
.
size
enqueued_jobs_size
=
enqueued_jobs
.
size
assert_equal
number
,
enqueued_jobs_size
,
"
#{
number
}
jobs expected, but
#{
enqueued_jobs_size
}
were enqueued"
end
end
...
...
@@ -98,7 +107,8 @@ def assert_performed_jobs(number)
assert_equal
original_count
+
number
,
new_count
,
"
#{
number
}
jobs expected, but
#{
new_count
-
original_count
}
were performed"
else
assert_equal
number
,
performed_jobs
.
size
performed_jobs_size
=
performed_jobs
.
size
assert_equal
number
,
performed_jobs_size
,
"
#{
number
}
jobs expected, but
#{
performed_jobs_size
}
were performed"
end
end
...
...
@@ -165,7 +175,6 @@ def assert_performed_with(args = {}, &_block)
queue_adapter
.
performed_jobs
=
original_performed_jobs
+
performed_jobs
end
def
queue_adapter
ActiveJob
::
Base
.
queue_adapter
end
...
...
@@ -175,12 +184,6 @@ def queue_adapter
to: :queue_adapter
private
def
initialize_queue_test_adapter
ActiveJob
::
Base
.
queue_adapter
=
:test
clear_enqueued_jobs
clear_performed_jobs
end
def
clear_enqueued_jobs
enqueued_jobs
.
clear
end
...
...
activejob/test/cases/test_case_test.rb
浏览文件 @
d7add535
# encoding: utf-8
require
'helper'
require
'jobs/hello_job'
require
'jobs/logging_job'
...
...
activejob/test/cases/test_helper_test.rb
浏览文件 @
d7add535
# encoding: utf-8
require
'helper'
require
'active_support/core_ext/time'
require
'active_support/core_ext/date'
...
...
@@ -74,7 +73,7 @@ def test_assert_enqueued_jobs_too_many_sent
assert_match
(
/1 .* but 2/
,
error
.
message
)
end
#
def
test_assert_no_enqueued_jobs_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_enqueued_jobs
do
...
...
@@ -182,7 +181,7 @@ def test_assert_performed_jobs_too_many_sent
assert_match
(
/1 .* but 2/
,
error
.
message
)
end
#
def
test_assert_no_performed_jobs_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录