forked from tobi/delayed_job
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe Delayed::MessageSending do | ||
describe "handle_asynchronously" do | ||
class Story < ActiveRecord::Base | ||
def tell!(arg) | ||
end | ||
handle_asynchronously :tell! | ||
end | ||
|
||
it "should alias original method" do | ||
Story.new.should respond_to(:tell_without_delay!) | ||
Story.new.should respond_to(:tell_with_delay!) | ||
end | ||
|
||
it "should create a PerformableMethod" do | ||
story = Story.create! | ||
lambda { | ||
job = story.tell!(1) | ||
job.payload_object.class.should == Delayed::PerformableMethod | ||
job.payload_object.method.should == :tell_without_delay! | ||
job.payload_object.args.should == [1] | ||
}.should change { Delayed::Job.count } | ||
end | ||
end | ||
|
||
context "delay" do | ||
it "should create a new PerformableMethod job" do | ||
lambda { | ||
job = "hello".delay.count('l') | ||
job.payload_object.class.should == Delayed::PerformableMethod | ||
job.payload_object.method.should == :count | ||
job.payload_object.args.should == ['l'] | ||
}.should change { Delayed::Job.count }.by(1) | ||
end | ||
|
||
it "should set job options" do | ||
run_at = Time.parse('2010-05-03 12:55 AM') | ||
job = Object.delay(:priority => 20, :run_at => run_at).to_s | ||
job.run_at.should == run_at | ||
job.priority.should == 20 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
class StoryReader | ||
def read(story) | ||
"Epilog: #{story.tell}" | ||
end | ||
end | ||
|
||
describe Delayed::PerformableMethod do | ||
|
||
it "should ignore ActiveRecord::RecordNotFound errors because they are permanent" do | ||
story = Story.create :text => 'Once upon...' | ||
p = Delayed::PerformableMethod.new(story, :tell, []) | ||
story.destroy | ||
lambda { p.perform }.should_not raise_error | ||
describe "perform" do | ||
before do | ||
@method = Delayed::PerformableMethod.new("foo", :count, ['o']) | ||
end | ||
|
||
context "with the persisted record cannot be found" do | ||
before do | ||
@method.object = nil | ||
end | ||
|
||
it "should be a no-op if object is nil" do | ||
lambda { @method.perform }.should_not raise_error | ||
end | ||
end | ||
|
||
it "should call the method on the object" do | ||
@method.object.should_receive(:count).with('o') | ||
@method.perform | ||
end | ||
end | ||
|
||
it "should store the object as string if its an active record" do | ||
story = Story.create :text => 'Once upon...' | ||
p = Delayed::PerformableMethod.new(story, :tell, []) | ||
p.class.should == Delayed::PerformableMethod | ||
p.object.should == story | ||
p.method.should == :tell | ||
p.args.should == [] | ||
p.perform.should == 'Once upon...' | ||
end | ||
|
||
it "should allow class methods to be called on ActiveRecord models" do | ||
p = Delayed::PerformableMethod.new(Story, :count, []) | ||
lambda { p.perform.should be_kind_of(Fixnum) }.should_not raise_error | ||
|
||
it "should raise a ArgumentError if target method doesn't exist" do | ||
lambda { | ||
Delayed::PerformableMethod.new(Object, :method_that_does_not_exist, []) | ||
}.should raise_error(NoMethodError) | ||
end | ||
|
||
it "should store arguments as string if they are active record objects" do | ||
story = Story.create :text => 'Once upon...' | ||
reader = StoryReader.new | ||
p = Delayed::PerformableMethod.new(reader, :read, [story]) | ||
p.class.should == Delayed::PerformableMethod | ||
p.method.should == :read | ||
p.args.should == [story] | ||
p.perform.should == 'Epilog: Once upon...' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters