Changed track checker to track filter. Made track filter tests more clear.

This commit is contained in:
Paul Coates 2014-05-22 10:11:23 -07:00
parent 1857f8dd57
commit e8d98a7ad3
2 changed files with 8 additions and 8 deletions

View file

@ -3,19 +3,19 @@ module Rack
class Track
extend Forwardable
attr_reader :checker
attr_reader :filter
def initialize(name, options = {}, block)
options[:type] = :track
if options[:limit] && options[:period]
@checker = Throttle.new(name, options, block)
@filter = Throttle.new(name, options, block)
else
@checker = Check.new(name, options, block)
@filter = Check.new(name, options, block)
end
end
def_delegator :@checker, :[], :[]
def_delegator :@filter, :[]
end
end
end

View file

@ -43,16 +43,16 @@ describe 'Rack::Attack.track' do
end
describe "without limit and period options" do
it "should delegate [] to check" do
it "should assign the track filter to a Check instance" do
tracker = Rack::Attack.track("homepage") { |req| req.path == "/"}
tracker.checker.class.must_equal Rack::Attack::Check
tracker.filter.class.must_equal Rack::Attack::Check
end
end
describe "with limit and period options" do
it "should delegate [] method to throttle" do
it "should assign the track filter to a Throttle instance" do
tracker = Rack::Attack.track("homepage", :limit => 10, :period => 10) { |req| req.path == "/"}
tracker.checker.class.must_equal Rack::Attack::Throttle
tracker.filter.class.must_equal Rack::Attack::Throttle
end
end
end