Permalink
Browse files

Merge branch 'master' of github.com:wireframe/backgrounded

  • Loading branch information...
2 parents 2294e84 + 930824f commit c235b5843be0b9d0055e86067bc0149349d5cbdc Ryan Sonnek committed Jan 18, 2012
Showing with 26 additions and 1 deletion.
  1. +1 −1 lib/backgrounded/handler/resque_handler.rb
  2. +25 −0 test/backgrounded/handler/resque_handler_test.rb
@@ -23,7 +23,7 @@ def self.perform(clazz, id, method, *args)
private
def self.find_instance(clazz, id, method)
clazz = clazz.constantize
- clazz.respond_to?(method) ? clazz : clazz.find(id)
+ id.to_i == -1 ? clazz : clazz.find(id)
end
def instance_identifiers(object)
instance, id = if object.is_a?(Class)
@@ -3,6 +3,10 @@
require 'resque_unit'
ActiveRecord::Schema.define(:version => 1) do
+ create_table :blogs, :force => true do |t|
+ t.column :name, :string
+ end
+
create_table :users, :force => true do |t|
t.column :name, :string
end
@@ -34,6 +38,9 @@ class << self
def do_stuff
end
end
+ backgrounded :do_stuff
+ def do_stuff
+ end
end
context 'when backgrounded is configured with resque' do
@@ -60,6 +67,24 @@ def do_stuff
should "invoke method on class" do end #see expectations
end
end
+ context 'with an instance level backgrounded method of the same name' do
+ setup do
+ @blog = Blog.create
+ @blog.do_stuff_backgrounded
+ end
+ should "enqueue instance method job to resque" do
+ assert_queued Backgrounded::Handler::ResqueHandler, [Blog.to_s, @blog.id, 'do_stuff']
+ assert_equal Backgrounded::Handler::ResqueHandler::DEFAULT_QUEUE, Resque.queue_from_class(Backgrounded::Handler::ResqueHandler)
+ end
+ context "running background job" do
+ setup do
+ Blog.expects(:do_stuff).never
+ Blog.any_instance.expects(:do_stuff)
+ Resque.run!
+ end
+ should "invoke method on instance" do end #see expectations
+ end
+ end
end
context 'a persisted object with a single backgrounded method' do

0 comments on commit c235b58

Please sign in to comment.