我正在使用 rspec 编写 Controller 测试,在操作完成后,我的工作应该向管理员用户发送电子邮件。但我想为我的测试禁用这项工作或以某种方式模拟它。我该怎么做?
我正在使用 delayed_job_active_record
+ daemons
gem 。
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
最佳答案
#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)
关于ruby-on-rails - 禁用 ruby on rails 作业进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40891740/