Adding ActiveJob RSpec helper for using Test queue adapter.
This commit is contained in:
parent
10110e03cb
commit
3a5d597ab9
2 changed files with 41 additions and 0 deletions
|
@ -11,6 +11,9 @@ class ApplicationJob < ActiveJob::Base
|
||||||
# until we resolve this dependency.
|
# until we resolve this dependency.
|
||||||
around_enqueue do |job, block|
|
around_enqueue do |job, block|
|
||||||
block.call.tap do |delayed_job|
|
block.call.tap do |delayed_job|
|
||||||
|
# skip test adapter
|
||||||
|
break if delayed_job.is_a?(Array)
|
||||||
|
|
||||||
delayed_job.update!(attempts: job.executions)
|
delayed_job.update!(attempts: job.executions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
38
spec/support/active_job.rb
Normal file
38
spec/support/active_job.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
module ZammadActiveJobHelper
|
||||||
|
|
||||||
|
delegate :enqueued_jobs, :performed_jobs, to: :queue_adapter
|
||||||
|
|
||||||
|
def queue_adapter
|
||||||
|
::ActiveJob::Base.queue_adapter
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_jobs
|
||||||
|
enqueued_jobs.clear
|
||||||
|
performed_jobs.clear
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RSpec.configure do |config|
|
||||||
|
|
||||||
|
activate_for = {
|
||||||
|
type: :job, # actual Job examples
|
||||||
|
performs_jobs: true, # examples performing Jobs
|
||||||
|
}
|
||||||
|
|
||||||
|
activate_for.each do |key, value|
|
||||||
|
config.include ZammadActiveJobHelper, key => value
|
||||||
|
config.include RSpec::Rails::JobExampleGroup, key => value
|
||||||
|
|
||||||
|
config.around(:each, key => value) do |example|
|
||||||
|
|
||||||
|
default_queue_adapter = ::ActiveJob::Base.queue_adapter
|
||||||
|
::ActiveJob::Base.queue_adapter = :test
|
||||||
|
|
||||||
|
clear_jobs
|
||||||
|
|
||||||
|
example.run
|
||||||
|
|
||||||
|
::ActiveJob::Base.queue_adapter = default_queue_adapter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue