Skip to content

Commit

Permalink
Rearrange some specs
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed May 4, 2010
1 parent 0885b19 commit 69d6de4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 110 deletions.
6 changes: 1 addition & 5 deletions lib/delayed/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def payload_object
def name
@name ||= begin
payload = payload_object
if payload.respond_to?(:display_name)
payload.display_name
else
payload.class.name
end
payload.respond_to?(:display_name) ? payload.display_name : payload.class.name
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/delayed/worker.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'timeout'
require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/kernel'

module Delayed
class Worker
Expand Down
46 changes: 0 additions & 46 deletions spec/delayed_method_spec.rb

This file was deleted.

44 changes: 44 additions & 0 deletions spec/message_sending_spec.rb
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
60 changes: 24 additions & 36 deletions spec/performable_method_spec.rb
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
17 changes: 0 additions & 17 deletions spec/story_spec.rb

This file was deleted.

10 changes: 4 additions & 6 deletions spec/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ def job_create(opts = {})
end

describe "backend=" do
it "should set the Delayed::Job constant to the backend" do
before do
@clazz = Class.new
Delayed::Worker.backend = @clazz
end

it "should set the Delayed::Job constant to the backend" do
Delayed::Job.should == @clazz
end

it "should set backend with a symbol" do
Delayed::Worker.backend = Class.new
Delayed::Worker.backend = :active_record
Delayed::Worker.backend.should == Delayed::Backend::ActiveRecord::Job
end
Expand Down Expand Up @@ -51,8 +53,6 @@ def job_create(opts = {})
end

it "should only work_off jobs that are >= min_priority" do
SimpleJob.runs.should == 0

job_create(:priority => -10)
job_create(:priority => 0)
@worker.work_off
Expand All @@ -61,8 +61,6 @@ def job_create(opts = {})
end

it "should only work_off jobs that are <= max_priority" do
SimpleJob.runs.should == 0

job_create(:priority => 10)
job_create(:priority => 0)

Expand Down

0 comments on commit 69d6de4

Please sign in to comment.