From 4742208b80a4a60d28176ab38deb1ecd47b970f4 Mon Sep 17 00:00:00 2001 From: rubiii Date: Sun, 30 Jun 2013 19:17:32 +0200 Subject: [PATCH] convert keys for qualified messages w/o namespace possible fix for #461 --- lib/savon/message.rb | 4 +--- lib/savon/qualified_message.rb | 24 ++++++++++++--------- spec/savon/message_spec.rb | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 spec/savon/message_spec.rb diff --git a/lib/savon/message.rb b/lib/savon/message.rb index 934a4ef7..caa52ae7 100644 --- a/lib/savon/message.rb +++ b/lib/savon/message.rb @@ -20,9 +20,7 @@ def to_s if @element_form_default == :qualified translated_operation_name = Gyoku.xml_tag(@operation_name, :key_converter => @key_converter).to_s - # XXX: there is no `@request_key_converter` instance variable! - # the third argument is therefore always `nil`. [dh, 2013-03-09] - @message = QualifiedMessage.new(@types, @used_namespaces, @request_key_converter).to_hash(@message, [translated_operation_name]) + @message = QualifiedMessage.new(@types, @used_namespaces, @key_converter).to_hash(@message, [translated_operation_name]) end gyoku_options = { diff --git a/lib/savon/qualified_message.rb b/lib/savon/qualified_message.rb index d7a21643..0f0a70d0 100644 --- a/lib/savon/qualified_message.rb +++ b/lib/savon/qualified_message.rb @@ -15,17 +15,21 @@ def to_hash(hash, path) return hash.to_s unless hash.kind_of? Hash hash.inject({}) do |newhash, (key, value)| - translated_key = Gyoku.xml_tag(key, :key_converter => @key_converter).to_s - newpath = path + [translated_key] - - if @used_namespaces[newpath] - newhash.merge( - "#{@used_namespaces[newpath]}:#{translated_key}" => - to_hash(value, @types[newpath] ? [@types[newpath]] : newpath) - ) - else - add_namespaces_to_values(value, path) if key == :order! + if key == :order! + add_namespaces_to_values(value, path) newhash.merge(key => value) + else + translated_key = Gyoku.xml_tag(key, :key_converter => @key_converter).to_s + newpath = path + [translated_key] + + if @used_namespaces[newpath] + newhash.merge( + "#{@used_namespaces[newpath]}:#{translated_key}" => + to_hash(value, @types[newpath] ? [@types[newpath]] : newpath) + ) + else + newhash.merge(translated_key => value) + end end end end diff --git a/spec/savon/message_spec.rb b/spec/savon/message_spec.rb new file mode 100644 index 00000000..012d9b2d --- /dev/null +++ b/spec/savon/message_spec.rb @@ -0,0 +1,39 @@ +require "spec_helper" +require "integration/support/server" + +describe Savon::Message do + + before do + @server = IntegrationServer.run + end + + after do + @server.stop + end + + context "with a qualified message" do + it "converts request Hash keys for which there is not namespace" do + client = Savon.client( + :endpoint => @server.url(:repeat), + :namespace => 'http://example.com', + + :element_form_default => :qualified, + :convert_request_keys_to => :camelcase, + + :convert_response_tags_to => nil + ) + + message = { + :email_count => 3, + :user_name => 'josh', + :order! => [:user_name, :email_count] + } + + response = client.call(:something, :message => message) + body = response.hash['Envelope']['Body'] + + expect(response.xml).to include('josh3') + end + end + +end