This is my test code:
require 'rails_helper'
describe CookCookieWorker do
let(:user) { FactoryGirl.create(:user) }
let(:oven) { user.ovens.first }
it { is_expected.to be_processed_in :cookies }
it 'enqueues the cook cookies worker to be processed in 5 seconds' do
oven.cookies.create!({ fillings: 'Vanilla' })
cookie = oven.cookies.last
expect(CookCookieWorker).to have_enqueued_sidekiq_job(cookie.id).in(5.seconds)
end
end
And this is the result I get
expected to have an enqueued CookCookieWorker job
arguments: [1]
options: {"in"=>5 seconds}
found
arguments: []
options: []
Just to clarify, I have an after_save
callback in the Cookie
model that calls the worker this way:
CookCookieWorker.perform_in(5.seconds, id)
at the beginning I thought that probably I could not test the worker this way, probably the model callbacks doesn't have effect? However I tried to manually call the worker in the test:
require 'rails_helper'
describe CookCookieWorker do
let(:user) { FactoryGirl.create(:user) }
let(:oven) { user.ovens.first }
it { is_expected.to be_processed_in :cookies }
it 'enqueues the cook cookies worker to be processed in 5 seconds' do
oven.cookies.create!({ fillings: 'Vanilla' })
cookie = oven.cookies.last
CookCookieWorker.perform_in(5.seconds, cookie.id) # Calling it manually
expect(CookCookieWorker).to have_enqueued_sidekiq_job(cookie.id).in(5.seconds)
end
end
But I get the same result, the test fails. Any idea?