prop 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/prop.rb +1 -1
- data/lib/prop/limiter.rb +2 -1
- data/prop.gemspec +1 -1
- data/test/test_limiter.rb +10 -0
- metadata +3 -3
data/lib/prop.rb
CHANGED
data/lib/prop/limiter.rb
CHANGED
@@ -57,7 +57,8 @@ module Prop
|
|
57
57
|
if at_threshold?(counter, options[:threshold])
|
58
58
|
raise Prop::RateLimited.new(options.merge(:cache_key => cache_key, :handle => handle))
|
59
59
|
else
|
60
|
-
|
60
|
+
increment = options.key?(:increment) ? options[:increment].to_i : 1
|
61
|
+
counter = writer.call(cache_key, counter + increment)
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
data/prop.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'prop'
|
16
|
-
s.version = '0.7.
|
16
|
+
s.version = '0.7.6'
|
17
17
|
s.date = '2012-04-06'
|
18
18
|
s.rubyforge_project = 'prop'
|
19
19
|
|
data/test/test_limiter.rb
CHANGED
@@ -51,6 +51,12 @@ class TestLimiter < Test::Unit::TestCase
|
|
51
51
|
should "raise Prop::RateLimited" do
|
52
52
|
assert_raises(Prop::RateLimited) { Prop.throttle!(:something) { "wibble" }}
|
53
53
|
end
|
54
|
+
|
55
|
+
should "raise even if given :increment => 0" do
|
56
|
+
value = Prop.count(:something)
|
57
|
+
assert_raises(Prop::RateLimited) { Prop.throttle!(:something, nil, :increment => 0) { "wibble" }}
|
58
|
+
assert_equal value, Prop.count(:something)
|
59
|
+
end
|
54
60
|
end
|
55
61
|
|
56
62
|
context "not given a block" do
|
@@ -75,6 +81,10 @@ class TestLimiter < Test::Unit::TestCase
|
|
75
81
|
should "return the updated throttle count" do
|
76
82
|
assert_equal Prop.count(:something) + 1, Prop.throttle!(:something)
|
77
83
|
end
|
84
|
+
|
85
|
+
should "not update count if passed an increment of 0" do
|
86
|
+
assert_equal Prop.count(:something), Prop.throttle!(:something, nil, :increment => 0)
|
87
|
+
end
|
78
88
|
end
|
79
89
|
end
|
80
90
|
end
|
metadata
CHANGED