From aec8a5f464504ed6e4e6734afee00f6b6c7698cf Mon Sep 17 00:00:00 2001 From: Ashwin M Date: Sun, 28 Dec 2025 14:28:51 +0530 Subject: [PATCH] Enable rate limiting in test environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, Rails uses the cache_store for rate limiting. Since the test environment uses :null_store, rate limiting was silently disabled in tests. This configures a separate :memory_store for action_controller.cache_store so rate limiting actually works in tests. The cache is cleared in the IntegrationTest setup to prevent rate limit data from persisting across tests. Also updates the join_codes_controller_test to stub the correct cache store. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- config/environments/test.rb | 3 +++ test/controllers/join_codes_controller_test.rb | 2 +- test/test_helper.rb | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 157e4b00bb..e09d0f3b2c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -28,6 +28,9 @@ config.action_controller.perform_caching = false config.cache_store = :null_store + # Use memory store for rate limiting (null_store silently disables it) + config.action_controller.cache_store = :memory_store + # Render exception templates for rescuable exceptions and raise for other exceptions. config.action_dispatch.show_exceptions = :rescuable diff --git a/test/controllers/join_codes_controller_test.rb b/test/controllers/join_codes_controller_test.rb index 81a4ea6eae..2d92bba94e 100644 --- a/test/controllers/join_codes_controller_test.rb +++ b/test/controllers/join_codes_controller_test.rb @@ -96,7 +96,7 @@ class JoinCodesControllerTest < ActionDispatch::IntegrationTest end test "create is rate limited" do - Rails.cache.stubs(:increment).returns(11) + ActionController::Base.cache_store.stubs(:increment).returns(11) post join_path(code: @join_code.code, script_name: @account.slug), params: { email_address: "test@example.com" } diff --git a/test/test_helper.rb b/test/test_helper.rb index 14893b030a..963135b75b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -60,6 +60,7 @@ class TestCase class ActionDispatch::IntegrationTest setup do integration_session.default_url_options[:script_name] = "/#{ActiveRecord::FixtureSet.identify("37signals")}" + ActionController::Base.cache_store.clear end private