Sha256: d5da7bf9f91edd5da927e548e3aab210a30f2921eb06c2d54d31cca932978c9e

Contents?: true

Size: 1.45 KB

Versions: 22

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe Object do
  before       { Delayed::Job.delete_all }

  it "should call #delay 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.first
    job.payload_object.class.should   == Delayed::PerformableMethod
    job.payload_object.method.should  == :whatever_without_delay
    job.payload_object.args.should    == [1, 5]
    job.payload_object.perform.should == 'Once upon...'
  end

  context "delay" do
    it "should raise a ArgumentError if target method doesn't exist" do
      lambda { Object.new.delay.method_that_does_not_exist }.should raise_error(NoMethodError)
    end

    it "should add a new entry to the job table when delay is called on it" do
      lambda { Object.new.delay.to_s }.should change { Delayed::Job.count }.by(1)
    end

    it "should add a new entry to the job table when delay is called on the class" do
      lambda { Object.delay.to_s }.should change { Delayed::Job.count }.by(1)
    end
    
    it "should set job options" do
      run_at = 1.day.from_now
      job = Object.delay(:priority => 20, :run_at => run_at).to_s
      job.run_at.should == run_at
      job.priority.should == 20
    end
    
    it "should save args for original method" do
      job = 3.delay.+(5)
      job.payload_object.args.should == [5]
    end
  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
delayed_job-2.0.8 spec/delayed_method_spec.rb
delayed_job_csi-2.0.7 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.14 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.13 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.12 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.11 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.10 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.9 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.8 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.7 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.6 spec/delayed_method_spec.rb
delayed-job-ajaycb-2.0.10 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.5 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.4 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.3 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.2 spec/delayed_method_spec.rb
delayed_job_with_named_queues-2.0.7.1 spec/delayed_method_spec.rb
yetanothernguyen-delayed_job-0.0.1 spec/delayed_method_spec.rb
delayed_job-2.0.7 spec/delayed_method_spec.rb
delayed_job-2.0.6 spec/delayed_method_spec.rb