@@ -521,3 +521,39 @@ def assert_flash_error
521521 assert_equal "reCAPTCHA verification failed, please try again." , @controller . flash [ :recaptcha_error ]
522522 end
523523end
524+
525+ describe "Recaptcha.skip_env?" do
526+ # test/helper.rb deletes RAILS_ENV and RACK_ENV, so default_env is nil in this suite.
527+ # This mirrors what can happen in multi-threaded servers (e.g. Puma running system tests)
528+ # where the Configuration singleton is initialised before the env var is visible,
529+ # leaving default_env as nil even though Rails.env correctly returns "test".
530+
531+ it "returns true when env argument matches skip_verify_env" do
532+ assert Recaptcha . skip_env? ( "test" )
533+ end
534+
535+ it "returns false when env argument is not in skip_verify_env" do
536+ refute Recaptcha . skip_env? ( "production" )
537+ end
538+
539+ it "returns false when env argument is nil and default_env is nil" do
540+ assert_nil Recaptcha . configuration . default_env
541+ refute Recaptcha . skip_env? ( nil )
542+ end
543+
544+ describe "when Rails.env is available and in skip_verify_env" do
545+ before do
546+ rails_stub = Module . new { def self . env ; "test" ; end }
547+ Object . const_set ( :Rails , rails_stub )
548+ end
549+
550+ after do
551+ Object . send ( :remove_const , :Rails ) if defined? ( Rails )
552+ end
553+
554+ it "returns true even when default_env is nil" do
555+ assert_nil Recaptcha . configuration . default_env
556+ assert Recaptcha . skip_env? ( nil )
557+ end
558+ end
559+ end
0 commit comments