Skip to content

Commit

Permalink
Merge d3a89da into f8e3141
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Apr 7, 2014
2 parents f8e3141 + d3a89da commit 57eaf07
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ script: "bundle exec rake test"
rvm:
- 1.9.2
- 1.9.3
- rbx-19mode
- rbx
- jruby
- 2.0.0
- 2.1.1
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ group :test do
gem "shoulda", ">= 0"
gem "timecop"
gem "mocha", "~> 0.10"
gem "mock_redis", "~> 0.2.0"
gem "mock_redis", "~> 0.11.0"
gem "rake"
gem 'coveralls', require: false
end
74 changes: 46 additions & 28 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,45 +1,63 @@
GEM
remote: http://rubygems.org/
specs:
colorize (0.5.8)
coveralls (0.6.7)
colorize
activesupport (4.0.4)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
git (1.2.5)
docile (1.1.3)
git (1.2.6)
i18n (0.6.9)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
json (1.6.1)
json (1.6.1-java)
maruku (0.6.1)
syntax (>= 1.0.0)
metaclass (0.0.1)
mime-types (1.24)
mocha (0.10.0)
json (1.8.1)
json (1.8.1-java)
maruku (0.7.1)
metaclass (0.0.4)
mime-types (2.2)
minitest (4.7.5)
mocha (0.14.0)
metaclass (~> 0.0.1)
mock_redis (0.2.0)
multi_json (1.7.9)
rake (0.9.2)
rdoc (3.11)
mock_redis (0.11.0)
multi_json (1.9.2)
rake (10.2.2)
rdoc (4.1.1)
json (~> 1.4)
redis (2.2.2)
redis-namespace (1.1.0)
redis (< 3.0.0)
redis (3.0.7)
redis-namespace (1.4.1)
redis (~> 3.0.4)
rest-client (1.6.7)
mime-types (>= 1.16)
shoulda (2.11.3)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
syntax (1.0.0)
thor (0.18.1)
timecop (0.3.5)
yard (0.7.3)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.5.0)
activesupport (>= 3.0.0)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
thread_safe (0.3.3)
thread_safe (0.3.3-java)
timecop (0.7.1)
tins (1.1.0)
tzinfo (0.3.39)
yard (0.8.7.4)

PLATFORMS
java
Expand All @@ -50,7 +68,7 @@ DEPENDENCIES
jeweler (~> 1.6.4)
maruku
mocha (~> 0.10)
mock_redis (~> 0.2.0)
mock_redis (~> 0.11.0)
rake
rdoc
redis
Expand Down
4 changes: 3 additions & 1 deletion lib/ratelimit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def initialize(key, options = {})
#
# @param [String] subject A unique key to identify the subject. For example, 'user@foo.com'
# @param [Integer] count The number by which to increase the counter
#
# @return [Integer] The counter value
def add(subject, count = 1)
bucket = get_bucket
subject = "#{@key}:#{subject}"
Expand All @@ -41,7 +43,7 @@ def add(subject, count = 1)
redis.hdel(subject, (bucket + 1) % @bucket_count)
redis.hdel(subject, (bucket + 2) % @bucket_count)
redis.expire(subject, @bucket_expiry)
end
end.first
end

# Returns the count for a given subject and interval
Expand Down
5 changes: 5 additions & 0 deletions test/test_ratelimit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def setup
end
end

should "return counter value" do
r = @r.add("value1")
assert_equal @r.count("value1", 1), r
end

should "respond to exceeded? method correctly" do
5.times do
@r.add("value1")
Expand Down

0 comments on commit 57eaf07

Please sign in to comment.