Sha256: bc3eb58f24110ac55c927de796967562997ef1d3ebfbd6319f7e59807acdfb24

Contents?: true

Size: 792 Bytes

Versions: 2

Compression:

Stored size: 792 Bytes

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Rack::Throttle::Hourly do
  include Rack::Test::Methods

  def app
    @target_app ||= example_target_app
    @app ||= Rack::Throttle::Hourly.new(@target_app, :max_per_hour => 3)
  end

  it "should be allowed if not seen this hour" do
    get "/foo"
    last_response.body.should show_allowed_response
  end
  
  it "should be allowed if seen fewer than the max allowed per hour" do
    2.times { get "/foo" }
    last_response.body.should show_allowed_response
  end
  
  it "should not be allowed if seen more times than the max allowed per hour" do
    4.times { get "/foo" }
    last_response.body.should show_throttled_response
  end
  
  # TODO mess with time travelling and requests to make sure no overlap
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
improved-rack-throttle-0.7.1 spec/limiters/hourly_spec.rb
improved-rack-throttle-0.7.0 spec/limiters/hourly_spec.rb