Sha256: 92a3411f81e111080750fef0ccf13b91b45db1c9a93d83feea5740d8c4301235

Contents?: true

Size: 802 Bytes

Versions: 2

Compression:

Stored size: 802 Bytes

Contents

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

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

  def app
    @target_app ||= example_target_app
    @app ||= Rack::Throttle::Limiter.new(@target_app, :rules => {:url => /foo/})
  end

  it "should not bother checking if the path doesn't match the rule" do
    expect(app).not_to receive(:allowed?)
    get "/bar"
    expect(last_response.body).to show_allowed_response
  end

  it "should check if the path matches the rule" do
    expect(app).to receive(:allowed?).and_return(false)
    get "/foo"
    expect(last_response.body).to show_throttled_response
  end

  it "should append the rule to the cache key" do
    get "/foo"
    expect(app.send(:cache_key, last_request)).to eq "127.0.0.1:url-/foo/"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
improved-rack-throttle-0.9.0 spec/matchers/url_matcher_spec.rb
improved-rack-throttle-0.8.0 spec/matchers/url_matcher_spec.rb