diff --git a/lib/resque_spec/scheduler.rb b/lib/resque_spec/scheduler.rb index d7af460..e366741 100644 --- a/lib/resque_spec/scheduler.rb +++ b/lib/resque_spec/scheduler.rb @@ -6,8 +6,11 @@ def self.extended(klass) if klass.respond_to? :enqueue_at klass.instance_eval do alias :enqueue_at_without_resque_spec :enqueue_at + alias :enqueue_at_with_queue_without_resque_spec :enqueue_at_with_queue alias :enqueue_in_without_resque_spec :enqueue_in + alias :enqueue_in_with_queue_without_resque_spec :enqueue_in_with_queue alias :remove_delayed_without_resque_spec :remove_delayed + alias :scheduled_at_without_resque_spec :scheduled_at end end klass.extend(ResqueSpec::SchedulerExtMethods) @@ -22,7 +25,7 @@ def enqueue_at(time, klass, *args) end def enqueue_at_with_queue(queue, time, klass, *args) - return enqueue_at_with_queue_without_resque_spec(time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_at_with_queue_without_resque_spec) + return enqueue_at_with_queue_without_resque_spec(queue, time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_at_with_queue_without_resque_spec) ResqueSpec.enqueue_at_with_queue(queue, time, klass, *args) end @@ -34,7 +37,7 @@ def enqueue_in(time, klass, *args) end def enqueue_in_with_queue(queue, time, klass, *args) - return enqueue_in_with_queue_without_resque_spec(time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_in_with_queue_without_resque_spec) + return enqueue_in_with_queue_without_resque_spec(queue, time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_in_with_queue_without_resque_spec) ResqueSpec.enqueue_in_with_queue(queue, time, klass, *args) end @@ -44,6 +47,12 @@ def remove_delayed(klass, *args) ResqueSpec.remove_delayed(klass, *args) end + + def scheduled_at(klass, *args) + return scheduled_at_without_resque_spec(klass, *args) if ResqueSpec.disable_ext && respond_to?(:scheduled_at_without_resque_spec) + + ResqueSpec.scheduled_at(klass, *args) + end end def enqueue_at(time, klass, *args) @@ -77,6 +86,12 @@ def schedule_for(klass) queue_by_name(schedule_queue_name(klass)) end + def scheduled_at(klass, *args) + schedule_for(klass).collect do |job| + job[:args] == args ? job[:time].to_i : nil + end.compact + end + private def is_time?(time) diff --git a/spec/resque_spec/scheduler_spec.rb b/spec/resque_spec/scheduler_spec.rb index c9fe7d0..866fc39 100644 --- a/spec/resque_spec/scheduler_spec.rb +++ b/spec/resque_spec/scheduler_spec.rb @@ -194,7 +194,18 @@ Resque.remove_delayed(NameFromClassMethod, 1).should == 1 end end + end + + describe "#scheduled_at" do + before do + Timecop.travel(Time.at(0)) do + Resque.enqueue_at(scheduled_at, NameFromClassMethod, 1) + end + end + it "returns the scheduled job" do + Resque.scheduled_at(NameFromClassMethod, 1).should eq [scheduled_at.to_i] + end end end