No need to disable rate limiter after running tests (#13093)

No need to disable rate limiter after running tests (#13093)

We disable rate limiter before running every test here discourse/rails_helper.rb at 90ab3b1c7575772aed87755e302aea530909af9a · discourse/discourse · GitHub

diff --git a/spec/components/auth/default_current_user_provider_spec.rb b/spec/components/auth/default_current_user_provider_spec.rb
index 94b3429..1ff3e6e 100644
--- a/spec/components/auth/default_current_user_provider_spec.rb
+++ b/spec/components/auth/default_current_user_provider_spec.rb
@@ -195,10 +195,6 @@ describe Auth::DefaultCurrentUserProvider do
         RateLimiter.enable
       end
 
-      after do
-        RateLimiter.disable
-      end
-
       it "rate limits api requests per api key" do
         global_setting :max_admin_api_reqs_per_key_per_minute, 3
 
@@ -424,10 +420,6 @@ describe Auth::DefaultCurrentUserProvider do
       RateLimiter.enable
     end
 
-    after do
-      RateLimiter.disable
-    end
-
     it "can only try 10 bad cookies a minute" do
       token = UserAuthToken.generate!(user_id: user.id)
 
@@ -627,10 +619,6 @@ describe Auth::DefaultCurrentUserProvider do
         RateLimiter.enable
       end
 
-      after do
-        RateLimiter.disable
-      end
-
       it "rate limits api usage" do
         limiter1 = RateLimiter.new(nil, "user_api_day_#{api_key.key}", 10, 60)
         limiter2 = RateLimiter.new(nil, "user_api_min_#{api_key.key}", 10, 60)
diff --git a/spec/components/middleware/anonymous_cache_spec.rb b/spec/components/middleware/anonymous_cache_spec.rb
index e2beddc..33089a2 100644
--- a/spec/components/middleware/anonymous_cache_spec.rb
+++ b/spec/components/middleware/anonymous_cache_spec.rb
@@ -178,10 +178,6 @@ describe Middleware::AnonymousCache do
       RateLimiter.enable
     end
 
-    after do
-      RateLimiter.disable
-    end
-
     it 'will revert to anonymous once we reach the limit' do
 
       RateLimiter.clear_all!
diff --git a/spec/components/middleware/request_tracker_spec.rb b/spec/components/middleware/request_tracker_spec.rb
index 459b968..c4ee17d 100644
--- a/spec/components/middleware/request_tracker_spec.rb
+++ b/spec/components/middleware/request_tracker_spec.rb
@@ -205,7 +205,6 @@ describe Middleware::RequestTracker do
     end
 
     after do
-      RateLimiter.disable
       Rails.logger = @old_logger
     end
 
diff --git a/spec/components/rate_limiter_spec.rb b/spec/components/rate_limiter_spec.rb
index 2b32df7..4802fea 100644
--- a/spec/components/rate_limiter_spec.rb
+++ b/spec/components/rate_limiter_spec.rb
@@ -34,10 +34,6 @@ describe RateLimiter do
       rate_limiter.clear!
     end
 
-    after do
-      RateLimiter.disable
-    end
-
     context 'aggressive rate limiter' do
 
       it 'can operate correctly and totally stop limiting' do
diff --git a/spec/integration/rate_limiting_spec.rb b/spec/integration/rate_limiting_spec.rb
index 353569e..e7bb8f3 100644
--- a/spec/integration/rate_limiting_spec.rb
+++ b/spec/integration/rate_limiting_spec.rb
@@ -10,10 +10,6 @@ describe 'rate limiter integration' do
     RateLimiter.clear_all!
   end
 
-  after do
-    RateLimiter.disable
-  end
-
   it "will rate limit message bus requests once queueing" do
     freeze_time
 
diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb
index 2454364..63c3849 100644
--- a/spec/models/category_spec.rb
+++ b/spec/models/category_spec.rb
@@ -875,10 +875,6 @@ describe Category do
   end
 
   describe 'auto bump' do
-    after do
-      RateLimiter.disable
-    end
-
     it 'should correctly automatically bump topics' do
       freeze_time
       category = Fabricate(:category_with_definition, created_at: 1.minute.ago)
diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb
index 07f4de9..57ff44c 100644
--- a/spec/models/topic_spec.rb
+++ b/spec/models/topic_spec.rb
@@ -629,7 +629,6 @@ describe Topic do
 
       after do
         RateLimiter.clear_all!
-        RateLimiter.disable
       end
 
       it "rate limits topic invitations" do
@@ -2296,7 +2295,6 @@ describe Topic do
 
     after do
       RateLimiter.clear_all!
-      RateLimiter.disable
     end
 
     it "limits according to max_personal_messages_per_day" do
diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb
index 0fde425..2e76f30 100644
--- a/spec/requests/application_controller_spec.rb
+++ b/spec/requests/application_controller_spec.rb
@@ -692,8 +692,6 @@ RSpec.describe ApplicationController do
         RateLimiter.enable
       end
 
-      after { RateLimiter.disable }
-
       it "serves a LimitExceeded error in the preferred locale" do
         SiteSetting.max_likes_per_day = 1
         post1 = Fabricate(:post)
diff --git a/spec/requests/invites_controller_spec.rb b/spec/requests/invites_controller_spec.rb
index aecfa50..6dc26b8 100644
--- a/spec/requests/invites_controller_spec.rb
+++ b/spec/requests/invites_controller_spec.rb
@@ -320,8 +320,6 @@ describe InvitesController do
           .to change { RateLimiter.new(user, 'resend-invite-per-hour', 10, 1.hour).remaining }.by(-1)
         expect(response.status).to eq(200)
         expect(Jobs::InviteEmail.jobs.size).to eq(1)
-      ensure
-        RateLimiter.disable
       end
 
       it 'cannot create duplicated invites' do
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 4bbf1fd..e7430a9 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -324,7 +324,6 @@ describe UsersController do
 
       context "rate limiting" do
         before { RateLimiter.clear_all!; RateLimiter.enable }
-        after  { RateLimiter.disable }
 
         it "rate limits reset passwords" do
           freeze_time
diff --git a/spec/requests/users_email_controller_spec.rb b/spec/requests/users_email_controller_spec.rb
index ffb7b1f..046e618 100644
--- a/spec/requests/users_email_controller_spec.rb
+++ b/spec/requests/users_email_controller_spec.rb
@@ -134,7 +134,6 @@ describe UsersEmailController do
 
         context "rate limiting" do
           before { RateLimiter.clear_all!; RateLimiter.enable }
-          after  { RateLimiter.disable }
 
           it "rate limits by IP" do
             freeze_time

GitHub sha: 075cd07a

This commit appears in #13093 which was approved by ZogStriP. It was merged by AndrewPrigorshnev.