提交 abe8fa73 编写于 作者: K Kent Sibilev

Added support for decimal types. Closes #6676.



git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5670 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 db459370
*SVN* *SVN*
* Added support for decimal types. Closes #6676. [Kent Sibilev]
* Removed deprecated end_form_tag helper. [Kent Sibilev] * Removed deprecated end_form_tag helper. [Kent Sibilev]
* Removed deprecated @request and @response usages. [Kent Sibilev] * Removed deprecated @request and @response usages. [Kent Sibilev]
......
...@@ -95,6 +95,8 @@ def cast_base_type(value, signature_type) # :nodoc: ...@@ -95,6 +95,8 @@ def cast_base_type(value, signature_type) # :nodoc:
end end
when :float when :float
Float(value) Float(value)
when :decimal
BigDecimal(value.to_s)
when :time 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 = "%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) value.kind_of?(Time) ? value : Time.parse(value.to_s)
......
...@@ -118,18 +118,12 @@ def soap_type_name(type_name) ...@@ -118,18 +118,12 @@ def soap_type_name(type_name)
end end
def register_static_factories def register_static_factories
@registry.add(ActionWebService::Base64, @registry.add(ActionWebService::Base64, SOAP::SOAPBase64, SoapBase64Factory.new, nil)
SOAP::SOAPBase64,
SoapBase64Factory.new,
nil)
mapping = @registry.find_mapped_soap_class(ActionWebService::Base64) mapping = @registry.find_mapped_soap_class(ActionWebService::Base64)
@type2binding[ActionWebService::Base64] = @type2binding[ActionWebService::Base64] =
SoapBinding.new(self, SOAP::SOAPBase64::Type, SoapBinding.new(self, SOAP::SOAPBase64::Type, ActionWebService::Base64, mapping)
ActionWebService::Base64, mapping) @registry.add(Array, SOAP::SOAPArray, SoapTypedArrayFactory.new, nil)
@registry.add(Array, @registry.add(::BigDecimal, SOAP::SOAPDouble, SOAP::Mapping::Registry::BasetypeFactory, {:derived_class => true})
SOAP::SOAPArray,
SoapTypedArrayFactory.new,
nil)
end end
end end
......
...@@ -5,6 +5,16 @@ module XMLRPC # :nodoc: ...@@ -5,6 +5,16 @@ module XMLRPC # :nodoc:
class FaultException # :nodoc: class FaultException # :nodoc:
alias :message :faultString alias :message :faultString
end end
class Create
def wrong_type(value)
if BigDecimal === value
[true, value.to_f]
else
false
end
end
end
end end
module ActionWebService # :nodoc: module ActionWebService # :nodoc:
......
...@@ -61,6 +61,8 @@ def canonical_type_name(name) # :nodoc: ...@@ -61,6 +61,8 @@ def canonical_type_name(name) # :nodoc:
:bool :bool
when :float, :double when :float, :double
:float :float
when :decimal
:decimal
when :time, :timestamp when :time, :timestamp
:time :time
when :datetime when :datetime
...@@ -117,6 +119,8 @@ def type_name_to_class(name) # :nodoc: ...@@ -117,6 +119,8 @@ def type_name_to_class(name) # :nodoc:
TrueClass TrueClass
when :float when :float
Float Float
when :decimal
BigDecimal
when :time when :time
Time Time
when :date when :date
......
...@@ -126,6 +126,7 @@ def test_model_return ...@@ -126,6 +126,7 @@ def test_model_return
assert user.active? assert user.active?
assert_kind_of Date, user.created_on assert_kind_of Date, user.created_on
assert_equal Date.today, user.created_on assert_equal Date.today, user.created_on
assert_equal BigDecimal('12.2'), user.balance
end end
def test_with_model def test_with_model
......
...@@ -125,6 +125,7 @@ def test_model_return ...@@ -125,6 +125,7 @@ def test_model_return
assert user.active? assert user.active?
assert_kind_of Time, user.created_on 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 Time.utc(Time.now.year, Time.now.month, Time.now.day), user.created_on
assert_equal BigDecimal('12.2'), user.balance
end end
def test_with_model def test_with_model
......
...@@ -2,6 +2,7 @@ CREATE TABLE `users` ( ...@@ -2,6 +2,7 @@ CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`name` varchar(30) default NULL, `name` varchar(30) default NULL,
`active` tinyint(4) default NULL, `active` tinyint(4) default NULL,
`balance` decimal(5, 2) default NULL,
`created_on` date default NULL, `created_on` date default NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
...@@ -2,9 +2,11 @@ user1: ...@@ -2,9 +2,11 @@ user1:
id: 1 id: 1
name: Kent name: Kent
active: 1 active: 1
balance: 12.2
created_on: <%= Date.today %> created_on: <%= Date.today %>
user2: user2:
id: 2 id: 2
name: David name: David
active: 1 active: 1
balance: 16.4
created_on: <%= Date.today %> created_on: <%= Date.today %>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册