forked from dryruby/rack-throttle
/
limiter_spec.rb
50 lines (42 loc) · 1.41 KB
/
limiter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require File.dirname(__FILE__) + '/spec_helper'
def app
@target_app ||= example_target_app
@app ||= Rack::Throttle::Limiter.new(@target_app)
end
describe Rack::Throttle::Limiter do
include Rack::Test::Methods
describe "basic calling" do
it "should return the example app" do
get "/foo"
last_response.body.should show_allowed_response
end
it "should call the application if allowed" do
app.should_receive(:allowed?).and_return(true)
get "/foo"
last_response.body.should show_allowed_response
end
it "should give a rate limit exceeded message if not allowed" do
app.should_receive(:allowed?).and_return(false)
get "/foo"
last_response.body.should show_throttled_response
end
end
describe "allowed?" do
it "should return true if whitelisted" do
app.should_receive(:whitelisted?).and_return(true)
get "/foo"
last_response.body.should show_allowed_response
end
it "should return false if blacklisted" do
app.should_receive(:blacklisted?).and_return(true)
get "/foo"
last_response.body.should show_throttled_response
end
it "should return true if not whitelisted or blacklisted" do
app.should_receive(:whitelisted?).and_return(false)
app.should_receive(:blacklisted?).and_return(false)
get "/foo"
last_response.body.should show_allowed_response
end
end
end