diff --git a/actionwebservice/CHANGELOG b/actionwebservice/CHANGELOG index a07042d1d59a7f92655753021c97b4f8b266f686..2ed40aac48ef0d043f2d05af1de4659d36b4b032 100644 --- a/actionwebservice/CHANGELOG +++ b/actionwebservice/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added support for decimal types. Closes #6676. [Kent Sibilev] + * Removed deprecated end_form_tag helper. [Kent Sibilev] * Removed deprecated @request and @response usages. [Kent Sibilev] diff --git a/actionwebservice/lib/action_web_service/casting.rb b/actionwebservice/lib/action_web_service/casting.rb index 71cdf4e0555adcf5a2de4dcedee68f0b2e6b3ab5..71f422eaea0388b9cf5ba5ef522601998bcc2da0 100644 --- a/actionwebservice/lib/action_web_service/casting.rb +++ b/actionwebservice/lib/action_web_service/casting.rb @@ -95,6 +95,8 @@ def cast_base_type(value, signature_type) # :nodoc: end when :float Float(value) + when :decimal + BigDecimal(value.to_s) when :time value = "%s/%s/%s %s:%s:%s" % value.values_at(*%w[2 3 1 4 5 6]) if value.kind_of?(Hash) value.kind_of?(Time) ? value : Time.parse(value.to_s) diff --git a/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb b/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb index 351c9da1593b69e8af0064f9cd9413bfdcfd5af1..187339627770eb3586329b2070301701a7e368f5 100644 --- a/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb +++ b/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb @@ -118,18 +118,12 @@ def soap_type_name(type_name) end def register_static_factories - @registry.add(ActionWebService::Base64, - SOAP::SOAPBase64, - SoapBase64Factory.new, - nil) + @registry.add(ActionWebService::Base64, SOAP::SOAPBase64, SoapBase64Factory.new, nil) mapping = @registry.find_mapped_soap_class(ActionWebService::Base64) @type2binding[ActionWebService::Base64] = - SoapBinding.new(self, SOAP::SOAPBase64::Type, - ActionWebService::Base64, mapping) - @registry.add(Array, - SOAP::SOAPArray, - SoapTypedArrayFactory.new, - nil) + SoapBinding.new(self, SOAP::SOAPBase64::Type, ActionWebService::Base64, mapping) + @registry.add(Array, SOAP::SOAPArray, SoapTypedArrayFactory.new, nil) + @registry.add(::BigDecimal, SOAP::SOAPDouble, SOAP::Mapping::Registry::BasetypeFactory, {:derived_class => true}) end end diff --git a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb index a3abc6a24d6aad22594df208336bcb65b8fe8913..8ec36a29f1bf5504a2b5924bc7d9e84915b9471c 100644 --- a/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb +++ b/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb @@ -5,6 +5,16 @@ module XMLRPC # :nodoc: class FaultException # :nodoc: alias :message :faultString end + + class Create + def wrong_type(value) + if BigDecimal === value + [true, value.to_f] + else + false + end + end + end end module ActionWebService # :nodoc: diff --git a/actionwebservice/lib/action_web_service/support/signature_types.rb b/actionwebservice/lib/action_web_service/support/signature_types.rb index 36224c645e26b119bfe27398cf7c67bdd0df599a..66c86bf6daecd1fb3e1bc35b9973bbba0c2f80b1 100644 --- a/actionwebservice/lib/action_web_service/support/signature_types.rb +++ b/actionwebservice/lib/action_web_service/support/signature_types.rb @@ -61,6 +61,8 @@ def canonical_type_name(name) # :nodoc: :bool when :float, :double :float + when :decimal + :decimal when :time, :timestamp :time when :datetime @@ -117,6 +119,8 @@ def type_name_to_class(name) # :nodoc: TrueClass when :float Float + when :decimal + BigDecimal when :time Time when :date diff --git a/actionwebservice/test/client_soap_test.rb b/actionwebservice/test/client_soap_test.rb index c03c24141f57dea28535915f9ab9ff6b643163d5..914bf377ea80e8e41d83a23b28b08d1ff7298f4b 100644 --- a/actionwebservice/test/client_soap_test.rb +++ b/actionwebservice/test/client_soap_test.rb @@ -126,6 +126,7 @@ def test_model_return assert user.active? assert_kind_of Date, user.created_on assert_equal Date.today, user.created_on + assert_equal BigDecimal('12.2'), user.balance end def test_with_model diff --git a/actionwebservice/test/client_xmlrpc_test.rb b/actionwebservice/test/client_xmlrpc_test.rb index 0abd5898d82d4385fe706f90782d9755e917d150..896ec5951cff440442db9a145d64e9e1f902c3a7 100644 --- a/actionwebservice/test/client_xmlrpc_test.rb +++ b/actionwebservice/test/client_xmlrpc_test.rb @@ -125,6 +125,7 @@ def test_model_return assert user.active? assert_kind_of Time, user.created_on assert_equal Time.utc(Time.now.year, Time.now.month, Time.now.day), user.created_on + assert_equal BigDecimal('12.2'), user.balance end def test_with_model diff --git a/actionwebservice/test/fixtures/db_definitions/mysql.sql b/actionwebservice/test/fixtures/db_definitions/mysql.sql index 026f2a2c64b52c7d0351c35db54e4ced7a8ffbc0..8e01eef4534b4964f0e80863e31bce54609b1487 100644 --- a/actionwebservice/test/fixtures/db_definitions/mysql.sql +++ b/actionwebservice/test/fixtures/db_definitions/mysql.sql @@ -2,6 +2,7 @@ CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `name` varchar(30) default NULL, `active` tinyint(4) default NULL, + `balance` decimal(5, 2) default NULL, `created_on` date default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; diff --git a/actionwebservice/test/fixtures/users.yml b/actionwebservice/test/fixtures/users.yml index a97d8c848616fc07ab5b2e58f51f9590fb603b15..926d6015f50f9a340927b518db40910ed9b72d49 100644 --- a/actionwebservice/test/fixtures/users.yml +++ b/actionwebservice/test/fixtures/users.yml @@ -2,9 +2,11 @@ user1: id: 1 name: Kent active: 1 + balance: 12.2 created_on: <%= Date.today %> user2: id: 2 name: David active: 1 + balance: 16.4 created_on: <%= Date.today %>