Skip to content

Commit 7860a82

Browse files
authored
Merge pull request rack#187 from mferrier/spec-throttle-block-nil
add a spec to specify the behavior of non-matching throttle blocks
2 parents 88e3ed0 + 031efcd commit 7860a82

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/rack_attack_throttle_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,25 @@
8585
end
8686
end
8787
end
88+
89+
describe 'Rack::Attack.throttle with block retuning nil' do
90+
before do
91+
@period = 60
92+
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
93+
Rack::Attack.throttle('ip/sec', :limit => 1, :period => @period) { |_| nil }
94+
end
95+
96+
allow_ok_requests
97+
98+
describe 'a single request' do
99+
before { get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' }
100+
it 'should not set the counter' do
101+
key = "rack::attack:#{Time.now.to_i/@period}:ip/sec:1.2.3.4"
102+
Rack::Attack.cache.store.read(key).must_equal nil
103+
end
104+
105+
it 'should not populate throttle data' do
106+
last_request.env['rack.attack.throttle_data'].must_equal nil
107+
end
108+
end
109+
end

0 commit comments

Comments
 (0)