Sha256: b1c0ee0c6df33257a79c0dce8252241dd3956547df4cefdebbd92b8e2dd62765

Contents?: true

Size: 809 Bytes

Versions: 2

Compression:

Stored size: 809 Bytes

Contents

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

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

  def app
    @target_app ||= example_target_app
    @app ||= Rack::Throttle::Limiter.new(@target_app, :rules => {:method => :post})
  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)
    post "/foo"
    expect(last_response.body).to show_throttled_response
  end

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

Version data entries

2 entries across 2 versions & 1 rubygems

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