diff --git a/lib/sidekiq/priority.rb b/lib/sidekiq/priority.rb index 0eaeec4..c901adb 100644 --- a/lib/sidekiq/priority.rb +++ b/lib/sidekiq/priority.rb @@ -18,7 +18,7 @@ def self.priorities=(priorities) end def self.queue_with_priority(queue, priority) - priority.nil? ? queue : "#{queue}_#{priority}" + priority && self.priorities.include?(priority) ? "#{queue}_#{priority}" : queue end end end diff --git a/spec/sidekiq/worker_ext_spec.rb b/spec/sidekiq/worker_ext_spec.rb index cfe9895..f98e27c 100644 --- a/spec/sidekiq/worker_ext_spec.rb +++ b/spec/sidekiq/worker_ext_spec.rb @@ -22,5 +22,26 @@ def perform(first, second) 'queue' => 'foo_high' } end + + it 'sends an item to the default queue if priority is nil' do + TestWorker.stub(:client_push) { |item| item } + item = TestWorker.perform_with_priority(:invalid_priority, 1, 2) + item.should == { + 'class' => TestWorker, + 'args' => [1, 2], + 'queue' => :foo + } + end + + it 'sends an item to the default queue if a random priority is given' do + TestWorker.stub(:client_push) { |item| item } + item = TestWorker.perform_with_priority(:random_priority, 1, 2) + item.should == { + 'class' => TestWorker, + 'args' => [1, 2], + 'queue' => :foo + } + end + end end