2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
require "helper"
|
2015-03-11 17:57:13 -04:00
|
|
|
|
2014-09-23 23:43:12 -04:00
|
|
|
module ActiveJob
|
|
|
|
module QueueAdapters
|
|
|
|
class StubOneAdapter
|
|
|
|
def enqueue(*); end
|
|
|
|
def enqueue_at(*); end
|
|
|
|
end
|
|
|
|
|
|
|
|
class StubTwoAdapter
|
|
|
|
def enqueue(*); end
|
|
|
|
def enqueue_at(*); end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-11 17:57:13 -04:00
|
|
|
class QueueAdapterTest < ActiveJob::TestCase
|
2016-08-06 12:41:18 -04:00
|
|
|
test "should forbid nonsense arguments" do
|
2015-03-11 17:57:13 -04:00
|
|
|
assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex }
|
|
|
|
assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex.new }
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
test "should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling" do
|
2017-01-31 16:37:16 -05:00
|
|
|
ActiveJob::Base.disable_test_adapter
|
2014-09-23 23:43:12 -04:00
|
|
|
base_queue_adapter = ActiveJob::Base.queue_adapter
|
|
|
|
|
|
|
|
child_job_one = Class.new(ActiveJob::Base)
|
2016-05-16 16:13:08 -04:00
|
|
|
assert_equal child_job_one.queue_adapter_name, ActiveJob::Base.queue_adapter_name
|
|
|
|
|
2014-09-23 23:43:12 -04:00
|
|
|
child_job_one.queue_adapter = :stub_one
|
|
|
|
|
2017-05-26 08:04:13 -04:00
|
|
|
assert_not_equal ActiveJob::Base.queue_adapter, child_job_one.queue_adapter
|
2016-05-16 16:13:08 -04:00
|
|
|
assert_equal "stub_one", child_job_one.queue_adapter_name
|
2014-09-23 23:43:12 -04:00
|
|
|
assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter
|
|
|
|
|
|
|
|
child_job_two = Class.new(ActiveJob::Base)
|
|
|
|
child_job_two.queue_adapter = :stub_two
|
2017-05-26 08:04:13 -04:00
|
|
|
|
2016-05-16 16:13:08 -04:00
|
|
|
assert_equal "stub_two", child_job_two.queue_adapter_name
|
2014-09-23 23:43:12 -04:00
|
|
|
|
|
|
|
assert_kind_of ActiveJob::QueueAdapters::StubTwoAdapter, child_job_two.queue_adapter
|
|
|
|
assert_kind_of ActiveJob::QueueAdapters::StubOneAdapter, child_job_one.queue_adapter, "child_job_one's queue adapter should remain unchanged"
|
|
|
|
assert_equal base_queue_adapter, ActiveJob::Base.queue_adapter, "ActiveJob::Base's queue adapter should remain unchanged"
|
|
|
|
|
|
|
|
child_job_three = Class.new(ActiveJob::Base)
|
|
|
|
|
|
|
|
assert_not_nil child_job_three.queue_adapter
|
|
|
|
end
|
2015-03-11 17:57:13 -04:00
|
|
|
end
|