active_job.rb 871 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. module ZammadActiveJobHelper
  2. delegate :enqueued_jobs, :performed_jobs, to: :queue_adapter
  3. def queue_adapter
  4. ::ActiveJob::Base.queue_adapter
  5. end
  6. def clear_jobs
  7. enqueued_jobs.clear
  8. performed_jobs.clear
  9. ActiveJobLock.destroy_all
  10. end
  11. end
  12. RSpec.configure do |config|
  13. activate_for = {
  14. type: :job, # actual Job examples
  15. performs_jobs: true, # examples performing Jobs
  16. }
  17. activate_for.each do |key, value|
  18. config.include ZammadActiveJobHelper, key => value
  19. config.include RSpec::Rails::JobExampleGroup, key => value
  20. config.around(:each, key => value) do |example|
  21. default_queue_adapter = ::ActiveJob::Base.queue_adapter
  22. ::ActiveJob::Base.queue_adapter = :test
  23. clear_jobs
  24. example.run
  25. ensure
  26. ::ActiveJob::Base.queue_adapter = default_queue_adapter
  27. end
  28. end
  29. end