aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases
diff options
context:
space:
mode:
authorwvengen <dev-rails@willem.engen.nl>2015-03-18 10:48:26 +0100
committerwvengen <dev-rails@willem.engen.nl>2015-09-17 22:17:39 +0200
commit7059ab35f797c163cd8907abcd7d0830b31e56f7 (patch)
tree708ccbf2da4412030b305f79c629a6961eb487c1 /activejob/test/cases
parent61f9e47feac75a2cf4ed9e092bac036294564168 (diff)
downloadrails-7059ab35f797c163cd8907abcd7d0830b31e56f7.tar.gz
rails-7059ab35f797c163cd8907abcd7d0830b31e56f7.tar.bz2
rails-7059ab35f797c163cd8907abcd7d0830b31e56f7.zip
Add job priorities to ActiveJob
Diffstat (limited to 'activejob/test/cases')
-rw-r--r--activejob/test/cases/queue_priority_test.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/activejob/test/cases/queue_priority_test.rb b/activejob/test/cases/queue_priority_test.rb
new file mode 100644
index 0000000000..ca17b51dad
--- /dev/null
+++ b/activejob/test/cases/queue_priority_test.rb
@@ -0,0 +1,47 @@
+require 'helper'
+require 'jobs/hello_job'
+
+class QueuePriorityTest < ActiveSupport::TestCase
+ test 'priority unset by default' do
+ assert_equal nil, HelloJob.priority
+ end
+
+ test 'uses given priority' do
+ 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
+ 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
+ original_priority = HelloJob.priority
+
+ begin
+ HelloJob.queue_with_priority { self.arguments.first=='1' ? 99 : 11 }
+ assert_equal 99, HelloJob.new('1').priority
+ assert_equal 11, HelloJob.new('3').priority
+ ensure
+ HelloJob.priority = original_priority
+ end
+ end
+
+ test 'uses priority passed to #set' do
+ job = HelloJob.set(priority: 123).perform_later
+ assert_equal 123, job.priority
+ end
+end