Add specs for `RateLimiter::LimitExceeded#description`.
This commit is contained in:
parent
3725fd8345
commit
630b4570ef
|
@ -10,16 +10,16 @@ class RateLimiter
|
|||
end
|
||||
|
||||
def description
|
||||
time_left = ""
|
||||
if @available_in <= 3
|
||||
time_left = I18n.t("rate_limiter.short_time")
|
||||
elsif @available_in < 1.minute.to_i
|
||||
time_left = I18n.t("rate_limiter.seconds", count: @available_in)
|
||||
elsif @available_in < 1.hour.to_i
|
||||
time_left = I18n.t("rate_limiter.minutes", count: (@available_in / 1.minute.to_i))
|
||||
else
|
||||
time_left = I18n.t("rate_limiter.hours", count: (@available_in / 1.hour.to_i))
|
||||
end
|
||||
time_left =
|
||||
if @available_in <= 3
|
||||
I18n.t("rate_limiter.short_time")
|
||||
elsif @available_in < 1.minute.to_i
|
||||
I18n.t("rate_limiter.seconds", count: @available_in)
|
||||
elsif @available_in < 1.hour.to_i
|
||||
I18n.t("rate_limiter.minutes", count: (@available_in / 1.minute.to_i))
|
||||
else
|
||||
I18n.t("rate_limiter.hours", count: (@available_in / 1.hour.to_i))
|
||||
end
|
||||
|
||||
if @type.present?
|
||||
type_key = @type.tr("-", "_")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RateLimiter::LimitExceeded do
|
||||
describe '#description' do
|
||||
it 'should return the right description' do
|
||||
[
|
||||
[3, I18n.t("rate_limiter.short_time")],
|
||||
[59, I18n.t("rate_limiter.seconds", count: 59)],
|
||||
[3599, I18n.t("rate_limiter.minutes", count: 59)],
|
||||
[7000, I18n.t("rate_limiter.hours", count: 1)]
|
||||
].each do |available_in, time_left|
|
||||
|
||||
expect(described_class.new(available_in).description).to eq(I18n.t(
|
||||
"rate_limiter.too_many_requests",
|
||||
time_left: time_left
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue