forked from collectiveidea/delayed_job
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow class methods to be queued on ActiveRecord objects. Closes coll…
- Loading branch information
Showing
3 changed files
with
54 additions
and
74 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 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,45 @@ | ||
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 | ||
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 == "LOAD;Story;#{story.id}" | ||
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.send(:load, p.object) }.should_not raise_error | ||
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 == ["LOAD;Story;#{story.id}"] | ||
p.perform.should == 'Epilog: Once upon...' | ||
end | ||
|
||
|
||
|
||
end |