Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespaces to body and order #275

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/savon/soap/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def add_namespaces_to_body(hash, path = [input[1].to_s])
add_namespaces_to_body(value, types[newpath] ? [types[newpath]] : newpath)
)
else
add_namespaces_to_values(value, path) if key == :order!
newhash.merge(key => value)
end
end
Expand All @@ -224,6 +225,14 @@ def add_namespace_to_input
[used_namespaces[[input[1].to_s]], input[1], input[2]]
end

def add_namespaces_to_values(values, path)
values.collect! { |value|
camelcased_value = Gyoku::XMLKey.create(value)
namespace_path = path + [camelcased_value.to_s]
namespace = used_namespaces[namespace_path]
"#{namespace.blank? ? '' : namespace + ":"}#{camelcased_value}"
}
end
end
end
end
27 changes: 27 additions & 0 deletions spec/savon/soap/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,33 @@
end
end

describe "#add_namespaces_to_body" do
before :each do
xml.used_namespaces.merge!({
["authenticate", "id"] =>"ns0",
["authenticate", "name"] =>"ns1",
["authenticate", "name", "firstName"] =>"ns2"
})
end

it "adds namespaces" do
body = {:id => 1, :name => {:first_name => 'Bob'}}
xml.send(:add_namespaces_to_body, body).should == {"ns0:id" => "1", "ns1:name" => {"ns2:firstName" => "Bob"}}
end

it "adds namespaces to order! list" do
body = {:id => 1, :name => {:first_name => 'Bob', :order! => [:first_name]}, :order! => [:id, :name]}
xml.send(:add_namespaces_to_body, body).should == {
"ns0:id" => "1",
"ns1:name" => {
"ns2:firstName" => "Bob",
:order! => ["ns2:firstName"]
},
:order! => ["ns0:id", "ns1:name"]
}
end
end

def reset_soap_version
Savon.soap_version = Savon::SOAP::DefaultVersion
end
Expand Down