From 1768f2a37ec7772d48518202cb4503db4a7c5ece Mon Sep 17 00:00:00 2001 From: Paul Thornthwaite Date: Wed, 26 Feb 2014 22:07:06 +0000 Subject: [PATCH] [GH-2711] Add Fog::XML::Connection Attempting to move to using Fog::XML::SAXParserConnection directly failed because the arguments changed. This adds another compatibility level with two key differences: 1) It's namespaced within XML so stands out as not being part of core 2) It is NOT creating deprecation warnings so can be used as the final step if rewriting to use SAXParserConnection is undesired So when merged Fog::Connection usage will create noise. Fog::XML::Connection works the same way and will be extracted to "fog/xml" when we get to it. Fog::Core::Connection just wraps Excon.request and leaves the response body parsing to the provider. --- lib/fog/core/deprecated/connection.rb | 9 ++++---- lib/fog/xml.rb | 12 +++++++++-- lib/fog/xml/connection.rb | 13 ++++++++++++ test/fog/xml/connection_test.rb | 30 +++++++++++++++++++++++++++ test/hello_world_test.rb | 8 ------- 5 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 lib/fog/xml/connection.rb create mode 100644 test/fog/xml/connection_test.rb delete mode 100644 test/hello_world_test.rb diff --git a/lib/fog/core/deprecated/connection.rb b/lib/fog/core/deprecated/connection.rb index e27931fc0..a9f9069a4 100644 --- a/lib/fog/core/deprecated/connection.rb +++ b/lib/fog/core/deprecated/connection.rb @@ -12,15 +12,14 @@ module Fog # # @see https://github.com/geemus/excon/blob/master/lib/excon/connection.rb # - class Connection < Fog::XML::SAXParserConnection + class Connection < Fog::XML::Connection def request(params, &block) - if (parser = params.delete(:parser)) - Fog::Logger.deprecation("Fog::Connection is deprecated use Fog::XML::SAXParserConnection instead [light_black](#{caller.first})[/]") - super(parser, params) + if params.key?(:parser) + Fog::Logger.deprecation("Fog::Connection is deprecated use Fog::XML::Connection instead [light_black](#{caller.first})[/]") else Fog::Logger.deprecation("Fog::Connection is deprecated use Fog::Core::Connection instead [light_black](#{caller.first})[/]") - original_request(params) end + super(params) end end end diff --git a/lib/fog/xml.rb b/lib/fog/xml.rb index 0e4b61573..13d3c88c3 100644 --- a/lib/fog/xml.rb +++ b/lib/fog/xml.rb @@ -1,5 +1,6 @@ require "nokogiri" require "fog/core/parser" +require "fog/xml/sax_parser_connection" module Fog @@ -15,7 +16,14 @@ module Fog # its services # module XML + class Connection < Fog::XML::SAXParserConnection + def request(params, &block) + if (parser = params.delete(:parser)) + super(parser, params) + else + original_request(params) + end + end + end end end - -require "fog/xml/sax_parser_connection" diff --git a/lib/fog/xml/connection.rb b/lib/fog/xml/connection.rb new file mode 100644 index 000000000..fedcc4b62 --- /dev/null +++ b/lib/fog/xml/connection.rb @@ -0,0 +1,13 @@ +module Fog + module XML + class Connection < SAXParserConnection + def request(params, &block) + if (parser = params.delete(:parser)) + super(parser, params) + else + original_request(params) + end + end + end + end +end diff --git a/test/fog/xml/connection_test.rb b/test/fog/xml/connection_test.rb new file mode 100644 index 000000000..9f36bdd7b --- /dev/null +++ b/test/fog/xml/connection_test.rb @@ -0,0 +1,30 @@ +require "minitest/autorun" +require "fog" + +# Note this is going to be part of fog-xml eventually +class TestFogXMLConnection < MiniTest::Unit::TestCase + def setup + @connection = Fog::XML::Connection.new("http://localhost") + end + + def teardown + Excon.stubs.clear + end + + def test_respond_to_request + assert_respond_to @connection, :request + end + + def test_request_with_parser + @parser = Fog::ToHashDocument.new + Excon.stub({}, { :status => 200, :body => "" }) + response = @connection.request(:parser => @parser, :mock => true) + assert_equal({ :xml => "" }, response.body) + end + + def test_request_without_parser + Excon.stub({}, { :status => 200, :body => "" }) + response = @connection.request(:mock => true) + assert_equal("", response.body) + end +end diff --git a/test/hello_world_test.rb b/test/hello_world_test.rb deleted file mode 100644 index 1a8b8fe9d..000000000 --- a/test/hello_world_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "minitest/autorun" - -class HelloWorldTest < Minitest::Test - # This is a placeholder to ensure minitest is being picked up by rake - def test_truth - assert true - end -end