Disable ruby ​​on rails to check

I am writing a test test with rspec, and after the action is completed, my job is to send an email to admin. But I would like to disable this work for my tests or somehow make fun of it. How can i do this?

I use delayed_job_active_record + daemons gems.

 class AdminNotificationJob < ActiveJob::Base queue_as :default def perform(method, parameter) User.admin.includes(:profile).each do |admin| AdminMailer.send(method, admin, parameter).deliver_later end end end 
+5
source share
2 answers
 #config/environment/test.rb config.active_job.queue_adapter = :test # in spec expect { your_action_that_triggers_job_enqueuing }.to have_enqueued_job(AdminNotificationJob).with(your_arguments) 
+7
source

Your controller test will look like this:

 it "enqueues a AdminNotification" do expect { get :your_controller_action, {} }.to have_enqueued_job(AdminNotificationJob) end 

This uses the #have_enqueued_job method found on rspec-rails

+1
source

Source: https://habr.com/ru/post/1260596/


All Articles