Sha256: 21a8caa79cceccfb32910667f81373321e5eb262ef7395063c62b10b0591a100

Contents?: true

Size: 884 Bytes

Versions: 2

Compression:

Stored size: 884 Bytes

Contents

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

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

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

  it "should not bother checking if the path doesn't match the rule" do
    expect(app).not_to receive(:allowed?)
    get "/foo"
    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)
    header 'User-Agent', 'blahdeblah GoogleBot owns your soul'
    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:ua-/google/i"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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