Sha256: 8439c087c2e0dc04866caaae64a165bf14d9525edbf837b083971f44bbe45d33

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'
require 'resque/rate_limited_queue'

class RateLimitedTestQueueAL
  def self.perform(succeed)
    raise(AngellistApi::Error::TooManyRequests, 'error') unless succeed
  end
end

describe Resque::Plugins::RateLimitedQueue::AngellistQueue do
  before do
    Resque::Plugins::RateLimitedQueue::AngellistQueue.stub(:paused?).and_return(false)
  end

  describe 'enqueue' do
    it 'enqueues to the correct queue with the correct parameters' do
      Resque.should_receive(:enqueue_to).with(
        :angellist_api,
        Resque::Plugins::RateLimitedQueue::AngellistQueue,
        RateLimitedTestQueueAL.to_s,
        true)
      Resque::Plugins::RateLimitedQueue::AngellistQueue
        .enqueue(RateLimitedTestQueueAL, true)
    end
  end

  describe 'perform' do
    before do
      Resque.inline = true
    end
    context 'with everything' do
      it 'calls the class with the right parameters' do
        RateLimitedTestQueueAL.should_receive(:perform).with('test_param')
        Resque::Plugins::RateLimitedQueue::AngellistQueue
          .enqueue(RateLimitedTestQueueAL, 'test_param')
      end
    end

    context 'with rate limit exception' do
      before do
        Resque::Plugins::RateLimitedQueue::AngellistQueue.stub(:rate_limited_requeue)
      end
      it 'pauses queue when request fails' do
        Resque::Plugins::RateLimitedQueue::AngellistQueue.should_receive(:pause_for)
        Resque::Plugins::RateLimitedQueue::AngellistQueue
          .enqueue(RateLimitedTestQueueAL, false)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resque-rate_limited_queue-0.0.34 spec/apis/angellist_queue_spec.rb
resque-rate_limited_queue-0.0.33 spec/apis/angellist_queue_spec.rb
resque-rate_limited_queue-0.0.32 spec/apis/angellist_queue_spec.rb