mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Leverage test helpers for enqueued jobs
The production code calls `perform_later` and it's better to do the same in specs. Handy test helper allow us to control the execution. Credit to https://github.com/cyrillefr.
This commit is contained in:
@@ -11,8 +11,9 @@ describe ReportJob do
|
||||
let(:format) { :csv }
|
||||
|
||||
it "generates a report" do
|
||||
job = ReportJob.new
|
||||
job.perform(*report_args)
|
||||
job = perform_enqueued_jobs(only: ReportJob) do
|
||||
ReportJob.perform_later(*report_args)
|
||||
end
|
||||
expect_csv_report(job)
|
||||
end
|
||||
|
||||
@@ -20,10 +21,7 @@ describe ReportJob do
|
||||
job = ReportJob.perform_later(*report_args)
|
||||
expect(job.done?).to eq false
|
||||
|
||||
# This performs the job in the same process but that's good enought for
|
||||
# testing the job code. I hope that we can rely on the job worker.
|
||||
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
|
||||
job.retry_job
|
||||
perform_enqueued_jobs(only: ReportJob)
|
||||
|
||||
expect(job.done?).to eq true
|
||||
expect_csv_report(job)
|
||||
|
||||
Reference in New Issue
Block a user