Skip to content

Commit

Permalink
Added Object#send_at(time, method) method to compliment Object#send_l…
Browse files Browse the repository at this point in the history
…ater
  • Loading branch information
samoli committed Feb 24, 2010
1 parent e7661d3 commit 0a42e01
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/delayed/message_sending.rb
Expand Up @@ -4,6 +4,10 @@ def send_later(method, *args)
Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args)
end

def send_at(time, method, *args)
Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args), 0, time
end

module ClassMethods
def handle_asynchronously(method)
without_name = "#{method}_without_send_later"
Expand Down
35 changes: 34 additions & 1 deletion spec/delayed_method_spec.rb
Expand Up @@ -44,11 +44,22 @@ def read(story)
RandomRubyObject.new.respond_to?(:send_later)

end

it "should respond_to :send_at method" do

RandomRubyObject.new.respond_to?(:send_at)

end


it "should raise a ArgumentError if send_later is called but the target method doesn't exist" do
lambda { RandomRubyObject.new.send_later(:method_that_deos_not_exist) }.should raise_error(NoMethodError)
end

it "should raise a ArgumentError if send_at is called but the target method doesn't exist" do
lambda { RandomRubyObject.new.send_at(:method_that_deos_not_exist, Time.at(1267012917)) }.should raise_error(NoMethodError)
end

it "should add a new entry to the job table when send_later is called on it" do
Delayed::Job.count.should == 0

Expand All @@ -64,13 +75,35 @@ def read(story)

Delayed::Job.count.should == 1
end

it "should add a new entry to the job table when send_at is called on it" do
Delayed::Job.count.should == 0

RandomRubyObject.new.send_at(Time.at(1267012917), :to_s)

Delayed::Job.count.should == 1
end

it "should run get the original method executed when the job is performed" do
it "should run get the original method executed when the send later job is performed" do

RandomRubyObject.new.send_later(:say_hello)

Delayed::Job.count.should == 1
end

it "should run get the original method executed when the send at job is performed" do

RandomRubyObject.new.send_at(Time.at(1267012917), :say_hello)

Delayed::Job.count.should == 1
end

it "should schedule original method executed when the send at job is performed" do

RandomRubyObject.new.send_at(Time.at(1267012917), :say_hello)

Delayed::Job.last.run_at.should == Time.at(1267012917)
end

it "should ignore ActiveRecord::RecordNotFound errors because they are permanent" do

Expand Down

0 comments on commit 0a42e01

Please sign in to comment.