I am using rails 6.01
, and delayed_job, 4.1.8
. I have set the active job queue adapter
#config/environments/test.rb
config.active_job.queue_adapter = :inline
The rspec code is
before(:each) { ActionMailer::Base.deliveries = [] }
it 'sends some message' do
UserMailer.delay.some_message
mail = ActionMailer::Base.deliveries
expect(mail.count).to eq 1
end
This test fails with a count of 0. Looking at the log the mail message is queued into DelayedJob but not executed:
Delayed::Backend::ActiveRecord::Job Create (0.4ms) INSERT INTO "delayed_jobs" ("handler", "run_at", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["handler", "--- !ruby/object:Delayed::PerformableMailer\nobject: !ruby/class 'UserMailer'\nmethod_name: :some_message"], ["run_at", "2019-12-12 18:29:26.457639"], ["created_at", "2019-12-12 18:29:26.458062"], ["updated_at", "2019-12-12 18:29:26.458062"]]
f I using binding.pry
in the test and examine Rails.application.config.queue_adapter.queue
the value is #<ActiveJob::QueueAdapters::InlineAdapter:0x00007faefad1d408>
which seems correct, so this problem is probably not caused by this rails 6 issue.
If I use
UserMailer.some_message.deliver
the test passes, so there is nothing wrong with the mailer.
How do I fix this?