throttling 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ ## 0.2.0 (April 12, 2012)
2
+
3
+ Bugfixes:
4
+
5
+ - Fixed bug when occurrences where increased for larger periods, when smaller ones did not pass
6
+
7
+ ## 0.1.0 (April 12, 2012)
8
+
9
+ Features:
10
+
11
+ - Allows to throttle actions occurred in period of time
12
+ - Allows to specify limits inline or in external configuration file
13
+ - 100% test coverage
@@ -12,7 +12,9 @@ module Throttling
12
12
 
13
13
  # Convert simple limits to a hash
14
14
  if @limits[:limit] && @limits[:period]
15
- @limits = { 'global' => @limits }
15
+ @limits = [[ 'global', @limits ]]
16
+ else
17
+ @limits = @limits.sort_by { |name, params| params && params[:period] }
16
18
  end
17
19
  end
18
20
 
@@ -1,3 +1,3 @@
1
1
  module Throttling
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
@@ -71,18 +71,30 @@ describe Throttling do
71
71
 
72
72
  describe 'with multi-level limits' do
73
73
  before do
74
- Throttling.limits = { 'foo' => { 'one' => { 'limit' => 5, 'period' => 2 }, 'two' => { 'limit' => 10, 'period' => 20 } } }
74
+ Throttling.limits = { 'foo' => { 'two' => { 'limit' => 10, 'period' => 20 }, 'one' => { 'limit' => 5, 'period' => 2 } } }
75
75
  end
76
76
 
77
- it "should return false if at least one limit is reached" do
77
+ it 'should return false if at least one limit is reached' do
78
78
  @storage.should_receive(:fetch).and_return(1, 100)
79
79
  Throttling.for('foo').check_ip('127.0.0.1').should be_false
80
80
  end
81
81
 
82
- it "should return true if none limits reached" do
82
+ it 'should return true if none limits reached' do
83
83
  @storage.should_receive(:fetch).and_return(1, 2)
84
84
  Throttling.for('foo').check_ip('127.0.0.1').should be_true
85
85
  end
86
+
87
+ it 'should sort limits by period' do
88
+ @storage.should_receive(:fetch).ordered.with(/\:one\:/, anything).and_return(0)
89
+ @storage.should_receive(:fetch).ordered.with(/\:two\:/, anything).and_return(0)
90
+ Throttling.for('foo').check_ip('127.0.0.1').should be_true
91
+ end
92
+
93
+ it 'should return as soon as limit reached' do
94
+ @storage.should_receive(:fetch).ordered.with(/\:one\:/, anything).and_return(10)
95
+ @storage.should_not_receive(:fetch).with(/\:two\:/)
96
+ Throttling.for('foo').check_ip('127.0.0.1').should be_false
97
+ end
86
98
  end
87
99
 
88
100
  context do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: throttling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70193684278040 !ruby/object:Gem::Requirement
17
+ requirement: &70166425496360 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70193684278040
25
+ version_requirements: *70166425496360
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70193684277620 !ruby/object:Gem::Requirement
28
+ requirement: &70166425495940 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70193684277620
36
+ version_requirements: *70166425495940
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: timecop
39
- requirement: &70193684277200 !ruby/object:Gem::Requirement
39
+ requirement: &70166425495520 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70193684277200
47
+ version_requirements: *70166425495520
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: guard-rspec
50
- requirement: &70193684276780 !ruby/object:Gem::Requirement
50
+ requirement: &70166425495100 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70193684276780
58
+ version_requirements: *70166425495100
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rb-fsevent
61
- requirement: &70193684276360 !ruby/object:Gem::Requirement
61
+ requirement: &70166425494680 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70193684276360
69
+ version_requirements: *70166425494680
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: growl
72
- requirement: &70193684275940 !ruby/object:Gem::Requirement
72
+ requirement: &70166425494260 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70193684275940
80
+ version_requirements: *70166425494260
81
81
  description: Throttling gem provides basic, but very powerful way to throttle various
82
82
  user actions in your application
83
83
  email:
@@ -88,6 +88,7 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - .gitignore
90
90
  - .travis.yml
91
+ - CHANGELOG.md
91
92
  - Gemfile
92
93
  - Guardfile
93
94
  - LICENSE