mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Improve docs for Sidekiq job assertion helpers.
This commit is contained in:
@@ -1,8 +1,20 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module SidekiqHelpers
|
module SidekiqHelpers
|
||||||
# expect_enqueued_with(job: feature_topic_users, args: { topic_id: topic.id }) do
|
# Assert job is enqueued:
|
||||||
# PostCreator.new.create
|
#
|
||||||
|
# expect_enqueued_with(job: :post_process, args: { post_id: post.id }) do
|
||||||
|
# post.update!(raw: 'new raw')
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# Asserting jobs enqueued with delay:
|
||||||
|
#
|
||||||
|
# expect_enqueued_with(
|
||||||
|
# job: :post_process,
|
||||||
|
# args: { post_id: post.id },
|
||||||
|
# at: Time.zone.now + 1.hour
|
||||||
|
# ) do
|
||||||
|
# post.update!(raw: 'new raw')
|
||||||
# end
|
# end
|
||||||
def expect_enqueued_with(job:, args: {}, at: nil, expectation: true)
|
def expect_enqueued_with(job:, args: {}, at: nil, expectation: true)
|
||||||
klass = job.instance_of?(Class) ? job : "::Jobs::#{job.to_s.camelcase}".constantize
|
klass = job.instance_of?(Class) ? job : "::Jobs::#{job.to_s.camelcase}".constantize
|
||||||
@@ -22,8 +34,16 @@ module SidekiqHelpers
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# expect_not_enqueued_with(job: feature_topic_users, args: { topic_id: topic.id }) do
|
# Assert job is not enqueued:
|
||||||
# # Do Nothing...
|
#
|
||||||
|
# expect_not_enqueued_with(job: :post_process) do
|
||||||
|
# post.update!(raw: 'new raw')
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# Assert job is not enqueued with specific params
|
||||||
|
#
|
||||||
|
# expect_not_enqueued_with(job: :post_process, args: { post_id: post.id }) do
|
||||||
|
# post.update!(raw: 'new raw')
|
||||||
# end
|
# end
|
||||||
def expect_not_enqueued_with(job:, args: {}, at: nil)
|
def expect_not_enqueued_with(job:, args: {}, at: nil)
|
||||||
expect_enqueued_with(job: job, args: args, at: at, expectation: false) do
|
expect_enqueued_with(job: job, args: args, at: at, expectation: false) do
|
||||||
@@ -31,6 +51,10 @@ module SidekiqHelpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks whether a job has been enqueued with the given arguments
|
||||||
|
#
|
||||||
|
# job_enqueued?(job: :post_process, args: { post_id: post.id }) => true/false
|
||||||
|
# job_enqueued?(job: :post_process, args: { post_id: post.id }, at: Time.zone.now + 1.hour) => true/false
|
||||||
def job_enqueued?(job:, args: {}, at: nil)
|
def job_enqueued?(job:, args: {}, at: nil)
|
||||||
klass = job.instance_of?(Class) ? job : "::Jobs::#{job.to_s.camelcase}".constantize
|
klass = job.instance_of?(Class) ? job : "::Jobs::#{job.to_s.camelcase}".constantize
|
||||||
at = at.to_f if at.is_a?(Time)
|
at = at.to_f if at.is_a?(Time)
|
||||||
|
|||||||
Reference in New Issue
Block a user