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!