aboutsummaryrefslogtreecommitdiffstats
path: root/actionwebservice
diff options
context:
space:
mode:
authorLeon Breedt <bitserf@gmail.com>2005-04-04 22:58:02 +0000
committerLeon Breedt <bitserf@gmail.com>2005-04-04 22:58:02 +0000
commitd7a7d85dbdd2e13612affe48cca39aa48643944d (patch)
treed4a7cd556125b93b4d93e53a074ee730fc25effa /actionwebservice
parenta87c1d4dd856d138e97e821083c905b481982399 (diff)
downloadrails-d7a7d85dbdd2e13612affe48cca39aa48643944d.tar.gz
rails-d7a7d85dbdd2e13612affe48cca39aa48643944d.tar.bz2
rails-d7a7d85dbdd2e13612affe48cca39aa48643944d.zip
* Fix casting of nested members in structured types if we have a signature
type available for it even if they are already of the desired type as SOAP/XML-RPC unmarshaling may have gotten it wrong: SOAP likes to always use DateTime no matter what, for example, whereas we allow a distinction between Date, DateTime and Time in the signature for convenience casting * Fix raising of exceptions by test_invoke so functional tests fail properly on exception instead of returning the exception object * Fix Struct#each_pair to yield the value and not the member type git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1089 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice')
-rw-r--r--actionwebservice/CHANGELOG3
-rw-r--r--actionwebservice/lib/action_web_service/casting.rb13
-rw-r--r--actionwebservice/lib/action_web_service/struct.rb4
-rw-r--r--actionwebservice/lib/action_web_service/test_invoke.rb10
-rw-r--r--actionwebservice/test/struct_test.rb8
5 files changed, 22 insertions, 16 deletions
diff --git a/actionwebservice/CHANGELOG b/actionwebservice/CHANGELOG
index ae94240cc3..38f01eb52e 100644
--- a/actionwebservice/CHANGELOG
+++ b/actionwebservice/CHANGELOG
@@ -10,6 +10,9 @@
* Include backtraces in 500 error responses for failed request parsing, and remove "rescue nil" statements obscuring real errors for XML-RPC
+* Perform casting of struct members even if the structure is already of the correct type, so that the type we specify for
+ the struct member is always the type of the value seen by the API implementation
+
*0.6.2* (27th March, 2005)
diff --git a/actionwebservice/lib/action_web_service/casting.rb b/actionwebservice/lib/action_web_service/casting.rb
index 113b24a93c..42ef97fd3b 100644
--- a/actionwebservice/lib/action_web_service/casting.rb
+++ b/actionwebservice/lib/action_web_service/casting.rb
@@ -40,7 +40,7 @@ module ActionWebService # :nodoc:
def cast(value, signature_type) # :nodoc:
return value if signature_type.nil? # signature.length != params.length
- unless signature_type.array?
+ unless signature_type.array? || signature_type.structured?
return value if canonical_type(value.class) == signature_type.type
end
if signature_type.array?
@@ -86,13 +86,20 @@ module ActionWebService # :nodoc:
end
def cast_to_structured_type(value, signature_type) # :nodoc:
- obj = signature_type.type_class.new
+ obj = nil
+ obj = value if canonical_type(value.class) == canonical_type(signature_type.type)
+ obj ||= signature_type.type_class.new
if value.respond_to?(:each_pair)
klass = signature_type.type_class
value.each_pair do |name, val|
type = klass.respond_to?(:member_type) ? klass.member_type(name) : nil
val = cast(val, type) if type
- obj.send("#{name}=", val)
+ obj.__send__("#{name}=", val)
+ end
+ elsif value.respond_to?(:attributes)
+ signature_type.each_member do |name, type|
+ val = value.__send__(name)
+ obj.__send__("#{name}=", cast(val, type))
end
else
raise CastingError, "Don't know how to cast #{value.class} to #{signature_type.type_class}"
diff --git a/actionwebservice/lib/action_web_service/struct.rb b/actionwebservice/lib/action_web_service/struct.rb
index f2bfba9e30..536207aa95 100644
--- a/actionwebservice/lib/action_web_service/struct.rb
+++ b/actionwebservice/lib/action_web_service/struct.rb
@@ -24,7 +24,7 @@ module ActionWebService
# it can contain initial values for the structure member.
def initialize(values={})
if values.is_a?(Hash)
- values.map{|k,v| send('%s=' % k.to_s, v)}
+ values.map{|k,v| __send__('%s=' % k.to_s, v)}
end
end
@@ -36,7 +36,7 @@ module ActionWebService
# Iterates through each member
def each_pair(&block)
self.class.members.each do |name, type|
- yield name, type
+ yield name, self.__send__(name)
end
end
diff --git a/actionwebservice/lib/action_web_service/test_invoke.rb b/actionwebservice/lib/action_web_service/test_invoke.rb
index c22ca618dc..119bc21f68 100644
--- a/actionwebservice/lib/action_web_service/test_invoke.rb
+++ b/actionwebservice/lib/action_web_service/test_invoke.rb
@@ -59,10 +59,8 @@ module Test # :nodoc:
def decode_rpc_response
public_method_name, return_value = protocol.decode_response(@response.body)
- unless @return_exceptions
- exception = is_exception?(return_value)
- raise exception if exception
- end
+ exception = is_exception?(return_value)
+ raise exception if exception
return_value
end
@@ -90,10 +88,10 @@ module Test # :nodoc:
def is_exception?(obj)
case protocol
- when :soap
+ when :soap, ActionWebService::Protocol::Soap::SoapProtocol
(obj.respond_to?(:detail) && obj.detail.respond_to?(:cause) && \
obj.detail.cause.is_a?(Exception)) ? obj.detail.cause : nil
- when :xmlrpc
+ when :xmlrpc, ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
obj.is_a?(XMLRPC::FaultException) ? obj : nil
end
end
diff --git a/actionwebservice/test/struct_test.rb b/actionwebservice/test/struct_test.rb
index 838cc2569c..f689746ee4 100644
--- a/actionwebservice/test/struct_test.rb
+++ b/actionwebservice/test/struct_test.rb
@@ -44,11 +44,9 @@ class TC_Struct < Test::Unit::TestCase
end
def test_each_pair
- members = {}
- @struct.each_pair do |name, type|
- members[name] = type
- assert ActionWebService::BaseType === type
+ @struct.each_pair do |name, value|
+ assert_equal @struct.__send__(name), value
+ assert_equal @struct[name], value
end
- assert_equal members, Struct.members
end
end