From 2bed01e8f4d2e93fa7afc547310ac85b2329c901 Mon Sep 17 00:00:00 2001 From: Kyle Huston Date: Thu, 3 Jul 2025 10:18:48 -0400 Subject: [PATCH] Fix enable_net_connection! when Connection is first used ActiveResource::HttpMock.enable_net_connection! was ignored on the first call to ActiveResource::Connection#http. --- lib/active_resource/http_mock.rb | 4 ++-- test/cases/connection_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_resource/http_mock.rb b/lib/active_resource/http_mock.rb index 6b76006346..9a8947cbe8 100644 --- a/lib/active_resource/http_mock.rb +++ b/lib/active_resource/http_mock.rb @@ -375,11 +375,11 @@ def http_stub end def unstub_http? - HttpMock.net_connection_enabled? && defined?(@http) && @http.kind_of?(HttpMock) + HttpMock.net_connection_enabled? && (!defined?(@http) || @http.kind_of?(HttpMock)) end def stub_http? - HttpMock.net_connection_disabled? && defined?(@http) && @http.kind_of?(Net::HTTP) + HttpMock.net_connection_disabled? && (!defined?(@http) || @http.kind_of?(Net::HTTP)) end end end diff --git a/test/cases/connection_test.rb b/test/cases/connection_test.rb index a4265f4dde..9d3145e050 100644 --- a/test/cases/connection_test.rb +++ b/test/cases/connection_test.rb @@ -312,6 +312,13 @@ def test_enable_net_connection end end + def test_enable_net_connection_first_time + keep_net_connection_status do + ActiveResource::HttpMock.enable_net_connection! + assert @conn.send(:http).kind_of?(Net::HTTP) + end + end + def test_disable_net_connection keep_net_connection_status do ActiveResource::HttpMock.enable_net_connection!