2
votes

I'm using delayed_job to send emails in a Rails app and I'd like to test the email sending locally. Normally what I do is just set the mailer config to :test and then take a peek at ActionMailer::Base.deliveries, but the problem is when I call MyMailer.delay.some_email instead of MyMailer.some_email.deliver, the email never gets added to deliveries. I assume it's because I'm not longer calling "deliver", but you're not supposed to call "deliver" when using delayed_job.

All my production emails work fine. It's only the testing ones that don't.

Thoughts?

1

1 Answers

2
votes

The jobs are not being worked off in the test environment because there's no jobs runner working. You need to instead check that the job has been added to the queue.

# Call the function
assert_not_equal Delayed::Job.count, 0, "Jobs have been added to the queue"

You can then test the job works by working it off, like so:

Delayed::Worker.new.work_off 1
# Check the job has been done as expected