Sha256: cd814da151793f4ba82ab9c5394616f200498ba9d6a1b276fc7ec21f50487b34

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

require File.dirname(__FILE__) + '/test_helper'
require File.dirname(__FILE__) + '/../lib/sweat_shop'

class SweatShopTest < Test::Unit::TestCase
  SweatShop.workers = []

  class HelloWorker < SweatShop::Worker
    def hello(name)
      "Hi, #{name}"
    end
  end

  class GroupedWorker < SweatShop::Worker
    queue_group :foo
  end

  test "group workers" do
    assert_equal [HelloWorker, GroupedWorker], SweatShop.workers_in_group(:all)
    assert_equal [HelloWorker],   SweatShop.workers_in_group(:default)
    assert_equal [GroupedWorker], SweatShop.workers_in_group(:foo)
  end

  test "synch call" do
    worker = HelloWorker.new
    assert_equal "Hi, Amos", worker.hello('Amos')
  end

  test "uid" do
    SweatShop.logger = :silent
    uid = HelloWorker.async_hello('Amos')
    assert_not_nil uid
  end

  test "before task" do
    HelloWorker.before_task do
      "hello"
    end
    assert_equal "hello", HelloWorker.before_task.call
  end

  test "after task" do
    HelloWorker.after_task do
      "goodbye"
    end
    assert_equal "goodbye", HelloWorker.after_task.call
  end

  test "chainable before tasks" do
    MESSAGES = []
    class BaseWorker < SweatShop::Worker
      before_task do |task|
        MESSAGES << 'base'
      end
    end
    class SubWorker < BaseWorker
      before_task do |task|
        MESSAGES << 'sub'
      end
    end
    SubWorker.call_before_task('foo')
    assert_equal ['base', 'sub'], MESSAGES
    SweatShop.workers.delete(BaseWorker)
    SweatShop.workers.delete(SubWorker)
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
Bira-sweat_shop-1.0.0 test/test_sweatshop.rb
famoseagle-sweat_shop-0.5.0 test/test_sweatshop.rb
famoseagle-sweat_shop-0.6.0 test/test_sweatshop.rb
famoseagle-sweat_shop-0.7.0 test/test_sweatshop.rb
famoseagle-sweat_shop-0.8.0 test/test_sweatshop.rb
famoseagle-sweat_shop-0.8.1 test/test_sweatshop.rb
famoseagle-sweat_shop-0.8.2 test/test_sweatshop.rb
famoseagle-sweat_shop-1.0.0 test/test_sweatshop.rb
famoseagle-sweat_shop-1.1.0 test/test_sweatshop.rb
famoseagle-sweat_shop-1.2.0 test/test_sweatshop.rb
famoseagle-sweat_shop-1.3.0 test/test_sweatshop.rb
famoseagle-sweat_shop-1.3.1 test/test_sweatshop.rb
netinlet-sweat_shop-1.1.0 test/test_sweatshop.rb
netinlet-sweat_shop-1.1.1 test/test_sweatshop.rb