All threads / Testing Controllers that call an activejob

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Testing Controllers that call an activejob

Paul C asked in Rails

Hi,

My integration tests hit a create method in my API that calls an activejob. This works fine in the actual app, but when I run any tests I get:

NameError: uninitialized constant Api::V1::ControllerName::JobName

Do I need to mock out the ActiveJob API or do load ActiveJob inside my ActionDispatch::IntegrationTest?
Thanks!

Maybe you just forgot to change uninitialized constant Api::V1::ControllerName::JobName to match your class name?

Thanks - I'm just calling

JobName.perform_later @content_for_job

Which raises the NameError. If I run it from the application UI it works fine, it's only when running from the test suite that it throws the NameError

Yeah, which is why my guess is that your test suite is referencing the wrong thing somewhere when it's trying to replicate the same thing.

Thanks. I made no changes to my codebase, but updated my mac which forced a restart of everything and now the tests pass without issue. I can only think that it was related to this Sidekiq issue:

https://github.com/mperham/sidekiq/issues/2207

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.