Sha256: 6322209bdf79e3920a44a219c7ccd363b7c84a349346f9e786fdb9238a010094

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

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

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

  def app
    @target_app ||= example_target_app
    @app ||= Rack::Throttle::Limiter.new(@target_app)
  end

  describe "basic calling" do
    it "should return the example app" do
      get "/foo"
      expect(last_response.body).to show_allowed_response
    end

    it "should call the application if allowed" do
      expect(app).to receive(:allowed?).and_return(true)
      get "/foo"
      expect(last_response.body).to show_allowed_response
    end

    it "should give a rate limit exceeded message if not allowed" do
      expect(app).to receive(:allowed?).and_return(false)
      get "/foo"
      expect(last_response.body).to show_throttled_response
    end
  end

  describe "allowed?" do
    it "should return true if whitelisted" do
      expect(app).to receive(:whitelisted?).and_return(true)
      get "/foo"
      expect(last_response.body).to show_allowed_response
    end

    it "should return false if blacklisted" do
      expect(app).to receive(:blacklisted?).and_return(true)
      get "/foo"
      expect(last_response.body).to show_throttled_response
    end

    it "should return true if not whitelisted or blacklisted" do
      expect(app).to receive(:whitelisted?).and_return(false)
      expect(app).to receive(:blacklisted?).and_return(false)
      get "/foo"
      expect(last_response.body).to show_allowed_response
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
improved-rack-throttle-0.9.0 spec/limiters/limiter_spec.rb
improved-rack-throttle-0.8.0 spec/limiters/limiter_spec.rb