mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Inline testing should pass arguments through json
If you are passing arguments like time objects that serialize to strings but don't deserialize back automatically, inline testing was passing the objects through raw meaning different behavior in tests vs. production. Now the inline wrapper does a round trip through json.
This commit is contained in:
parent
6ddb3eaea5
commit
1eb0c80ca0
2 changed files with 13 additions and 1 deletions
|
@ -29,7 +29,7 @@ module Sidekiq
|
|||
module ClassMethods
|
||||
alias_method :perform_async_old, :perform_async
|
||||
def perform_async(*args)
|
||||
new.perform(*args)
|
||||
new.perform(*Sidekiq.load_json(Sidekiq.dump_json(args)))
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ Sidekiq.hook_rails!
|
|||
class TestInline < MiniTest::Unit::TestCase
|
||||
describe 'sidekiq inline testing' do
|
||||
class InlineError < RuntimeError; end
|
||||
class ParameterIsNotString < RuntimeError; end
|
||||
|
||||
class InlineWorker
|
||||
include Sidekiq::Worker
|
||||
|
@ -20,6 +21,13 @@ class TestInline < MiniTest::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class InlineWorkerWithTimeParam
|
||||
include Sidekiq::Worker
|
||||
def perform(time)
|
||||
raise ParameterIsNotString unless time.is_a?(String)
|
||||
end
|
||||
end
|
||||
|
||||
class InlineFooMailer < ActionMailer::Base
|
||||
def bar(str)
|
||||
raise InlineError
|
||||
|
@ -71,5 +79,9 @@ class TestInline < MiniTest::Unit::TestCase
|
|||
Sidekiq::Client.enqueue(InlineWorker, false)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should relay parameters through json' do
|
||||
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue