-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Hi All,
I am having some trouble with Request Spec and Delayed Job. Currently I have an endpoint that is supposed to enqueue a job; but when triggering this through Request Spec, the job doesn't seem to be enqueued. When I try a similar test using a Controller Spec, the job is enqueued.
For example in my controller, I am enqueuing a job on a POST like follows...
module V1
class MyController < ApplicationController
def create
MyJob.perform_later(params[:name])
end
end
end
On a Controller Spec, this passes; I simply check to see if the job queue increments to 1.
require 'rails_helper'
RSpec.describe V1::MyController, type: :controller do
let(:valid_post) { {name: 'asdf'} }
let(:valid_session) { {} }
describe 'POST #create' do
it 'enqueues a job' do
post :create, params: valid_attributes, session: valid_session
expect(Delayed::Job.count).to eq(1)
end
end
end
But on Request spec, the job count is 0 and seemingly, the job is not enqueued
require 'rails_helper'
RSpec.describe '/my-endpoint', type: :request do
let(:valid_post) { {name: 'asdf'} }
describe 'POST #create' do
it 'enqueues a job' do
post '/my-endpoint', params: valid_attributes
expect(Delayed::Job.count).to eq(1)
end
end
end
Is there any setting that would cause a difference in between Controller and Request Specs?
Thanks for your help.
Metadata
Metadata
Assignees
Labels
No labels