aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-27 23:11:08 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-27 23:11:08 +0000
commit5e836127663f96ef6597f7dcdac3d14cc052fce3 (patch)
tree6ed9a3c1f0d7e1586bc11490e8fae382cd650ccb
parent8352287c725c09ad64db39bd54a69efdae3cdce4 (diff)
downloadrails-5e836127663f96ef6597f7dcdac3d14cc052fce3.tar.gz
rails-5e836127663f96ef6597f7dcdac3d14cc052fce3.tar.bz2
rails-5e836127663f96ef6597f7dcdac3d14cc052fce3.zip
Fix Hash#from_xml with Type records. Closes #9242 [Juanjo Bazan, Isaac Feliu]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8937 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/test/controller/webservice_test.rb49
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb5
2 files changed, 50 insertions, 4 deletions
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb
index 1ef1392236..32f67ddd6c 100644
--- a/actionpack/test/controller/webservice_test.rb
+++ b/actionpack/test/controller/webservice_test.rb
@@ -56,16 +56,61 @@ class WebServiceTest < Test::Unit::TestCase
assert_equal 'content...', @controller.params["entry"]['summary']
assert_equal 'true', @controller.params["entry"]['attributed']
end
-
+
def test_put_xml
process('PUT', 'application/xml', '<entry attributed="true"><summary>content...</summary></entry>')
-
+
assert_equal 'entry', @controller.response.body
assert @controller.params.has_key?(:entry)
assert_equal 'content...', @controller.params["entry"]['summary']
assert_equal 'true', @controller.params["entry"]['attributed']
end
+ def test_put_xml_using_a_type_node
+ process('PUT', 'application/xml', '<type attributed="true"><summary>content...</summary></type>')
+
+ assert_equal 'type', @controller.response.body
+ assert @controller.params.has_key?(:type)
+ assert_equal 'content...', @controller.params["type"]['summary']
+ assert_equal 'true', @controller.params["type"]['attributed']
+ end
+
+ def test_put_xml_using_a_type_node_and_attribute
+ process('PUT', 'application/xml', '<type attributed="true"><summary type="boolean">false</summary></type>')
+
+ assert_equal 'type', @controller.response.body
+ assert @controller.params.has_key?(:type)
+ assert_equal false, @controller.params["type"]['summary']
+ assert_equal 'true', @controller.params["type"]['attributed']
+ end
+
+ def test_post_xml_using_a_type_node
+ process('POST', 'application/xml', '<font attributed="true"><type>arial</type></font>')
+
+ assert_equal 'font', @controller.response.body
+ assert @controller.params.has_key?(:font)
+ assert_equal 'arial', @controller.params['font']['type']
+ assert_equal 'true', @controller.params["font"]['attributed']
+ end
+
+ def test_post_xml_using_a_root_node_named_type
+ process('POST', 'application/xml', '<type type="integer">33</type>')
+
+ assert @controller.params.has_key?(:type)
+ assert_equal 33, @controller.params['type']
+ end
+
+ def test_post_xml_using_an_attributted_node_named_type
+ ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) }
+ process('POST', 'application/xml', '<request><type type="string">Arial,12</type><z>3</z></request>')
+
+ assert_equal 'type, z', @controller.response.body
+ assert @controller.params.has_key?(:type)
+ assert_equal 'string', @controller.params['type']['type']
+ assert_equal 'Arial,12', @controller.params['type']['content']
+ assert_equal '3', @controller.params['z']
+ end
+
def test_register_and_use_yaml
ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) }
process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml)
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 470537fe24..3d6a8d8588 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -211,8 +211,9 @@ module ActiveSupport #:nodoc:
elsif value.blank? || value['nil'] == 'true'
nil
# If the type is the only element which makes it then
- # this still makes the value nil
- elsif value['type'] && value.size == 1
+ # this still makes the value nil, except if type is
+ # a xml node(where type['value'] is a Hash)
+ elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash)
nil
else
xml_value = value.inject({}) do |h,(k,v)|