diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index a28060ea5b..3900ee0d7c 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -91,7 +91,7 @@ module Admin # Send notifications to all producers who are part of the order cycle def notify_producers - Delayed::Job.enqueue OrderCycleNotificationJob.new(params[:id].to_i) + OrderCycleNotificationJob.perform_later params[:id].to_i redirect_to main_app.admin_order_cycles_path, notice: I18n.t(:order_cycles_email_to_producers_notice) diff --git a/app/jobs/order_cycle_notification_job.rb b/app/jobs/order_cycle_notification_job.rb index d4efa6de13..b6ab117320 100644 --- a/app/jobs/order_cycle_notification_job.rb +++ b/app/jobs/order_cycle_notification_job.rb @@ -1,6 +1,6 @@ # Delivers an email with a report of the order cycle to each of its suppliers -OrderCycleNotificationJob = Struct.new(:order_cycle_id) do - def perform +class OrderCycleNotificationJob < ActiveJob::Base + def perform(order_cycle_id) order_cycle = OrderCycle.find(order_cycle_id) order_cycle.suppliers.each do |supplier| ProducerMailer.order_cycle_report(supplier, order_cycle).deliver diff --git a/spec/jobs/order_cycle_notification_job_spec.rb b/spec/jobs/order_cycle_notification_job_spec.rb index aa2eb2b2b4..06092433ee 100644 --- a/spec/jobs/order_cycle_notification_job_spec.rb +++ b/spec/jobs/order_cycle_notification_job_spec.rb @@ -9,7 +9,7 @@ describe OrderCycleNotificationJob do end it 'sends a mail to each supplier' do - run_job OrderCycleNotificationJob.new(order_cycle.id) + OrderCycleNotificationJob.perform_now order_cycle.id expect(ProducerMailer).to have_received(:order_cycle_report).twice end end