spec/resque-restriction/job_spec.rb in resque-restriction-0.2.1 vs spec/resque-restriction/job_spec.rb in resque-restriction-0.2.2

- old
+ new

@@ -1,26 +1,39 @@ require File.join(File.dirname(__FILE__) + '/../spec_helper') describe Resque::Job do - it "should repush restriction queue when reserve" do + before(:each) do Resque.redis.flushall - Resque.push('restriction', :class => 'OneHourRestrictionJob', :args => ['any args']) - Resque::Job.reserve('restriction').should be_nil - Resque::Job.reserve('normal').should == Resque::Job.new('normal', {'class' => 'OneHourRestrictionJob', 'args' => ['any args']}) + end + + it "should repush restriction queue when reserve" do + Resque.push('restriction_normal', :class => 'OneHourRestrictionJob', :args => ['any args']) + Resque::Job.reserve('restriction_normal').should == Resque::Job.new('restriction_normal', {'class' => 'OneHourRestrictionJob', 'args' => ['any args']}) + Resque::Job.reserve('restriction_normal').should be_nil Resque::Job.reserve('normal').should be_nil end it "should push back to restriction queue when still restricted" do - Resque.redis.flushall Resque.redis.set(OneHourRestrictionJob.redis_key(:per_hour), -1) - Resque.push('restriction', :class => 'OneHourRestrictionJob', :args => ['any args']) - Resque::Job.reserve('restriction').should be_nil - Resque.pop('restriction').should == {'class' => 'OneHourRestrictionJob', 'args' => ['any args']} + Resque.push('restriction_normal', :class => 'OneHourRestrictionJob', :args => ['any args']) + Resque::Job.reserve('restriction_normal').should be_nil + Resque.pop('restriction_normal').should == {'class' => 'OneHourRestrictionJob', 'args' => ['any args']} Resque::Job.reserve('normal').should be_nil end it "should not repush when reserve normal queue" do Resque.push('normal', :class => 'OneHourRestrictionJob', :args => ['any args']) Resque::Job.reserve('normal').should == Resque::Job.new('normal', {'class' => 'OneHourRestrictionJob', 'args' => ['any args']}) Resque::Job.reserve('normal').should be_nil + Resque::Job.reserve('restriction_normal').should be_nil end + + it "should only push back queue_length times to restriction queue" do + Resque.redis.set(OneHourRestrictionJob.redis_key(:per_hour), -1) + 3.times { Resque.push('restriction_normal', :class => 'OneHourRestrictionJob', :args => ['any args']) } + Resque.size('restriction_normal').should == 3 + OneHourRestrictionJob.should_receive(:repush).exactly(3).times.and_return(true) + Resque::Job.reserve('restriction_normal') + end + + end