Sha256: faffb7e16c662f6a67dc6f94da5dbb52fbe3bbc73bdef6bee53a3069e00fcf26

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

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

class ThrottledJobTest < Test::Unit::TestCase

  context "Resque::ThrottledJob" do
    should "instantiate a new Resque::ThrottledJob" do
      assert Resque::ThrottledJob.new
    end

    context "settings" do
      context "#can_run_every" do
        should "return the number of seconds in which to throttle these jobs" do
          assert_equal 3600, OneHourThrottledJob.can_run_every
        end

        should "default to 30 minutes (1800 seconds) if not provided" do
          assert_equal 1800, DefaultThrottledJob.can_run_every
        end
      end

      context "#identifier" do
        should "return an additional key identifier used in storing the key in the redis SET" do
          assert_equal "my_identifier", IdentifierThrottledJob.identifier("identifier")
        end

        should "return nil if not defined" do
          assert_nil DefaultThrottledJob.identifier
        end
      end

      context "#disabled" do
        should "not be disabled by default" do
          assert !DefaultThrottledJob.disabled
        end

        should "be able to be overriden" do
          assert DisabledThrottledJob.disabled
        end
      end
    end

    context "#key" do
      should "consist of a prefix, the class name and the identifier" do
        assert_equal(
          "resque-throttle:IdentifierThrottledJob:my_identifier", 
          IdentifierThrottledJob.key("identifier")
        )
      end

      should "consist of just the module prefix and the class name if the identifier is not provided" do
        assert_equal(
          "resque-throttle:DefaultThrottledJob", DefaultThrottledJob.key
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fhwang-resque-throttle-0.3.0 test/resque/throttled_job_test.rb