2014-05-18 10:24:30 -04:00
|
|
|
require 'helper'
|
|
|
|
require 'jobs/hello_job'
|
2014-08-12 06:53:46 -04:00
|
|
|
require 'jobs/logging_job'
|
|
|
|
require 'jobs/nested_job'
|
2014-05-18 10:24:30 -04:00
|
|
|
|
|
|
|
class QueueNamingTest < ActiveSupport::TestCase
|
|
|
|
test 'name derived from base' do
|
2014-08-15 16:32:08 -04:00
|
|
|
assert_equal "default", HelloJob.queue_name
|
2014-05-18 10:24:30 -04:00
|
|
|
end
|
2014-08-12 06:53:46 -04:00
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
test 'uses given queue name job' do
|
2014-10-10 02:53:22 -04:00
|
|
|
original_queue_name = HelloJob.queue_name
|
|
|
|
|
2014-05-18 10:24:30 -04:00
|
|
|
begin
|
|
|
|
HelloJob.queue_as :greetings
|
2014-08-25 10:34:50 -04:00
|
|
|
assert_equal "greetings", HelloJob.new.queue_name
|
|
|
|
ensure
|
|
|
|
HelloJob.queue_name = original_queue_name
|
|
|
|
end
|
|
|
|
end
|
2014-06-09 12:49:14 -04:00
|
|
|
|
2014-10-09 13:33:55 -04:00
|
|
|
test 'allows a blank queue name' do
|
2014-10-10 02:53:22 -04:00
|
|
|
original_queue_name = HelloJob.queue_name
|
|
|
|
|
2014-10-09 13:33:55 -04:00
|
|
|
begin
|
|
|
|
HelloJob.queue_as ""
|
|
|
|
assert_equal "", HelloJob.new.queue_name
|
|
|
|
ensure
|
|
|
|
HelloJob.queue_name = original_queue_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'does not use a nil queue name' do
|
2014-10-10 02:53:22 -04:00
|
|
|
original_queue_name = HelloJob.queue_name
|
|
|
|
|
2014-10-09 13:33:55 -04:00
|
|
|
begin
|
|
|
|
HelloJob.queue_as nil
|
|
|
|
assert_equal "default", HelloJob.new.queue_name
|
|
|
|
ensure
|
|
|
|
HelloJob.queue_name = original_queue_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
test 'evals block given to queue_as to determine queue' do
|
2014-10-10 02:53:22 -04:00
|
|
|
original_queue_name = HelloJob.queue_name
|
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
begin
|
|
|
|
HelloJob.queue_as { :another }
|
|
|
|
assert_equal "another", HelloJob.new.queue_name
|
2014-05-18 10:24:30 -04:00
|
|
|
ensure
|
2014-08-25 10:34:50 -04:00
|
|
|
HelloJob.queue_name = original_queue_name
|
2014-05-18 10:24:30 -04:00
|
|
|
end
|
|
|
|
end
|
2014-08-18 04:17:36 -04:00
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
test 'can use arguments to determine queue_name in queue_as block' do
|
2014-10-10 02:53:22 -04:00
|
|
|
original_queue_name = HelloJob.queue_name
|
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
begin
|
|
|
|
HelloJob.queue_as { self.arguments.first=='1' ? :one : :two }
|
|
|
|
assert_equal "one", HelloJob.new('1').queue_name
|
|
|
|
assert_equal "two", HelloJob.new('3').queue_name
|
|
|
|
ensure
|
|
|
|
HelloJob.queue_name = original_queue_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'queu_name_prefix prepended to the queue name' do
|
2014-10-10 02:53:22 -04:00
|
|
|
original_queue_name_prefix = ActiveJob::Base.queue_name_prefix
|
|
|
|
original_queue_name = HelloJob.queue_name
|
2014-08-18 04:17:36 -04:00
|
|
|
|
2014-10-10 02:53:22 -04:00
|
|
|
begin
|
2014-08-18 04:17:36 -04:00
|
|
|
ActiveJob::Base.queue_name_prefix = 'aj'
|
|
|
|
HelloJob.queue_as :low
|
|
|
|
assert_equal 'aj_low', HelloJob.queue_name
|
|
|
|
ensure
|
|
|
|
ActiveJob::Base.queue_name_prefix = original_queue_name_prefix
|
|
|
|
HelloJob.queue_name = original_queue_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-25 10:34:50 -04:00
|
|
|
test 'uses queue passed to #set' do
|
|
|
|
job = HelloJob.set(queue: :some_queue).perform_later
|
|
|
|
assert_equal "some_queue", job.queue_name
|
|
|
|
end
|
2014-05-18 10:24:30 -04:00
|
|
|
end
|