From e2d33b4fbb68ec3d7863f5ada774679bf38fa301 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Sat, 10 Aug 2024 08:39:36 +0300 Subject: [PATCH] #59 extra checks --- lib/fbe/middleware/quota.rb | 4 ++++ test/fbe/middleware/test_quota.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fbe/middleware/quota.rb b/lib/fbe/middleware/quota.rb index 0504b78..c7c266e 100644 --- a/lib/fbe/middleware/quota.rb +++ b/lib/fbe/middleware/quota.rb @@ -30,12 +30,16 @@ def initialize(app, loog: Loog::NULL, pause: 60, limit: 100, rate: 5) super(app) @requests = 0 @app = app + raise 'The "loog" cannot be nil' if loog.nil? @loog = loog raise 'The "pause" cannot be nil' if pause.nil? + raise 'The "pause" must be a positive integer' unless pause.positive? @pause = pause raise 'The "limit" cannot be nil' if limit.nil? + raise 'The "limit" must be a positive integer' unless limit.positive? @limit = limit raise 'The "rate" cannot be nil' if rate.nil? + raise 'The "rate" must be a positive integer' unless rate.positive? @rate = rate end diff --git a/test/fbe/middleware/test_quota.rb b/test/fbe/middleware/test_quota.rb index 3cbc04e..85d46c3 100644 --- a/test/fbe/middleware/test_quota.rb +++ b/test/fbe/middleware/test_quota.rb @@ -45,7 +45,7 @@ def call(env) def test_quota_middleware_pauses_when_quota_low loog = Loog::NULL - pause = 0 + pause = 1 app = FakeApp.new middleware = Fbe::Middleware::Quota.new(app, loog:, pause:) start_time = Time.now