1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/test/cases/queue_priority_test.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2017-07-09 13:49:52 -04:00
# frozen_string_literal: true
require "helper"
require "jobs/hello_job"
2015-03-18 05:48:26 -04:00
class QueuePriorityTest < ActiveSupport::TestCase
test "priority unset by default" do
assert_nil HelloJob.priority
2015-03-18 05:48:26 -04:00
end
test "uses given priority" do
2015-03-18 05:48:26 -04:00
original_priority = HelloJob.priority
begin
HelloJob.queue_with_priority 90
assert_equal 90, HelloJob.new.priority
ensure
HelloJob.priority = original_priority
end
end
test "evals block given to priority to determine priority" do
2015-03-18 05:48:26 -04:00
original_priority = HelloJob.priority
begin
HelloJob.queue_with_priority { 25 }
assert_equal 25, HelloJob.new.priority
ensure
HelloJob.priority = original_priority
end
end
test "can use arguments to determine priority in priority block" do
2015-03-18 05:48:26 -04:00
original_priority = HelloJob.priority
begin
HelloJob.queue_with_priority { arguments.first == "1" ? 99 : 11 }
assert_equal 99, HelloJob.new("1").priority
assert_equal 11, HelloJob.new("3").priority
2015-03-18 05:48:26 -04:00
ensure
HelloJob.priority = original_priority
end
end
test "uses priority passed to #set" do
2015-03-18 05:48:26 -04:00
job = HelloJob.set(priority: 123).perform_later
assert_equal 123, job.priority
end
end