Skip to content

Request Spec not Enqueuing Delayed Job #1948

@musiaht

Description

@musiaht

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions