Permalink
Browse files

ensure clients can handle APIs with named parameter signatures,

and test for this


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@680 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 418d487 commit 5f3f44e76fdf465910b7c6521568bb6a1e8bd641 @leonbreedt leonbreedt committed Feb 19, 2005
@@ -30,6 +30,10 @@ def method_name(name)
nil
end
end
+
+ def lookup_class(klass)
+ klass.is_a?(Hash) ? klass.values[0] : klass
+ end
end
end
end
@@ -62,13 +62,14 @@ def create_soap_rpc_driver(api, endpoint_uri)
if expects
expects.each do |klass|
param_name = klass.is_a?(Hash) ? klass.keys[0] : "param#{i}"
- mapping = @mapper.lookup(klass)
+ param_klass = lookup_class(klass)
+ mapping = @mapper.lookup(param_klass)
param_def << ['in', param_name, mapping.registry_mapping]
i += 1
end
end
if returns
- mapping = @mapper.lookup(returns[0])
+ mapping = @mapper.lookup(lookup_class(returns[0]))
param_def << ['retval', 'return', mapping.registry_mapping]
end
driver.add_method(qname, action, name.to_s, param_def)
@@ -54,7 +54,7 @@ def transform_outgoing_method_params(method_name, params)
signature = Protocol::XmlRpc::XmlRpcProtocol.transform_array_types(signature)
(1..signature.size).each do |i|
i -= 1
- params[i] = Protocol::XmlRpc::XmlRpcProtocol.ruby_to_xmlrpc(params[i], signature[i])
+ params[i] = Protocol::XmlRpc::XmlRpcProtocol.ruby_to_xmlrpc(params[i], lookup_class(signature[i]))
end
end
params
@@ -63,7 +63,8 @@ def transform_outgoing_method_params(method_name, params)
def transform_return_value(method_name, return_value)
info = @api.api_methods[method_name.to_sym]
return true unless signature = info[:returns]
- signature = Protocol::XmlRpc::XmlRpcProtocol.transform_array_types(signature)
+ param_klass = lookup_class(signature[0])
+ signature = Protocol::XmlRpc::XmlRpcProtocol.transform_array_types([param_klass])
Protocol::XmlRpc::XmlRpcProtocol.xmlrpc_to_ruby(return_value, signature[0])
end
@@ -19,6 +19,7 @@ class API < ActionWebService::API::Base
api_method :array_return, :returns => [[Person]]
api_method :struct_pass, :expects => [[Person]], :returns => [:bool]
api_method :client_container, :returns => [:int]
+ api_method :named_parameters, :expects => [{:key=>:string}, {:id=>:int}]
end
class NullLogOut
@@ -32,13 +33,15 @@ class Container < ActionController::Base
attr :value_normal
attr :value_array_return
attr :value_struct_pass
+ attr :value_named_parameters
def initialize
@session = @assigns = {}
@value_void = nil
@value_normal = nil
@value_array_return = nil
@value_struct_pass = nil
+ @value_named_parameters = nil
end
def void
@@ -66,6 +69,10 @@ def client_container
50
end
+ def named_parameters
+ @value_named_parameters = @method_params
+ end
+
def protocol_request(request)
probe_request_protocol(request)
end
@@ -84,4 +84,10 @@ def test_struct_pass
def test_client_container
assert_equal(50, ClientContainer.new.get_client.client_container)
end
+
+ def test_named_parameters
+ assert(@container.value_named_parameters.nil?)
+ assert(@client.named_parameters("key", 5).nil?)
+ assert_equal(["key", 5], @container.value_named_parameters)
+ end
end
@@ -83,4 +83,10 @@ def test_struct_pass
def test_client_container
assert_equal(50, ClientContainer.new.get_client.client_container)
end
+
+ def test_named_parameters
+ assert(@container.value_named_parameters.nil?)
+ assert_equal(true, @client.named_parameters("xxx", 7))
+ assert_equal(["xxx", 7], @container.value_named_parameters)
+ end
end

0 comments on commit 5f3f44e

Please sign in to comment.