From 0740945aec85a1682a741f63f7105603bd165ee6 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Sun, 27 Apr 2014 15:34:31 +0400 Subject: [PATCH 1/2] Allow to pass the `adapter` option in initializer, use the provided adapter to fetch remote WSDL. There is no tests yet. Bumped version for use in savon gemspec. --- lib/wasabi/document.rb | 7 ++++--- lib/wasabi/resolver.rb | 7 ++++--- lib/wasabi/version.rb | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/wasabi/document.rb b/lib/wasabi/document.rb index febc5e3..7ddce22 100644 --- a/lib/wasabi/document.rb +++ b/lib/wasabi/document.rb @@ -21,11 +21,12 @@ def self.validate_element_form_default!(value) end # Accepts a WSDL +document+ to parse. - def initialize(document = nil) + def initialize(document = nil, adapter = nil) self.document = document + self.adapter = adapter end - attr_accessor :document, :request + attr_accessor :document, :request, :adapter attr_writer :xml @@ -138,7 +139,7 @@ def user_defined(namespace) # Returns the raw WSDL document. # Can be used as a hook to extend the library. def xml - @xml ||= Resolver.new(document, request).resolve + @xml ||= Resolver.new(document, request, adapter).resolve end # Parses the WSDL document and returns the Wasabi::Parser. diff --git a/lib/wasabi/resolver.rb b/lib/wasabi/resolver.rb index 79c7d6b..2281816 100644 --- a/lib/wasabi/resolver.rb +++ b/lib/wasabi/resolver.rb @@ -18,12 +18,13 @@ def initialize(message, response=nil) URL = /^http[s]?:/ XML = /^ Date: Thu, 1 May 2014 14:12:24 +0400 Subject: [PATCH 2/2] Add test for adapter usage --- spec/support/adapter.rb | 18 ++++++++++++++++++ spec/wasabi/resolver_spec.rb | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/support/adapter.rb diff --git a/spec/support/adapter.rb b/spec/support/adapter.rb new file mode 100644 index 0000000..15d9f62 --- /dev/null +++ b/spec/support/adapter.rb @@ -0,0 +1,18 @@ +class FakeAdapterForTest < HTTPI::Adapter::Base + + register :fake_adapter_for_test + + def initialize(request) + @@requests ||= [] + @@requests.push request + @request = request + end + + attr_reader :client + + def request(method) + @@methods ||= [] + @@methods.push method + HTTPI::Response.new(200, {}, 'wsdl_by_adapter') + end +end diff --git a/spec/wasabi/resolver_spec.rb b/spec/wasabi/resolver_spec.rb index c3a3d23..b4ead0b 100644 --- a/spec/wasabi/resolver_spec.rb +++ b/spec/wasabi/resolver_spec.rb @@ -9,6 +9,17 @@ xml.should == "wsdl" end + it "resolves remote documents with custom adapter" do + prev_logging = HTTPI.instance_variable_get(:@log) + HTTPI.log = false # Don't pollute rspec output by request logging + xml = Wasabi::Resolver.new("http://example.com?wsdl", nil, :fake_adapter_for_test).resolve + xml.should == "wsdl_by_adapter" + expect(FakeAdapterForTest.class_variable_get(:@@requests).size).to eq(1) + expect(FakeAdapterForTest.class_variable_get(:@@requests).first.url).to eq(URI.parse("http://example.com?wsdl")) + expect(FakeAdapterForTest.class_variable_get(:@@methods)).to eq([:get]) + HTTPI.log = prev_logging + end + it "resolves local documents" do xml = Wasabi::Resolver.new(fixture(:authentication).path).resolve xml.should == fixture(:authentication).read