Skip to content
This repository
Browse code

Added support for decimal types. Closes #6676.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5670 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit abe8fa73a91b72e79717673393a4f5bc5cd341f7 1 parent db45937
authored December 03, 2006
2  actionwebservice/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Added support for decimal types. Closes #6676. [Kent Sibilev]
  4
+
3 5
 * Removed deprecated end_form_tag helper. [Kent Sibilev]
4 6
 
5 7
 * Removed deprecated @request and @response usages. [Kent Sibilev]
2  actionwebservice/lib/action_web_service/casting.rb
@@ -95,6 +95,8 @@ def cast_base_type(value, signature_type) # :nodoc:
95 95
             end
96 96
           when :float
97 97
             Float(value)
  98
+          when :decimal
  99
+            BigDecimal(value.to_s)
98 100
           when :time
99 101
             value = "%s/%s/%s %s:%s:%s" % value.values_at(*%w[2 3 1 4 5 6]) if value.kind_of?(Hash)
100 102
             value.kind_of?(Time) ? value : Time.parse(value.to_s)
14  actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb
@@ -118,18 +118,12 @@ def soap_type_name(type_name)
118 118
           end
119 119
 
120 120
           def register_static_factories
121  
-            @registry.add(ActionWebService::Base64,
122  
-                          SOAP::SOAPBase64,
123  
-                          SoapBase64Factory.new,
124  
-                          nil)
  121
+            @registry.add(ActionWebService::Base64, SOAP::SOAPBase64, SoapBase64Factory.new, nil)
125 122
             mapping = @registry.find_mapped_soap_class(ActionWebService::Base64)
126 123
             @type2binding[ActionWebService::Base64] =
127  
-              SoapBinding.new(self, SOAP::SOAPBase64::Type,
128  
-                              ActionWebService::Base64, mapping)
129  
-            @registry.add(Array,
130  
-                          SOAP::SOAPArray,
131  
-                          SoapTypedArrayFactory.new,
132  
-                          nil)
  124
+              SoapBinding.new(self, SOAP::SOAPBase64::Type, ActionWebService::Base64, mapping)
  125
+            @registry.add(Array, SOAP::SOAPArray, SoapTypedArrayFactory.new, nil)
  126
+            @registry.add(::BigDecimal, SOAP::SOAPDouble, SOAP::Mapping::Registry::BasetypeFactory, {:derived_class => true})
133 127
           end
134 128
       end
135 129
 
10  actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb
@@ -5,6 +5,16 @@ module XMLRPC # :nodoc:
5 5
   class FaultException # :nodoc:
6 6
     alias :message :faultString
7 7
   end
  8
+  
  9
+  class Create
  10
+    def wrong_type(value)
  11
+      if BigDecimal === value
  12
+        [true, value.to_f]
  13
+      else
  14
+        false
  15
+      end
  16
+    end
  17
+  end
8 18
 end
9 19
 
10 20
 module ActionWebService # :nodoc:
4  actionwebservice/lib/action_web_service/support/signature_types.rb
@@ -61,6 +61,8 @@ def canonical_type_name(name) # :nodoc:
61 61
           :bool
62 62
         when :float, :double
63 63
           :float
  64
+        when :decimal
  65
+          :decimal
64 66
         when :time, :timestamp
65 67
           :time
66 68
         when :datetime
@@ -117,6 +119,8 @@ def type_name_to_class(name) # :nodoc:
117 119
         TrueClass
118 120
       when :float
119 121
         Float
  122
+      when :decimal
  123
+        BigDecimal
120 124
       when :time
121 125
         Time
122 126
       when :date
1  actionwebservice/test/client_soap_test.rb
@@ -126,6 +126,7 @@ def test_model_return
126 126
     assert user.active?
127 127
     assert_kind_of Date, user.created_on
128 128
     assert_equal Date.today, user.created_on
  129
+    assert_equal BigDecimal('12.2'), user.balance
129 130
   end
130 131
   
131 132
   def test_with_model
1  actionwebservice/test/client_xmlrpc_test.rb
@@ -125,6 +125,7 @@ def test_model_return
125 125
     assert user.active?
126 126
     assert_kind_of Time, user.created_on
127 127
     assert_equal Time.utc(Time.now.year, Time.now.month, Time.now.day), user.created_on
  128
+    assert_equal BigDecimal('12.2'), user.balance
128 129
   end
129 130
 
130 131
   def test_with_model
1  actionwebservice/test/fixtures/db_definitions/mysql.sql
@@ -2,6 +2,7 @@ CREATE TABLE `users` (
2 2
   `id` int(11) NOT NULL auto_increment,
3 3
   `name` varchar(30) default NULL,
4 4
   `active` tinyint(4) default NULL,
  5
+  `balance` decimal(5, 2) default NULL,
5 6
   `created_on` date default NULL,
6 7
   PRIMARY KEY  (`id`)
7 8
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
2  actionwebservice/test/fixtures/users.yml
@@ -2,9 +2,11 @@ user1:
2 2
   id: 1
3 3
   name: Kent
4 4
   active: 1
  5
+  balance: 12.2
5 6
   created_on: <%= Date.today %>
6 7
 user2:
7 8
   id: 2
8 9
   name: David
9 10
   active: 1
  11
+  balance: 16.4
10 12
   created_on: <%= Date.today %>

0 notes on commit abe8fa7

Please sign in to comment.
Something went wrong with that request. Please try again.