Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ActiveJob InlineAdapter not used in request tests?

I have this code in my test.rb :

config.active_job.queue_adapter = :inline

In the test I have:

scenario '15 minutes after last call a recall should happen' do    
  p ActiveJob::Base.queue_adapter
end

This returns: ActiveJob::QueueAdapters::InlineAdapter

which is good because the perform_later are executed immediately.

However when I add type: :request to the test like this:

scenario '15 minutes after last call a recall should happen', type: :request do    
  p ActiveJob::Base.queue_adapter
end

i'm getting: requestActiveJob::QueueAdapters::TestAdapter and the perform_later isn't executed anymore. Is this intended behaviour? How can I make sure the perform_later blocks are always executed in tests?

like image 278
rept Avatar asked Sep 17 '25 09:09

rept


1 Answers

This is related to this issue: https://github.com/rails/rails/issues/37270

Putting

(ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter)

IN the actual test fixes it.

Another more cleaner option is to (if possible) change the test type into: type: :system and making sure your rspec-rails version is >= 4.1

like image 83
rept Avatar answered Sep 20 '25 03:09

rept