From 0a61f68b674f408eb326f47cc259fd9612261e60 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Fri, 29 Jan 2010 22:54:12 +0100 Subject: [PATCH] made sure empty hashes in Navvy::Job.enqueue get popped. --- lib/navvy/job/active_record.rb | 1 + lib/navvy/job/data_mapper.rb | 3 ++- lib/navvy/job/mongo_mapper.rb | 3 ++- lib/navvy/job/sequel.rb | 3 ++- spec/job_spec.rb | 15 ++++++++++++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/navvy/job/active_record.rb b/lib/navvy/job/active_record.rb index 21698d1..8622cbd 100644 --- a/lib/navvy/job/active_record.rb +++ b/lib/navvy/job/active_record.rb @@ -49,6 +49,7 @@ def self.enqueue(object, method_name, *args) options = {} if args.last.is_a?(Hash) options = args.last.delete(:job_options) || {} + args.pop if args.last.empty? end create( diff --git a/lib/navvy/job/data_mapper.rb b/lib/navvy/job/data_mapper.rb index 55defef..b59ddcd 100644 --- a/lib/navvy/job/data_mapper.rb +++ b/lib/navvy/job/data_mapper.rb @@ -30,7 +30,7 @@ class << self def self.limit @limit || Navvy.configuration.job_limit end - + ## # If and how long the jobs should be kept. # @@ -65,6 +65,7 @@ def self.enqueue(object, method_name, *args) options = {} if args.last.is_a?(Hash) options = args.last.delete(:job_options) || {} + args.pop if args.last.empty? end new_job = self.new diff --git a/lib/navvy/job/mongo_mapper.rb b/lib/navvy/job/mongo_mapper.rb index 55686ee..93ca0e5 100644 --- a/lib/navvy/job/mongo_mapper.rb +++ b/lib/navvy/job/mongo_mapper.rb @@ -28,7 +28,7 @@ class << self def self.limit @limit || Navvy.configuration.job_limit end - + ## # If and how long the jobs should be kept. # @@ -64,6 +64,7 @@ def self.enqueue(object, method_name, *args) options = {} if args.last.is_a?(Hash) options = args.last.delete(:job_options) || {} + args.pop if args.last.empty? end create( diff --git a/lib/navvy/job/sequel.rb b/lib/navvy/job/sequel.rb index a412145..97fde25 100644 --- a/lib/navvy/job/sequel.rb +++ b/lib/navvy/job/sequel.rb @@ -16,7 +16,7 @@ class << self def self.limit @limit || Navvy.configuration.job_limit end - + ## # If and how long the jobs should be kept. # @@ -52,6 +52,7 @@ def self.enqueue(object, method_name, *args) options = {} if args.last.is_a?(Hash) options = args.last.delete(:job_options) || {} + args.pop if args.last.empty? end create( diff --git a/spec/job_spec.rb b/spec/job_spec.rb index 4062d8e..7a25413 100644 --- a/spec/job_spec.rb +++ b/spec/job_spec.rb @@ -71,7 +71,20 @@ Navvy::Job.enqueue(Cow, :speak) first_job.priority.should == 0 end - + + it 'should set the options without messing up the arguments' do + job = Navvy::Job.enqueue( + Cow, + :speak, + true, + false, + :job_options => { + :run_at => Time.now + } + ) + job.args.should == [true, false] + end + it 'should set the priority' do Navvy::Job.enqueue( Cow,