Skip to content

Commit 4530a56

Browse files
committed
RateLimiting Cleanups
Followup: rails#50781 Some small issues I failed to address in the original PR.
1 parent 8f386d7 commit 4530a56

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

actionpack/test/controller/rate_limiting_test.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
class RateLimitedController < ActionController::Base
66
self.cache_store = ActiveSupport::Cache::MemoryStore.new
7-
rate_limit to: 2, within: 2.seconds, by: -> { Thread.current[:redis_test_seggregation] }, only: :limited_to_two
7+
rate_limit to: 2, within: 2.seconds, only: :limited_to_two
88

99
def limited_to_two
1010
head :ok
1111
end
1212

13-
rate_limit to: 2, within: 2.seconds, by: -> { Thread.current[:redis_test_seggregation] }, with: -> { head :forbidden }, only: :limited_with
13+
rate_limit to: 2, within: 2.seconds, by: -> { params[:rate_limit_key] }, with: -> { head :forbidden }, only: :limited_with
1414
def limited_with
1515
head :ok
1616
end
@@ -44,6 +44,16 @@ class RateLimitingTest < ActionController::TestCase
4444
end
4545
end
4646

47+
test "limit by" do
48+
get :limited_with
49+
get :limited_with
50+
get :limited_with
51+
assert_response :forbidden
52+
53+
get :limited_with, params: { rate_limit_key: "other" }
54+
get :limited_with
55+
end
56+
4757
test "limited with" do
4858
get :limited_with
4959
get :limited_with

activesupport/lib/active_support/cache/file_store.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,12 @@ def search_dir(dir, &callback)
210210
# Modifies the amount of an integer value that is stored in the cache.
211211
# If the key is not found it is created and set to +amount+.
212212
def modify_value(name, amount, options)
213-
file_name = normalize_key(name, options)
214213
options = merged_options(options)
215214
key = normalize_key(name, options)
216215
version = normalize_version(name, options)
217216
amount = Integer(amount)
218217

219-
lock_file(file_name) do
218+
lock_file(key) do
220219
entry = read_entry(key, **options)
221220

222221
if !entry || entry.expired? || entry.mismatched?(version)

0 commit comments

Comments
 (0)