forked from collectiveidea/delayed_job
/
delayed_method_spec.rb
59 lines (46 loc) · 1.94 KB
/
delayed_method_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'spec_helper'
describe 'random ruby objects' do
before { Delayed::Job.delete_all }
it "should respond_to :send_later method" do
Object.new.respond_to?(:send_later)
end
it "should raise a ArgumentError if send_later is called but the target method doesn't exist" do
lambda { Object.new.send_later(:method_that_deos_not_exist) }.should raise_error(NoMethodError)
end
it "should add a new entry to the job table when send_later is called on it" do
lambda { Object.new.send_later(:to_s) }.should change { Delayed::Job.count }.by(1)
end
it "should add a new entry to the job table when send_later is called on the class" do
lambda { Object.send_later(:to_s) }.should change { Delayed::Job.count }.by(1)
end
it "should call send later on methods which are wrapped with handle_asynchronously" do
story = Story.create :text => 'Once upon...'
Delayed::Job.count.should == 0
story.whatever(1, 5)
Delayed::Job.count.should == 1
job = Delayed::Job.find(:first)
job.payload_object.class.should == Delayed::PerformableMethod
job.payload_object.method.should == :whatever_without_send_later
job.payload_object.args.should == [1, 5]
job.payload_object.perform.should == 'Once upon...'
end
context "send_at" do
it "should queue a new job" do
lambda do
"string".send_at(1.hour.from_now, :length)
end.should change { Delayed::Job.count }.by(1)
end
it "should schedule the job in the future" do
time = 1.hour.from_now
job = "string".send_at(time, :length)
job.run_at.should == time
end
it "should store payload as PerformableMethod" do
job = "string".send_at(1.hour.from_now, :count, 'r')
job.payload_object.class.should == Delayed::PerformableMethod
job.payload_object.method.should == :count
job.payload_object.args.should == ['r']
job.payload_object.perform.should == 1
end
end
end