diff --git a/activerecord/test/cases/base_prevent_writes_test.rb b/activerecord/test/cases/base_prevent_writes_test.rb
index <HASH>..<HASH> 100644
--- a/activerecord/test/cases/base_prevent_writes_test.rb
+++ b/activerecord/test/cases/base_prevent_writes_test.rb
@@ -87,6 +87,12 @@ class BasePreventWritesTest < ActiveRecord::TestCase
 
       assert_match %r/\AWrite query attempted while in readonly mode: INSERT /, conn2_error.message
     end
+
+    test "current_preventing_writes" do
+      ActiveRecord::Base.while_preventing_writes do
+        assert ActiveRecord::Base.current_preventing_writes, "expected connection current_preventing_writes to return true"
+      end
+    end
   end
 
   class BasePreventWritesLegacyTest < ActiveRecord::TestCase
@@ -213,5 +219,11 @@ class BasePreventWritesTest < ActiveRecord::TestCase
         assert_match %r/\AWrite query attempted while in readonly mode: INSERT /, conn2_error.message
       end
     end
+
+    test "current_preventing_writes" do
+      ActiveRecord::Base.connection_handler.while_preventing_writes do
+        assert ActiveRecord::Base.current_preventing_writes, "expected connection current_preventing_writes to return true"
+      end
+    end
   end
 end
Add tests for `current_preventing_writes`

Ensure that the new version and legacy versions work as expected.