Fix test
This commit is contained in:
parent
29b904483e
commit
721f6f9c97
1 changed files with 20 additions and 20 deletions
|
@ -7,6 +7,26 @@ RSpec.describe Rack::Attack, type: :request do
|
|||
Rails.application
|
||||
end
|
||||
|
||||
def below_limit
|
||||
limit - 1
|
||||
end
|
||||
|
||||
def above_limit
|
||||
limit * 2
|
||||
end
|
||||
|
||||
def throttle_count
|
||||
described_class.cache.read("#{counter_prefix}:#{throttle}:#{discriminator}") || 0
|
||||
end
|
||||
|
||||
def counter_prefix
|
||||
(Time.now.to_i / period.seconds).to_i
|
||||
end
|
||||
|
||||
def increment_counter
|
||||
described_class.cache.count("#{throttle}:#{discriminator}", period)
|
||||
end
|
||||
|
||||
shared_context 'with throttled endpoint base' do
|
||||
before do
|
||||
# Rack::Attack periods are not rolling, so avoid flaky tests by setting the time in a way
|
||||
|
@ -18,26 +38,6 @@ RSpec.describe Rack::Attack, type: :request do
|
|||
|
||||
travel_to Time.zone.at(counter_prefix * period.seconds)
|
||||
end
|
||||
|
||||
def below_limit
|
||||
limit - 1
|
||||
end
|
||||
|
||||
def above_limit
|
||||
limit * 2
|
||||
end
|
||||
|
||||
def throttle_count
|
||||
described_class.cache.read("#{counter_prefix}:#{throttle}:#{discriminator}") || 0
|
||||
end
|
||||
|
||||
def counter_prefix
|
||||
(Time.now.to_i / period.seconds).to_i
|
||||
end
|
||||
|
||||
def increment_counter
|
||||
described_class.cache.count("#{throttle}:#{discriminator}", period)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'throttled endpoint' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue