Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2b594b06
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,发现更多精彩内容 >>
未验证
提交
2b594b06
编写于
8月 20, 2018
作者:
J
Jeremy Daer
提交者:
GitHub
8月 20, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #33635 from bogdanvlviv/improve-active_job-test_helpers
Improve Active Job test helpers
上级
96cd16bd
b8576425
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
726 addition
and
61 deletion
+726
-61
activejob/CHANGELOG.md
activejob/CHANGELOG.md
+13
-13
activejob/lib/active_job/queue_adapters/test_adapter.rb
activejob/lib/active_job/queue_adapters/test_adapter.rb
+11
-3
activejob/lib/active_job/test_helper.rb
activejob/lib/active_job/test_helper.rb
+114
-33
activejob/test/cases/test_helper_test.rb
activejob/test/cases/test_helper_test.rb
+588
-12
未找到文件。
activejob/CHANGELOG.md
浏览文件 @
2b594b06
*
Allow
`assert_performed_with`
to be called without a block.
*bogdanvlviv*
*
Execution of
`assert_performed_jobs`
, and
`assert_no_performed_jobs`
without a block should respect passed
`:except`
,
`:only`
, and
`:queue`
options.
*bogdanvlviv*
*
Allow
`:queue`
option to job assertions and helpers.
*bogdanvlviv*
*
Allow
`perform_enqueued_jobs`
to be called without a block.
*
Allow
`perform_enqueued_jobs`
to be called without a block.
Performs all of the jobs that have been enqueued up to this point in the test.
Performs all of the jobs that have been enqueued up to this point in the test.
...
@@ -11,19 +24,6 @@
...
@@ -11,19 +24,6 @@
*Zach Kemp*
*Zach Kemp*
*
Allow
`queue`
option to
`assert_no_enqueued_jobs`
.
Example:
```
def test_no_logging
assert_no_enqueued_jobs queue: 'default' do
LoggingJob.set(queue: :some_queue).perform_later
end
end
```
*bogdanvlviv*
*
Allow call
`assert_enqueued_with`
with no block.
*
Allow call
`assert_enqueued_with`
with no block.
Example:
Example:
...
...
activejob/lib/active_job/queue_adapters/test_adapter.rb
浏览文件 @
2b594b06
...
@@ -12,7 +12,7 @@ module QueueAdapters
...
@@ -12,7 +12,7 @@ module QueueAdapters
#
#
# Rails.application.config.active_job.queue_adapter = :test
# Rails.application.config.active_job.queue_adapter = :test
class
TestAdapter
class
TestAdapter
attr_accessor
(
:perform_enqueued_jobs
,
:perform_enqueued_at_jobs
,
:filter
,
:reject
)
attr_accessor
(
:perform_enqueued_jobs
,
:perform_enqueued_at_jobs
,
:filter
,
:reject
,
:queue
)
attr_writer
(
:enqueued_jobs
,
:performed_jobs
)
attr_writer
(
:enqueued_jobs
,
:performed_jobs
)
# Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
# Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
...
@@ -54,12 +54,20 @@ def perform_or_enqueue(perform, job, job_data)
...
@@ -54,12 +54,20 @@ def perform_or_enqueue(perform, job, job_data)
end
end
def
filtered?
(
job
)
def
filtered?
(
job
)
filtered_queue?
(
job
)
||
filtered_job_class?
(
job
)
end
def
filtered_queue?
(
job
)
if
queue
job
.
queue_name
!=
queue
.
to_s
end
end
def
filtered_job_class?
(
job
)
if
filter
if
filter
!
Array
(
filter
).
include?
(
job
.
class
)
!
Array
(
filter
).
include?
(
job
.
class
)
elsif
reject
elsif
reject
Array
(
reject
).
include?
(
job
.
class
)
Array
(
reject
).
include?
(
job
.
class
)
else
false
end
end
end
end
end
end
...
...
activejob/lib/active_job/test_helper.rb
浏览文件 @
2b594b06
...
@@ -52,7 +52,7 @@ def after_teardown # :nodoc:
...
@@ -52,7 +52,7 @@ def after_teardown # :nodoc:
queue_adapter_changed_jobs
.
each
{
|
klass
|
klass
.
disable_test_adapter
}
queue_adapter_changed_jobs
.
each
{
|
klass
|
klass
.
disable_test_adapter
}
end
end
# Specifies the queue adapter to use with all
active j
ob test helpers.
# Specifies the queue adapter to use with all
Active J
ob test helpers.
#
#
# Returns an instance of the queue adapter and defaults to
# Returns an instance of the queue adapter and defaults to
# <tt>ActiveJob::QueueAdapters::TestAdapter</tt>.
# <tt>ActiveJob::QueueAdapters::TestAdapter</tt>.
...
@@ -118,13 +118,17 @@ def queue_adapter_for_test
...
@@ -118,13 +118,17 @@ def queue_adapter_for_test
def
assert_enqueued_jobs
(
number
,
only:
nil
,
except:
nil
,
queue:
nil
)
def
assert_enqueued_jobs
(
number
,
only:
nil
,
except:
nil
,
queue:
nil
)
if
block_given?
if
block_given?
original_count
=
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
original_count
=
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
yield
yield
new_count
=
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
new_count
=
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
assert_equal
number
,
new_count
-
original_count
,
"
#{
number
}
jobs expected, but
#{
new_count
-
original_count
}
were enqueued"
actual_count
=
new_count
-
original_count
else
else
actual_count
=
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
actual_count
=
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
assert_equal
number
,
actual_count
,
"
#{
number
}
jobs expected, but
#{
actual_count
}
were enqueued"
end
end
assert_equal
number
,
actual_count
,
"
#{
number
}
jobs expected, but
#{
actual_count
}
were enqueued"
end
end
# Asserts that no jobs have been enqueued.
# Asserts that no jobs have been enqueued.
...
@@ -176,7 +180,7 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
...
@@ -176,7 +180,7 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
# Asserts that the number of performed jobs matches the given number.
# Asserts that the number of performed jobs matches the given number.
# If no block is passed, <tt>perform_enqueued_jobs</tt>
# If no block is passed, <tt>perform_enqueued_jobs</tt>
# must be called around the job call.
# must be called around
or after
the job call.
#
#
# def test_jobs
# def test_jobs
# assert_performed_jobs 0
# assert_performed_jobs 0
...
@@ -186,10 +190,11 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
...
@@ -186,10 +190,11 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
# end
# end
# assert_performed_jobs 1
# assert_performed_jobs 1
#
#
# perform_enqueued_jobs do
# HelloJob.perform_later('yves')
# HelloJob.perform_later('yves')
#
# assert_performed_jobs 2
# perform_enqueued_jobs
# end
#
# assert_performed_jobs 2
# end
# end
#
#
# If a block is passed, that block should cause the specified number of
# If a block is passed, that block should cause the specified number of
...
@@ -206,7 +211,7 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
...
@@ -206,7 +211,7 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
# end
# end
# end
# end
#
#
# Th
e block form supports filtering. If the :only
option is specified,
# Th
is method also supports filtering. If the +:only+
option is specified,
# then only the listed job(s) will be performed.
# then only the listed job(s) will be performed.
#
#
# def test_hello_job
# def test_hello_job
...
@@ -216,7 +221,7 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
...
@@ -216,7 +221,7 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
# end
# end
# end
# end
#
#
# Also if the
:except
option is specified,
# Also if the
+:except+
option is specified,
# then the job(s) except specific class will be performed.
# then the job(s) except specific class will be performed.
#
#
# def test_hello_job
# def test_hello_job
...
@@ -237,17 +242,30 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
...
@@ -237,17 +242,30 @@ def assert_no_enqueued_jobs(only: nil, except: nil, queue: nil, &block)
# end
# end
# end
# end
# end
# end
def
assert_performed_jobs
(
number
,
only:
nil
,
except:
nil
)
#
# If the +:queue+ option is specified,
# then only the job(s) enqueued to a specific queue will be performed.
#
# def test_assert_performed_jobs_with_queue_option
# assert_performed_jobs 1, queue: :some_queue do
# HelloJob.set(queue: :some_queue).perform_later("jeremy")
# HelloJob.set(queue: :other_queue).perform_later("bogdan")
# end
# end
def
assert_performed_jobs
(
number
,
only:
nil
,
except:
nil
,
queue:
nil
,
&
block
)
if
block_given?
if
block_given?
original_count
=
performed_jobs
.
size
original_count
=
performed_jobs
.
size
perform_enqueued_jobs
(
only:
only
,
except:
except
)
{
yield
}
perform_enqueued_jobs
(
only:
only
,
except:
except
,
queue:
queue
,
&
block
)
new_count
=
performed_jobs
.
size
new_count
=
performed_jobs
.
size
assert_equal
number
,
new_count
-
original_count
,
"
#{
number
}
jobs expected, but
#{
new_count
-
original_count
}
were performed"
performed_jobs_size
=
new_count
-
original_count
else
else
performed_jobs_size
=
performed_jobs
.
size
performed_jobs_size
=
performed_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
assert_equal
number
,
performed_jobs_size
,
"
#{
number
}
jobs expected, but
#{
performed_jobs_size
}
were performed"
end
end
assert_equal
number
,
performed_jobs_size
,
"
#{
number
}
jobs expected, but
#{
performed_jobs_size
}
were performed"
end
end
# Asserts that no jobs have been performed.
# Asserts that no jobs have been performed.
...
@@ -269,7 +287,7 @@ def assert_performed_jobs(number, only: nil, except: nil)
...
@@ -269,7 +287,7 @@ def assert_performed_jobs(number, only: nil, except: nil)
# end
# end
# end
# end
#
#
# The block form supports filtering. If the
:only
option is specified,
# The block form supports filtering. If the
+:only+
option is specified,
# then only the listed job(s) will not be performed.
# then only the listed job(s) will not be performed.
#
#
# def test_no_logging
# def test_no_logging
...
@@ -278,7 +296,7 @@ def assert_performed_jobs(number, only: nil, except: nil)
...
@@ -278,7 +296,7 @@ def assert_performed_jobs(number, only: nil, except: nil)
# end
# end
# end
# end
#
#
# Also if the
:except
option is specified,
# Also if the
+:except+
option is specified,
# then the job(s) except specific class will not be performed.
# then the job(s) except specific class will not be performed.
#
#
# def test_no_logging
# def test_no_logging
...
@@ -287,11 +305,20 @@ def assert_performed_jobs(number, only: nil, except: nil)
...
@@ -287,11 +305,20 @@ def assert_performed_jobs(number, only: nil, except: nil)
# end
# end
# end
# end
#
#
# If the +:queue+ option is specified,
# then only the job(s) enqueued to a specific queue will not be performed.
#
# def test_assert_no_performed_jobs_with_queue_option
# assert_no_performed_jobs queue: :some_queue do
# HelloJob.set(queue: :other_queue).perform_later("jeremy")
# end
# end
#
# Note: This assertion is simply a shortcut for:
# Note: This assertion is simply a shortcut for:
#
#
# assert_performed_jobs 0, &block
# assert_performed_jobs 0, &block
def
assert_no_performed_jobs
(
only:
nil
,
except:
nil
,
&
block
)
def
assert_no_performed_jobs
(
only:
nil
,
except:
nil
,
queue:
nil
,
&
block
)
assert_performed_jobs
0
,
only:
only
,
except:
except
,
&
block
assert_performed_jobs
0
,
only:
only
,
except:
except
,
queue:
queue
,
&
block
end
end
# Asserts that the job has been enqueued with the given arguments.
# Asserts that the job has been enqueued with the given arguments.
...
@@ -338,7 +365,25 @@ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
...
@@ -338,7 +365,25 @@ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
instantiate_job
(
matching_job
)
instantiate_job
(
matching_job
)
end
end
# Asserts that the job passed in the block has been performed with the given arguments.
# Asserts that the job has been performed with the given arguments.
#
# def test_assert_performed_with
# MyJob.perform_later(1,2,3)
#
# perform_enqueued_jobs
#
# assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high')
#
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
#
# perform_enqueued_jobs
#
# assert_performed_with(job: MyJob, at: Date.tomorrow.noon)
# end
#
# If a block is passed, that block performs all of the jobs that were
# enqueued throughout the duration of the block and asserts that
# the job has been performed with the given arguments in the block.
#
#
# def test_assert_performed_with
# def test_assert_performed_with
# assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') do
# assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') do
...
@@ -349,15 +394,24 @@ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
...
@@ -349,15 +394,24 @@ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# MyJob.set(wait_until: Date.tomorrow.noon).perform_later
# end
# end
# end
# end
def
assert_performed_with
(
job:
nil
,
args:
nil
,
at:
nil
,
queue:
nil
)
def
assert_performed_with
(
job:
nil
,
args:
nil
,
at:
nil
,
queue:
nil
,
&
block
)
original_performed_jobs_count
=
performed_jobs
.
count
expected
=
{
job:
job
,
args:
args
,
at:
at
,
queue:
queue
}.
compact
expected
=
{
job:
job
,
args:
args
,
at:
at
,
queue:
queue
}.
compact
serialized_args
=
serialize_args_for_assertion
(
expected
)
serialized_args
=
serialize_args_for_assertion
(
expected
)
perform_enqueued_jobs
{
yield
}
in_block_jobs
=
performed_jobs
.
drop
(
original_performed_jobs_count
)
if
block_given?
matching_job
=
in_block_jobs
.
find
do
|
in_block_job
|
original_performed_jobs_count
=
performed_jobs
.
count
serialized_args
.
all?
{
|
key
,
value
|
value
==
in_block_job
[
key
]
}
perform_enqueued_jobs
(
&
block
)
jobs
=
performed_jobs
.
drop
(
original_performed_jobs_count
)
else
jobs
=
performed_jobs
end
end
matching_job
=
jobs
.
find
do
|
performed_job
|
serialized_args
.
all?
{
|
key
,
value
|
value
==
performed_job
[
key
]
}
end
assert
matching_job
,
"No performed job found with
#{
expected
}
"
assert
matching_job
,
"No performed job found with
#{
expected
}
"
instantiate_job
(
matching_job
)
instantiate_job
(
matching_job
)
end
end
...
@@ -403,25 +457,42 @@ def assert_performed_with(job: nil, args: nil, at: nil, queue: nil)
...
@@ -403,25 +457,42 @@ def assert_performed_with(job: nil, args: nil, at: nil, queue: nil)
# assert_performed_jobs 1
# assert_performed_jobs 1
# end
# end
#
#
def
perform_enqueued_jobs
(
only:
nil
,
except:
nil
)
# If the +:queue+ option is specified,
# then only the job(s) enqueued to a specific queue will be performed.
#
# def test_perform_enqueued_jobs_with_queue
# perform_enqueued_jobs queue: :some_queue do
# MyJob.set(queue: :some_queue).perform_later(1, 2, 3) # will be performed
# HelloJob.set(queue: :other_queue).perform_later(1, 2, 3) # will not be performed
# end
# assert_performed_jobs 1
# end
#
def
perform_enqueued_jobs
(
only:
nil
,
except:
nil
,
queue:
nil
)
return
flush_enqueued_jobs
(
only:
only
,
except:
except
,
queue:
queue
)
unless
block_given?
validate_option
(
only:
only
,
except:
except
)
validate_option
(
only:
only
,
except:
except
)
old_perform_enqueued_jobs
=
queue_adapter
.
perform_enqueued_jobs
old_perform_enqueued_jobs
=
queue_adapter
.
perform_enqueued_jobs
old_perform_enqueued_at_jobs
=
queue_adapter
.
perform_enqueued_at_jobs
old_perform_enqueued_at_jobs
=
queue_adapter
.
perform_enqueued_at_jobs
old_filter
=
queue_adapter
.
filter
old_filter
=
queue_adapter
.
filter
old_reject
=
queue_adapter
.
reject
old_reject
=
queue_adapter
.
reject
old_queue
=
queue_adapter
.
queue
begin
begin
queue_adapter
.
perform_enqueued_jobs
=
true
queue_adapter
.
perform_enqueued_jobs
=
true
queue_adapter
.
perform_enqueued_at_jobs
=
true
queue_adapter
.
perform_enqueued_at_jobs
=
true
queue_adapter
.
filter
=
only
queue_adapter
.
filter
=
only
queue_adapter
.
reject
=
except
queue_adapter
.
reject
=
except
queue_adapter
.
queue
=
queue
block_given?
?
yield
:
flush_enqueued_jobs
(
only:
only
,
except:
except
)
yield
ensure
ensure
queue_adapter
.
perform_enqueued_jobs
=
old_perform_enqueued_jobs
queue_adapter
.
perform_enqueued_jobs
=
old_perform_enqueued_jobs
queue_adapter
.
perform_enqueued_at_jobs
=
old_perform_enqueued_at_jobs
queue_adapter
.
perform_enqueued_at_jobs
=
old_perform_enqueued_at_jobs
queue_adapter
.
filter
=
old_filter
queue_adapter
.
filter
=
old_filter
queue_adapter
.
reject
=
old_reject
queue_adapter
.
reject
=
old_reject
queue_adapter
.
queue
=
old_queue
end
end
end
end
...
@@ -443,10 +514,10 @@ def clear_performed_jobs
...
@@ -443,10 +514,10 @@ def clear_performed_jobs
performed_jobs
.
clear
performed_jobs
.
clear
end
end
def
enqueued_jobs_with
(
only:
nil
,
except:
nil
,
queue:
nil
)
def
jobs_with
(
jobs
,
only:
nil
,
except:
nil
,
queue:
nil
)
validate_option
(
only:
only
,
except:
except
)
validate_option
(
only:
only
,
except:
except
)
enqueued_
jobs
.
count
do
|
job
|
jobs
.
count
do
|
job
|
job_class
=
job
.
fetch
(
:job
)
job_class
=
job
.
fetch
(
:job
)
if
only
if
only
...
@@ -454,17 +525,27 @@ def enqueued_jobs_with(only: nil, except: nil, queue: nil)
...
@@ -454,17 +525,27 @@ def enqueued_jobs_with(only: nil, except: nil, queue: nil)
elsif
except
elsif
except
next
false
if
Array
(
except
).
include?
(
job_class
)
next
false
if
Array
(
except
).
include?
(
job_class
)
end
end
if
queue
if
queue
next
false
unless
queue
.
to_s
==
job
.
fetch
(
:queue
,
job_class
.
queue_name
)
next
false
unless
queue
.
to_s
==
job
.
fetch
(
:queue
,
job_class
.
queue_name
)
end
end
yield
job
if
block_given?
yield
job
if
block_given?
true
true
end
end
end
end
def
flush_enqueued_jobs
(
only:
nil
,
except:
nil
)
def
enqueued_jobs_with
(
only:
nil
,
except:
nil
,
queue:
nil
,
&
block
)
enqueued_jobs_with
(
only:
only
,
except:
except
)
do
|
payload
|
jobs_with
(
enqueued_jobs
,
only:
only
,
except:
except
,
queue:
queue
,
&
block
)
end
def
performed_jobs_with
(
only:
nil
,
except:
nil
,
queue:
nil
,
&
block
)
jobs_with
(
performed_jobs
,
only:
only
,
except:
except
,
queue:
queue
,
&
block
)
end
def
flush_enqueued_jobs
(
only:
nil
,
except:
nil
,
queue:
nil
)
enqueued_jobs_with
(
only:
only
,
except:
except
,
queue:
queue
)
do
|
payload
|
args
=
ActiveJob
::
Arguments
.
deserialize
(
payload
[
:args
])
args
=
ActiveJob
::
Arguments
.
deserialize
(
payload
[
:args
])
instantiate_job
(
payload
.
merge
(
args:
args
)).
perform_now
instantiate_job
(
payload
.
merge
(
args:
args
)).
perform_now
queue_adapter
.
performed_jobs
<<
payload
queue_adapter
.
performed_jobs
<<
payload
...
...
activejob/test/cases/test_helper_test.rb
浏览文件 @
2b594b06
...
@@ -618,6 +618,12 @@ def test_perform_enqueued_jobs_with_only_option_doesnt_leak_outside_the_block
...
@@ -618,6 +618,12 @@ def test_perform_enqueued_jobs_with_only_option_doesnt_leak_outside_the_block
assert_nil
queue_adapter
.
filter
assert_nil
queue_adapter
.
filter
end
end
def
test_perform_enqueued_jobs_without_block_with_only_option_doesnt_leak
perform_enqueued_jobs
only:
HelloJob
assert_nil
queue_adapter
.
filter
end
def
test_perform_enqueued_jobs_with_except_option_doesnt_leak_outside_the_block
def
test_perform_enqueued_jobs_with_except_option_doesnt_leak_outside_the_block
assert_nil
queue_adapter
.
reject
assert_nil
queue_adapter
.
reject
perform_enqueued_jobs
except:
HelloJob
do
perform_enqueued_jobs
except:
HelloJob
do
...
@@ -626,20 +632,148 @@ def test_perform_enqueued_jobs_with_except_option_doesnt_leak_outside_the_block
...
@@ -626,20 +632,148 @@ def test_perform_enqueued_jobs_with_except_option_doesnt_leak_outside_the_block
assert_nil
queue_adapter
.
reject
assert_nil
queue_adapter
.
reject
end
end
def
test_perform_enqueued_jobs_without_block_with_except_option_doesnt_leak
perform_enqueued_jobs
except:
HelloJob
assert_nil
queue_adapter
.
reject
end
def
test_perform_enqueued_jobs_with_queue_option_doesnt_leak_outside_the_block
assert_nil
queue_adapter
.
queue
perform_enqueued_jobs
queue: :some_queue
do
assert_equal
:some_queue
,
queue_adapter
.
queue
end
assert_nil
queue_adapter
.
queue
end
def
test_perform_enqueued_jobs_without_block_with_queue_option_doesnt_leak
perform_enqueued_jobs
queue: :some_queue
assert_nil
queue_adapter
.
reject
end
def
test_perform_enqueued_jobs_with_block
perform_enqueued_jobs
do
HelloJob
.
perform_later
(
"kevin"
)
LoggingJob
.
perform_later
(
"bogdan"
)
end
assert_performed_jobs
2
end
def
test_perform_enqueued_jobs_without_block
def
test_perform_enqueued_jobs_without_block
HelloJob
.
perform_later
(
"kevin"
)
HelloJob
.
perform_later
(
"kevin"
)
LoggingJob
.
perform_later
(
"bogdan"
)
assert_performed_jobs
1
,
only:
HelloJob
do
perform_enqueued_jobs
perform_enqueued_jobs
assert_performed_jobs
2
end
def
test_perform_enqueued_jobs_with_block_with_only_option
perform_enqueued_jobs
only:
LoggingJob
do
HelloJob
.
perform_later
(
"kevin"
)
LoggingJob
.
perform_later
(
"bogdan"
)
end
end
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
LoggingJob
end
end
def
test_perform_enqueued_jobs_without_block_
respects_filter
def
test_perform_enqueued_jobs_without_block_
with_only_option
HelloJob
.
perform_later
(
"kevin"
)
HelloJob
.
perform_later
(
"kevin"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
only:
LoggingJob
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
LoggingJob
end
def
test_perform_enqueued_jobs_with_block_with_except_option
perform_enqueued_jobs
except:
HelloJob
do
HelloJob
.
perform_later
(
"kevin"
)
LoggingJob
.
perform_later
(
"bogdan"
)
end
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
LoggingJob
end
def
test_perform_enqueued_jobs_without_block_with_except_option
HelloJob
.
perform_later
(
"kevin"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
except:
HelloJob
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
LoggingJob
end
def
test_perform_enqueued_jobs_with_block_with_queue_option
perform_enqueued_jobs
queue: :some_queue
do
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"kevin"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
perform_later
(
"bogdan"
)
end
assert_no_performed_jobs
do
assert_performed_jobs
1
perform_enqueued_jobs
only:
LoggingJob
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :some_queue
end
def
test_perform_enqueued_jobs_without_block_with_queue_option
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"kevin"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
queue: :some_queue
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :some_queue
end
def
test_perform_enqueued_jobs_with_block_with_only_and_queue_options
perform_enqueued_jobs
only:
HelloJob
,
queue: :other_queue
do
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"kevin"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
end
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :other_queue
end
def
test_perform_enqueued_jobs_without_block_with_only_and_queue_options
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"kevin"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
perform_enqueued_jobs
only:
HelloJob
,
queue: :other_queue
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :other_queue
end
def
test_perform_enqueued_jobs_with_block_with_except_and_queue_options
perform_enqueued_jobs
except:
HelloJob
,
queue: :other_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"kevin"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
end
end
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
LoggingJob
,
queue: :other_queue
end
def
test_perform_enqueued_jobs_without_block_with_except_and_queue_options
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"kevin"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
perform_enqueued_jobs
except:
HelloJob
,
queue: :other_queue
assert_performed_jobs
1
assert_performed_jobs
1
,
only:
LoggingJob
,
queue: :other_queue
end
end
def
test_assert_performed_jobs
def
test_assert_performed_jobs
...
@@ -747,6 +881,28 @@ def test_assert_performed_jobs_with_only_option
...
@@ -747,6 +881,28 @@ def test_assert_performed_jobs_with_only_option
end
end
end
end
def
test_assert_performed_jobs_without_block_with_only_option
HelloJob
.
perform_later
(
"jeremy"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
assert_performed_jobs
1
,
only:
HelloJob
end
def
test_assert_performed_jobs_without_block_with_only_option_failure
LoggingJob
.
perform_later
(
"jeremy"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
only:
HelloJob
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_with_except_option
def
test_assert_performed_jobs_with_except_option
assert_nothing_raised
do
assert_nothing_raised
do
assert_performed_jobs
1
,
except:
LoggingJob
do
assert_performed_jobs
1
,
except:
LoggingJob
do
...
@@ -756,6 +912,28 @@ def test_assert_performed_jobs_with_except_option
...
@@ -756,6 +912,28 @@ def test_assert_performed_jobs_with_except_option
end
end
end
end
def
test_assert_performed_jobs_without_block_with_except_option
HelloJob
.
perform_later
(
"jeremy"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
assert_performed_jobs
1
,
except:
HelloJob
end
def
test_assert_performed_jobs_without_block_with_except_option_failure
HelloJob
.
perform_later
(
"jeremy"
)
HelloJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
except:
HelloJob
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_with_only_and_except_option
def
test_assert_performed_jobs_with_only_and_except_option
error
=
assert_raise
ArgumentError
do
error
=
assert_raise
ArgumentError
do
assert_performed_jobs
1
,
only:
HelloJob
,
except:
HelloJob
do
assert_performed_jobs
1
,
only:
HelloJob
,
except:
HelloJob
do
...
@@ -767,6 +945,19 @@ def test_assert_performed_jobs_with_only_and_except_option
...
@@ -767,6 +945,19 @@ def test_assert_performed_jobs_with_only_and_except_option
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
end
end
def
test_assert_performed_jobs_without_block_with_only_and_except_options
error
=
assert_raise
ArgumentError
do
HelloJob
.
perform_later
(
"jeremy"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
assert_performed_jobs
1
,
only:
HelloJob
,
except:
HelloJob
end
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
end
def
test_assert_performed_jobs_with_only_option_as_array
def
test_assert_performed_jobs_with_only_option_as_array
assert_nothing_raised
do
assert_nothing_raised
do
assert_performed_jobs
2
,
only:
[
HelloJob
,
LoggingJob
]
do
assert_performed_jobs
2
,
only:
[
HelloJob
,
LoggingJob
]
do
...
@@ -892,6 +1083,134 @@ def test_assert_performed_jobs_with_only_and_except_option_and_too_many_sent
...
@@ -892,6 +1083,134 @@ def test_assert_performed_jobs_with_only_and_except_option_and_too_many_sent
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
end
end
def
test_assert_performed_jobs_with_queue_option
assert_performed_jobs
1
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
end
end
def
test_assert_performed_jobs_with_queue_option_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
end
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_without_block_with_queue_option
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
perform_enqueued_jobs
assert_performed_jobs
1
,
queue: :some_queue
end
def
test_assert_performed_jobs_without_block_with_queue_option_failure
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
queue: :some_queue
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_with_only_and_queue_options
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
def
test_assert_performed_jobs_with_only_and_queue_options_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_without_block_with_only_and_queue_options
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :some_queue
end
def
test_assert_performed_jobs_without_block_with_only_and_queue_options_failure
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
only:
HelloJob
,
queue: :some_queue
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_with_except_and_queue_options
assert_performed_jobs
1
,
except:
HelloJob
,
queue: :other_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
end
end
def
test_assert_performed_jobs_with_except_and_queue_options_failuree
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
except:
HelloJob
,
queue: :other_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_performed_jobs_without_block_with_except_and_queue_options
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
assert_performed_jobs
1
,
except:
HelloJob
,
queue: :other_queue
end
def
test_assert_performed_jobs_with_except_and_queue_options_failuree
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_jobs
1
,
except:
HelloJob
,
queue: :other_queue
end
assert_match
(
/1 .* but 0/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_with_only_option
def
test_assert_no_performed_jobs_with_only_option
assert_nothing_raised
do
assert_nothing_raised
do
assert_no_performed_jobs
only:
HelloJob
do
assert_no_performed_jobs
only:
HelloJob
do
...
@@ -900,6 +1219,26 @@ def test_assert_no_performed_jobs_with_only_option
...
@@ -900,6 +1219,26 @@ def test_assert_no_performed_jobs_with_only_option
end
end
end
end
def
test_assert_no_performed_jobs_without_block_with_only_option
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
assert_no_performed_jobs
only:
HelloJob
end
def
test_assert_no_performed_jobs_without_block_with_only_option_failure
HelloJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
only:
HelloJob
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_with_except_option
def
test_assert_no_performed_jobs_with_except_option
assert_nothing_raised
do
assert_nothing_raised
do
assert_no_performed_jobs
except:
LoggingJob
do
assert_no_performed_jobs
except:
LoggingJob
do
...
@@ -908,6 +1247,26 @@ def test_assert_no_performed_jobs_with_except_option
...
@@ -908,6 +1247,26 @@ def test_assert_no_performed_jobs_with_except_option
end
end
end
end
def
test_assert_no_performed_jobs_without_block_with_except_option
HelloJob
.
perform_later
(
"jeremy"
)
perform_enqueued_jobs
assert_no_performed_jobs
except:
HelloJob
end
def
test_assert_no_performed_jobs_without_block_with_except_option_failure
LoggingJob
.
perform_later
(
"jeremy"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
except:
HelloJob
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_with_only_and_except_option
def
test_assert_no_performed_jobs_with_only_and_except_option
error
=
assert_raise
ArgumentError
do
error
=
assert_raise
ArgumentError
do
assert_no_performed_jobs
only:
HelloJob
,
except:
HelloJob
do
assert_no_performed_jobs
only:
HelloJob
,
except:
HelloJob
do
...
@@ -918,6 +1277,19 @@ def test_assert_no_performed_jobs_with_only_and_except_option
...
@@ -918,6 +1277,19 @@ def test_assert_no_performed_jobs_with_only_and_except_option
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
end
end
def
test_assert_no_performed_jobs_without_block_with_only_and_except_options
error
=
assert_raise
ArgumentError
do
HelloJob
.
perform_later
(
"jeremy"
)
LoggingJob
.
perform_later
(
"bogdan"
)
perform_enqueued_jobs
assert_no_performed_jobs
only:
HelloJob
,
except:
HelloJob
end
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_with_only_option_as_array
def
test_assert_no_performed_jobs_with_only_option_as_array
assert_nothing_raised
do
assert_nothing_raised
do
assert_no_performed_jobs
only:
[
HelloJob
,
RescueJob
]
do
assert_no_performed_jobs
only:
[
HelloJob
,
RescueJob
]
do
...
@@ -978,13 +1350,141 @@ def test_assert_no_performed_jobs_with_only_and_except_option_failure
...
@@ -978,13 +1350,141 @@ def test_assert_no_performed_jobs_with_only_and_except_option_failure
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
assert_match
(
/`:only` and `:except`/
,
error
.
message
)
end
end
def
test_assert_performed_job
def
test_assert_no_performed_jobs_with_queue_option
assert_no_performed_jobs
queue: :some_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
end
end
def
test_assert_no_performed_jobs_with_queue_option_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
queue: :some_queue
do
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_without_block_with_queue_option
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
assert_no_performed_jobs
queue: :some_queue
end
def
test_assert_no_performed_jobs_without_block_with_queue_option_failure
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
queue: :some_queue
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_with_only_and_queue_options
assert_no_performed_jobs
only:
HelloJob
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
def
test_assert_no_performed_jobs_with_only_and_queue_options_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
only:
HelloJob
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_without_block_with_only_and_queue_options
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
assert_no_performed_jobs
only:
HelloJob
,
queue: :some_queue
end
def
test_assert_no_performed_jobs_without_block_with_only_and_queue_options_failure
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
only:
HelloJob
,
queue: :some_queue
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_with_except_and_queue_options
assert_no_performed_jobs
except:
HelloJob
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
end
end
def
test_assert_no_performed_jobs_with_except_and_queue_options_failure
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
except:
HelloJob
,
queue: :some_queue
do
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
end
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_no_performed_jobs_without_block_with_except_and_queue_options
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :other_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
assert_no_performed_jobs
except:
HelloJob
,
queue: :some_queue
end
def
test_assert_no_performed_jobs_without_block_with_except_and_queue_options_failure
HelloJob
.
set
(
queue: :other_queue
).
perform_later
(
"bogdan"
)
HelloJob
.
set
(
queue: :some_queue
).
perform_later
(
"bogdan"
)
LoggingJob
.
set
(
queue: :some_queue
).
perform_later
(
"jeremy"
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_no_performed_jobs
except:
HelloJob
,
queue: :some_queue
end
assert_match
(
/0 .* but 1/
,
error
.
message
)
end
def
test_assert_performed_with
assert_performed_with
(
job:
NestedJob
,
queue:
"default"
)
do
assert_performed_with
(
job:
NestedJob
,
queue:
"default"
)
do
NestedJob
.
perform_later
NestedJob
.
perform_later
end
end
end
end
def
test_assert_performed_job_returns
def
test_assert_performed_with_without_block
NestedJob
.
perform_later
perform_enqueued_jobs
assert_performed_with
(
job:
NestedJob
,
queue:
"default"
)
end
def
test_assert_performed_with_returns
job
=
assert_performed_with
(
job:
NestedJob
,
queue:
"default"
)
do
job
=
assert_performed_with
(
job:
NestedJob
,
queue:
"default"
)
do
NestedJob
.
perform_later
NestedJob
.
perform_later
end
end
...
@@ -995,7 +1495,20 @@ def test_assert_performed_job_returns
...
@@ -995,7 +1495,20 @@ def test_assert_performed_job_returns
assert_equal
"default"
,
job
.
queue_name
assert_equal
"default"
,
job
.
queue_name
end
end
def
test_assert_performed_job_failure
def
test_assert_performed_with_without_block_returns
NestedJob
.
perform_later
perform_enqueued_jobs
job
=
assert_performed_with
(
job:
NestedJob
,
queue:
"default"
)
assert_instance_of
NestedJob
,
job
assert_nil
job
.
scheduled_at
assert_equal
[],
job
.
arguments
assert_equal
"default"
,
job
.
queue_name
end
def
test_assert_performed_with_failure
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_with
(
job:
LoggingJob
)
do
assert_performed_with
(
job:
LoggingJob
)
do
HelloJob
.
perform_later
HelloJob
.
perform_later
...
@@ -1009,7 +1522,23 @@ def test_assert_performed_job_failure
...
@@ -1009,7 +1522,23 @@ def test_assert_performed_job_failure
end
end
end
end
def
test_assert_performed_job_with_at_option
def
test_assert_performed_with_without_block_failure
HelloJob
.
perform_later
perform_enqueued_jobs
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_with
(
job:
LoggingJob
)
end
HelloJob
.
set
(
queue:
"important"
).
perform_later
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_with
(
job:
HelloJob
,
queue:
"low"
)
end
end
def
test_assert_performed_with_with_at_option
assert_performed_with
(
job:
HelloJob
,
at:
Date
.
tomorrow
.
noon
)
do
assert_performed_with
(
job:
HelloJob
,
at:
Date
.
tomorrow
.
noon
)
do
HelloJob
.
set
(
wait_until:
Date
.
tomorrow
.
noon
).
perform_later
HelloJob
.
set
(
wait_until:
Date
.
tomorrow
.
noon
).
perform_later
end
end
...
@@ -1021,14 +1550,37 @@ def test_assert_performed_job_with_at_option
...
@@ -1021,14 +1550,37 @@ def test_assert_performed_job_with_at_option
end
end
end
end
def
test_assert_performed_job_with_global_id_args
def
test_assert_performed_with_without_block_with_at_option
HelloJob
.
set
(
wait_until:
Date
.
tomorrow
.
noon
).
perform_later
perform_enqueued_jobs
assert_performed_with
(
job:
HelloJob
,
at:
Date
.
tomorrow
.
noon
)
HelloJob
.
set
(
wait_until:
Date
.
tomorrow
.
noon
).
perform_later
perform_enqueued_jobs
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_with
(
job:
HelloJob
,
at:
Date
.
today
.
noon
)
end
end
def
test_assert_performed_wiht_with_global_id_args
ricardo
=
Person
.
new
(
9
)
ricardo
=
Person
.
new
(
9
)
assert_performed_with
(
job:
HelloJob
,
args:
[
ricardo
])
do
assert_performed_with
(
job:
HelloJob
,
args:
[
ricardo
])
do
HelloJob
.
perform_later
(
ricardo
)
HelloJob
.
perform_later
(
ricardo
)
end
end
end
end
def
test_assert_performed_job_failure_with_global_id_args
def
test_assert_performed_with_without_bllock_with_global_id_args
ricardo
=
Person
.
new
(
9
)
HelloJob
.
perform_later
(
ricardo
)
perform_enqueued_jobs
assert_performed_with
(
job:
HelloJob
,
args:
[
ricardo
])
end
def
test_assert_performed_with_failure_with_global_id_args
ricardo
=
Person
.
new
(
9
)
ricardo
=
Person
.
new
(
9
)
wilma
=
Person
.
new
(
11
)
wilma
=
Person
.
new
(
11
)
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
...
@@ -1040,7 +1592,19 @@ def test_assert_performed_job_failure_with_global_id_args
...
@@ -1040,7 +1592,19 @@ def test_assert_performed_job_failure_with_global_id_args
assert_equal
"No performed job found with {:job=>HelloJob, :args=>[
#{
wilma
.
inspect
}
]}"
,
error
.
message
assert_equal
"No performed job found with {:job=>HelloJob, :args=>[
#{
wilma
.
inspect
}
]}"
,
error
.
message
end
end
def
test_assert_performed_job_does_not_change_jobs_count
def
test_assert_performed_with_without_block_failure_with_global_id_args
ricardo
=
Person
.
new
(
9
)
wilma
=
Person
.
new
(
11
)
HelloJob
.
perform_later
(
ricardo
)
perform_enqueued_jobs
error
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_performed_with
(
job:
HelloJob
,
args:
[
wilma
])
end
assert_equal
"No performed job found with {:job=>HelloJob, :args=>[
#{
wilma
.
inspect
}
]}"
,
error
.
message
end
def
test_assert_performed_with_does_not_change_jobs_count
assert_performed_with
(
job:
HelloJob
)
do
assert_performed_with
(
job:
HelloJob
)
do
HelloJob
.
perform_later
HelloJob
.
perform_later
end
end
...
@@ -1051,6 +1615,18 @@ def test_assert_performed_job_does_not_change_jobs_count
...
@@ -1051,6 +1615,18 @@ def test_assert_performed_job_does_not_change_jobs_count
assert_equal
2
,
queue_adapter
.
performed_jobs
.
count
assert_equal
2
,
queue_adapter
.
performed_jobs
.
count
end
end
def
test_assert_performed_with_without_block_does_not_change_jobs_count
HelloJob
.
perform_later
perform_enqueued_jobs
assert_performed_with
(
job:
HelloJob
)
perform_enqueued_jobs
HelloJob
.
perform_later
assert_performed_with
(
job:
HelloJob
)
assert_equal
2
,
queue_adapter
.
performed_jobs
.
count
end
end
end
class
OverrideQueueAdapterTest
<
ActiveJob
::
TestCase
class
OverrideQueueAdapterTest
<
ActiveJob
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录