diff --git a/app/jobs/supporters_export_create_job.rb b/app/jobs/supporters_export_create_job.rb new file mode 100644 index 00000000..5c06c373 --- /dev/null +++ b/app/jobs/supporters_export_create_job.rb @@ -0,0 +1,7 @@ +class SupportersExportCreateJob < ApplicationJob + queue_as :default + + def perform(*args) + ExportSupporters.run_export(*args) + end +end diff --git a/lib/export/export_supporters.rb b/lib/export/export_supporters.rb index 40b13a08..549c4388 100644 --- a/lib/export/export_supporters.rb +++ b/lib/export/export_supporters.rb @@ -18,7 +18,7 @@ module ExportSupporters e = Export.create(nonprofit: npo, user: user, status: :queued, export_type: 'ExportSupporters', parameters: params.to_json) - DelayedJobHelper.enqueue_job(ExportSupporters, :run_export, [npo_id, params.to_json, user_id, e.id]) + SupportersExportCreateJob.perform_later(npo_id, params.to_json, user_id, e.id) end def self.run_export(npo_id, params, user_id, export_id) diff --git a/spec/lib/export/export_supporters_spec.rb b/spec/lib/export/export_supporters_spec.rb index 7ecbb25b..c995e8fe 100644 --- a/spec/lib/export/export_supporters_spec.rb +++ b/spec/lib/export/export_supporters_spec.rb @@ -48,17 +48,12 @@ describe ExportSupporters do end it 'creates an export object and schedules job' do - Timecop.freeze(2020, 4, 5) do - DelayedJobHelper = double('delayed') + Timecop.freeze(2020, 4, 5) do params = { param1: 'pp', root_url: 'https://localhost:8080' }.with_indifferent_access - expect(Export).to receive(:create).and_wrap_original { |m, *args| - e = m.call(*args) # get original create - expect(DelayedJobHelper).to receive(:enqueue_job).with(ExportSupporters, :run_export, [@nonprofit.id, params.to_json, @user.id, e.id]) # add the enqueue - e - } - - ExportSupporters.initiate_export(@nonprofit.id, params, @user.id) + expect { + ExportSupporters.initiate_export(@nonprofit.id, params, @user.id) + }.to have_enqueued_job(SupportersExportCreateJob) export = Export.first expected_export = { id: export.id, user_id: @user.id,