1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Update delayed extensions to use perform_async so they are stubbed out by the testing infrastructure, fixes #77

This commit is contained in:
Mike Perham 2012-03-10 11:56:34 -08:00
parent 25928c657e
commit 0ced9e623e
2 changed files with 45 additions and 15 deletions

View file

@ -13,7 +13,7 @@ module Sidekiq
# to JSON and then deserialized on the other side back into a
# Ruby object.
obj = [@target, name, args]
::Sidekiq::Client.push('class' => @performable.name, 'args' => [::YAML.dump(obj)])
@performable.perform_async(::YAML.dump(obj))
end
end

View file

@ -1,5 +1,9 @@
require 'helper'
require 'sidekiq/worker'
require 'active_record'
require 'action_mailer'
require 'sidekiq/extensions/action_mailer'
require 'sidekiq/extensions/active_record'
class TestTesting < MiniTest::Unit::TestCase
describe 'sidekiq testing' do
@ -11,22 +15,48 @@ class TestTesting < MiniTest::Unit::TestCase
end
end
it 'stubs the async call when in testing mode' do
begin
# Override Sidekiq::Worker
require 'sidekiq/testing'
assert_equal 0, DirectWorker.jobs.size
assert DirectWorker.perform_async(1, 2)
assert_equal 1, DirectWorker.jobs.size
ensure
# Undo override
Sidekiq::Worker::ClassMethods.class_eval do
remove_method :perform_async
alias_method :perform_async, :perform_async_old
remove_method :perform_async_old
end
class FooMailer < ActionMailer::Base
def bar(str)
str
end
end
class FooModel < ActiveRecord::Base
def bar(str)
str
end
end
before do
require 'sidekiq/testing'
end
after do
# Undo override
Sidekiq::Worker::ClassMethods.class_eval do
remove_method :perform_async
alias_method :perform_async, :perform_async_old
remove_method :perform_async_old
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.
assert_equal 0, DirectWorker.jobs.size
assert DirectWorker.perform_async(1, 2)
assert_equal 1, DirectWorker.jobs.size
assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
FooMailer.delay.bar('hello!')
assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
FooModel.delay.bar('hello!')
assert_equal 1, Sidekiq::Extensions::DelayedModel.jobs.size
end
end
end