rack-attack/spec/rack_attack_track_spec.rb
Aaron Suggs 80367e1e4a Add Rack::Attack.track.
track will fire notifications, but not alter request processing
2013-01-10 19:02:49 -05:00

44 lines
883 B
Ruby

require_relative 'spec_helper'
describe 'Rack::Attack.track' do
class Counter
def self.incr
@counter += 1
end
def self.reset
@counter = 0
end
def self.check
@counter
end
end
before do
Rack::Attack.track("everything"){ |req| true }
end
allow_ok_requests
it "should tag the env" do
get '/'
last_request.env['rack.attack.matched'].must_equal 'everything'
last_request.env['rack.attack.match_type'].must_equal :track
end
describe "with a notification subscriber and two tracks" do
before do
Counter.reset
# A second track
Rack::Attack.track("homepage"){ |req| req.path == "/"}
ActiveSupport::Notifications.subscribe("rack.attack") do |*args|
Counter.incr
end
get "/"
end
it "should notify twice" do
Counter.check.must_equal 2
end
end
end