Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Oops, fixes #1

  • Loading branch information...
commit b4d3c6577c624154842186ccf191bd3b2340a7fe 1 parent c20aeda
@leshill leshill authored
Showing with 29 additions and 2 deletions.
  1. +13 −2 lib/resque_spec/resque_spec.rb
  2. +16 −0 spec/resque_spec_spec.rb
View
15 lib/resque_spec/resque_spec.rb
@@ -13,8 +13,9 @@ def queue_for(klass)
end
def queue_name(klass)
- queue_name = klass.instance_variable_get(:@queue) || klass.respond_to?(:queue) && klass.queue
- raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.") unless queue_name
+ name_from_instance_var(klass) or
+ name_from_queue_accessor(klass) or
+ raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.")
end
def queues
@@ -30,6 +31,16 @@ def enqueue(klass, *args)
ResqueSpec.queue_for(klass) << {:klass => klass, :args => args}
end
end
+
+ private
+
+ def name_from_instance_var(klass)
+ klass.instance_variable_get(:@queue)
+ end
+
+ def name_from_queue_accessor(klass)
+ klass.respond_to?(:queue) and klass.queue
+ end
end
Resque.extend(ResqueSpec::Resque)
View
16 spec/resque_spec_spec.rb
@@ -37,6 +37,22 @@
end
end
+ describe "#queue_name" do
+ it "raises if there is no queue defined for a class" do
+ expect do
+ ResqueSpec.queue_name(Address)
+ end.should raise_error(::Resque::NoQueueError)
+ end
+
+ it "returns the queue name if there is a queue defined as an instance var" do
+ ResqueSpec.queue_name(Person).should == :people
+ end
+
+ it "returns the queue name if there is a queue defined via self.queue" do
+ ResqueSpec.queue_name(Account).should == :people
+ end
+ end
+
describe "#reset!" do
it "clears the queues" do
ResqueSpec.queue_for(Person) << 'queued'
Please sign in to comment.
Something went wrong with that request. Please try again.