I am building an application that uses github-omniauth for authentication. The basic user flow for a new user would be they login via github and on the redirect for the initial login I would schedule a background job to request/parse some data from github. How do I go about Test-driving this? I understand how to use the test mode of omniauth to test the redirect after a successful login but Im not really sure where to go next with verifying that a background job is queued. Any direction would be greatly appreciated.
Hi @ballou88 before we begin testing DJs, we have to make sure they don’t get run after creation (default behavior). This way we can make assertions about the jobs before they are run.
# spec/spec_helper.rb RSpec.configure do |config| before(:each). do Delayed::Worker.delay_jobs = true end # ... end
With this setting, DJ will actually delay the jobs, as opposed to just running them right away. That way we can set up an assertion like this:
# spec/features/user_signs_up_spec.rb require 'spec_helper' describe User, '#some_method' do it 'delays a job' do # steps that will trigger the job expect(Delayed::Job.count).to eq 1 expect(Delayed::Job.last.handler).to match 'some value' end end
Your test might look a little different than this – hopefully the syntax will point you in the right direction.
Paste some code if you run into any issues and we troubleshoot further.
Thanks for the reply, I haven’t had a chance to implement this yet, but it makes sense to me.