From ecf6782ef3483f3f862749fb24d6e02bb986ccd8 Mon Sep 17 00:00:00 2001 From: Nick Ragaz Date: Sat, 22 May 2010 17:19:30 -0400 Subject: [PATCH] ActiveResource raises TimeoutError rather than NoMethodError from Net::HTTP if site URI does not work --- activeresource/lib/active_resource/connection.rb | 5 +++++ activeresource/test/connection_test.rb | 7 +++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index b7befe1..e05991d 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -114,6 +114,11 @@ module ActiveResource handle_response(result) rescue Timeout::Error => e raise TimeoutError.new(e.message) + rescue NoMethodError => e + # Raised by pre-May 2010 versions of Net::HTTP when the connection was not started before an error occurred. + # This may occur if the site URI is not active. + # The current version of REE (2010.01) suffers from this bug. + raise TimeoutError.new(nil) rescue OpenSSL::SSL::SSLError => e raise SSLError.new(e.message) end diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index a2744d7..5d7b60e 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -180,6 +180,13 @@ class ConnectionTest < Test::Unit::TestCase response = @conn.delete("/people/2.xml", @header) assert_equal 200, response.code end + + def test_site_not_responsive_and_net_http_is_buggy + @http = mock('new Net::HTTP') + @conn.expects(:http).returns(@http) + @http.expects(:get).raises(NoMethodError, "undefined method `closed?' for nil:NilClass") + assert_raise(ActiveResource::TimeoutError) { @conn.get('/people.xml') } + end def test_timeout @http = mock('new Net::HTTP') -- 1.7.1