Sha256: 17d809e452d0e7e2646b39f7f2dec4d65b80bafcf5c1c0dbb758d23f27643b25

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require 'rubygems'
require 'mocha'

dir = File.dirname(__FILE__)
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
require 'resque-restriction'

#
# make sure we can run redis
#

if !system("which redis-server")
  puts '', "** can't find `redis-server` in your path"
  puts "** try running `sudo rake install`"
  abort ''
end


#
# start our own redis when the tests start,
# kill it when they end
#

at_exit do
  next if $!

  exit_code = Spec::Runner.run

  pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
  puts "Killing test redis server [#{pid}]..."
  `rm -f #{dir}/dump.rdb`
  Process.kill("KILL", pid.to_i)
  exit exit_code
end

puts "Starting redis for testing at localhost:9736..."
`redis-server #{dir}/redis-test.conf`
Resque.redis = 'localhost:9736'

#
# Helper to perform job classes
#
module PerformJob
  def perform_job(klass, *args)
    klass.perform_now(*args)
  end
end

class OneDayRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_day => 100

  queue_as 'normal'

  def perform(args)
  end
end

class OneHourRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10

  queue_as 'normal'

  def perform(args)
  end
end

class IdentifiedRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10

  queue_as 'normal'

  def self.restriction_identifier(*args)
    [self.to_s, args.first].join(":")
  end

  def perform(args)
  end
end

class ConcurrentRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :concurrent => 1

  queue_as 'normal'

  def perform(args)
    sleep 0.2
  end
end

class MultipleRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10, :per_300 => 2

  queue_as 'normal'

  def perform(args)
  end
end

class MultiCallRestrictionJob < Resque::Plugins::RestrictionJob
  restrict :per_hour => 10
  restrict :per_300 => 2

  queue_as 'normal'

  def perform(args)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
resque-restriction-0.4.2 spec/spec_helper.rb
resque-restriction-0.4.0 spec/spec_helper.rb