Skip to content

Commit

Permalink
Ensure enqueued classes pass Resque validation. Fixes danp#1
Browse files Browse the repository at this point in the history
  • Loading branch information
danp committed Jun 27, 2011
1 parent f774ec1 commit d452dc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/resque/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def enqueue_in(delay, klass, *args)
end

def defer(klass, args, delay = nil)
validate(klass)

if @async
add_job('payload' => { 'class' => klass, 'args' => args }, 'delay' => delay)
else
Expand Down
17 changes: 16 additions & 1 deletion spec/mock_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#require 'spec_helper'
require 'resque/mock'

Resque.mock!

class Performer
def self.queue
'performings'
end

def self.run?
!!@args
end
Expand Down Expand Up @@ -41,10 +44,22 @@ def self.perform(*args)
end
end

class QueuelessPerformer < Performer
class << self
undef :queue
end
end

describe Resque do
before { Performer.reset! }

describe "synchronously" do
it "ensures the queue can be determined" do
expect {
Resque.enqueue(QueuelessPerformer, 'hello', 'there')
}.to raise_error(Resque::NoQueueError)
end

it "performs jobs without delay" do
Resque.enqueue(Performer, 'hello', 'there')
Performer.should be_run
Expand Down

0 comments on commit d452dc0

Please sign in to comment.