Skip to content

Commit

Permalink
convert keys for qualified messages w/o namespace
Browse files Browse the repository at this point in the history
possible fix for #461
  • Loading branch information
rubiii committed Jun 30, 2013
1 parent 41d7ac9 commit 4742208
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib/savon/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
24 changes: 14 additions & 10 deletions lib/savon/qualified_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions spec/savon/message_spec.rb
Original file line number Diff line number Diff line change
@@ -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('<wsdl:UserName>josh</wsdl:UserName><wsdl:EmailCount>3</wsdl:EmailCount>')
end
end

end

0 comments on commit 4742208

Please sign in to comment.