Sha256: dc0bc60bc60ff3ce7c52a4abe310a43bb937f95959d2a9dc8773ffad8f77b82e

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'
require 'resque/rate_limited_queue'

class RateLimitedTestQueueAL
  def self.perform(succeed)
    fail(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_until)
        Resque::Plugins::RateLimitedQueue::AngellistQueue
          .enqueue(RateLimitedTestQueueAL, false)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resque-rate_limited_queue-1.0.4 spec/apis/angellist_queue_spec.rb