lib/sidekiq/testing.rb in sidekiq-5.0.0 vs lib/sidekiq/testing.rb in sidekiq-5.0.1
- old
+ new
@@ -53,10 +53,19 @@
def server_middleware
@server_chain ||= Middleware::Chain.new
yield @server_chain if block_given?
@server_chain
end
+
+ def constantize(str)
+ names = str.split('::')
+ names.shift if names.empty? || names.first.empty?
+
+ names.inject(Object) do |constant, name|
+ constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
+ end
+ end
end
end
# Default to fake testing to keep old behavior
Sidekiq::Testing.fake!
@@ -74,11 +83,11 @@
Queues.push(job['queue'], job['class'], job)
end
true
elsif Sidekiq::Testing.inline?
payloads.each do |job|
- klass = job['class'].constantize
+ klass = Sidekiq::Testing.constantize(job['class'])
job['id'] ||= SecureRandom.hex(12)
job_hash = Sidekiq.load_json(Sidekiq.dump_json(job))
klass.process_job(job_hash)
end
true
@@ -307,10 +316,10 @@
def drain_all
while jobs.any?
worker_classes = jobs.map { |job| job["class"] }.uniq
worker_classes.each do |worker_class|
- worker_class.constantize.drain
+ Sidekiq::Testing.constantize(worker_class).drain
end
end
end
end
end