mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Made sidekiq/testing work for the #enqueue method.
I also upgraded the testing tests so that they can be run in separate `it` blocks. The trick is to use `load` instead of `require` which allows the file to be re-executed.
This commit is contained in:
parent
7a105437d8
commit
c65d053808
2 changed files with 19 additions and 8 deletions
|
@ -66,7 +66,7 @@ module Sidekiq
|
|||
# Messages are enqueued to the 'default' queue.
|
||||
#
|
||||
def self.enqueue(klass, *args)
|
||||
push('class' => klass, 'args' => args)
|
||||
klass.perform_async(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,6 @@ Sidekiq.hook_rails!
|
|||
|
||||
class TestTesting < MiniTest::Unit::TestCase
|
||||
describe 'sidekiq testing' do
|
||||
|
||||
class DirectWorker
|
||||
include Sidekiq::Worker
|
||||
def perform(a, b)
|
||||
|
@ -19,6 +18,13 @@ class TestTesting < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class EnqueuedWorker
|
||||
include Sidekiq::Worker
|
||||
def perform(a, b)
|
||||
a + b
|
||||
end
|
||||
end
|
||||
|
||||
class FooMailer < ActionMailer::Base
|
||||
def bar(str)
|
||||
str
|
||||
|
@ -32,7 +38,7 @@ class TestTesting < MiniTest::Unit::TestCase
|
|||
end
|
||||
|
||||
before do
|
||||
require 'sidekiq/testing'
|
||||
load 'sidekiq/testing.rb'
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -44,23 +50,28 @@ class TestTesting < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
it 'stubs the async call when in testing mode' do
|
||||
# We can only have one it block here so all 'testing' tests
|
||||
# have to go here because require 'sidekiq/testing' changes
|
||||
# how Sidekiq works and we need to roll back those changes
|
||||
# when the test is done.
|
||||
it 'stubs the async call' do
|
||||
assert_equal 0, DirectWorker.jobs.size
|
||||
assert DirectWorker.perform_async(1, 2)
|
||||
assert_equal 1, DirectWorker.jobs.size
|
||||
end
|
||||
|
||||
it 'stubs the delay call on mailers' do
|
||||
assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
|
||||
FooMailer.delay.bar('hello!')
|
||||
assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
|
||||
end
|
||||
|
||||
it 'stubs the delay call on models' do
|
||||
assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
|
||||
FooModel.delay.bar('hello!')
|
||||
assert_equal 1, Sidekiq::Extensions::DelayedModel.jobs.size
|
||||
end
|
||||
|
||||
it 'stubs the enqueue call' do
|
||||
assert_equal 0, EnqueuedWorker.jobs.size
|
||||
assert Sidekiq::Client.enqueue(EnqueuedWorker, 1, 2)
|
||||
assert_equal 1, EnqueuedWorker.jobs.size
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue