throttling 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +4 -0
- data/CHANGELOG.md +20 -8
- data/Gemfile +1 -1
- data/Gemfile.lock +88 -0
- data/README.md +136 -109
- data/Rakefile +3 -3
- data/certs/kpumuk.pem +21 -0
- data/lib/throttling/base.rb +6 -6
- data/lib/throttling/indifferent_access.rb +31 -22
- data/lib/throttling/version.rb +1 -1
- data/lib/throttling.rb +14 -14
- data/throttling.gemspec +35 -20
- data.tar.gz.sig +2 -0
- metadata +82 -64
- metadata.gz.sig +0 -0
- data/.gitignore +0 -18
- data/Guardfile +0 -6
- data/spec/base_spec.rb +0 -181
- data/spec/fixtures/throttling.yml +0 -28
- data/spec/spec_helper.rb +0 -21
- data/spec/throttling_spec.rb +0 -103
data/spec/throttling_spec.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Throttling do
|
4
|
-
after :each do
|
5
|
-
Throttling.reset_defaults!
|
6
|
-
end
|
7
|
-
|
8
|
-
context 'with defaults' do
|
9
|
-
it 'should create logger' do
|
10
|
-
Throttling.logger.should be_a(Logger)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should be enabled' do
|
14
|
-
Throttling.enabled?.should be_true
|
15
|
-
Throttling.enabled.should be_true
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should set config file path' do
|
19
|
-
Throttling.limits_config.should == "#{Dir.pwd}/config/throttling.yml"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'setters' do
|
24
|
-
it 'should allow to enabled and disable client' do
|
25
|
-
Throttling.enabled = false
|
26
|
-
Throttling.should_not be_enabled
|
27
|
-
|
28
|
-
Throttling.enable!
|
29
|
-
Throttling.should be_enabled
|
30
|
-
|
31
|
-
Throttling.disable!
|
32
|
-
Throttling.should_not be_enabled
|
33
|
-
|
34
|
-
Throttling.enabled = true
|
35
|
-
Throttling.should be_enabled
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should allow to change logger' do
|
39
|
-
mock = Throttling.logger = mock('Logger')
|
40
|
-
Throttling.logger.should be(mock)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should allow to set limits' do
|
44
|
-
limits = { 'foo' => {'limit' => 5, 'period' => 2} }
|
45
|
-
Throttling.limits = limits
|
46
|
-
Throttling.limits.should == limits
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should allow to change config file path' do
|
50
|
-
path = File.expand_path('../fixtures/throttling.yml', __FILE__)
|
51
|
-
Throttling.limits_config = path
|
52
|
-
Throttling.limits_config.should == path
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '.for' do
|
57
|
-
it "should return a throttling class instance" do
|
58
|
-
Throttling.limits = { 'foo' => {'limit' => 5, 'period' => 2} }
|
59
|
-
Throttling.for('foo').should be_instance_of(Throttling::Base)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should raise an exception if no throttling_limits found in config" do
|
63
|
-
Throttling.limits = nil
|
64
|
-
lambda { Throttling.for('foo') }.should raise_error(ArgumentError)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should raise an exception if no throttling_limits[action] found in config" do
|
68
|
-
Throttling.limits = { 'foo' => nil }
|
69
|
-
lambda { Throttling.for('foo') }.should raise_error(ArgumentError)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'limits' do
|
74
|
-
context 'when set using .limits' do
|
75
|
-
it 'should convert Hash to HashWithIndifferentAccess' do
|
76
|
-
Throttling.limits = { 'foo' => {'limit' => 5, 'period' => 2} }
|
77
|
-
Throttling.limits.should have_key(:foo)
|
78
|
-
Throttling.limits.should have_key('foo')
|
79
|
-
Throttling.limits[:foo].should have_key(:limit)
|
80
|
-
Throttling.limits[:foo].should have_key('limit')
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'when set using .limits_config' do
|
85
|
-
before do
|
86
|
-
Throttling.limits_config = File.expand_path('../fixtures/throttling.yml', __FILE__)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should load limits from configuration file' do
|
90
|
-
Throttling.limits.should be_kind_of(Hash)
|
91
|
-
Throttling.limits.should have_key('search_requests')
|
92
|
-
Throttling.limits.should have_key('user_signup')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should convert Hash to HashWithIndifferentAccess' do
|
96
|
-
Throttling.limits.should have_key(:search_requests)
|
97
|
-
Throttling.limits.should have_key('search_requests')
|
98
|
-
Throttling.limits[:search_requests].should have_key(:daily)
|
99
|
-
Throttling.limits[:search_requests].should have_key('daily')
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|