Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8937

Show
Ignore:
Timestamp:
02/27/08 23:11:08 (6 months ago)
Author:
bitsweat
Message:

Fix Hash#from_xml with Type records. Closes #9242 [Juanjo Bazan, Isaac Feliu]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/test/controller/webservice_test.rb

    r8564 r8937  
    5757    assert_equal 'true', @controller.params["entry"]['attributed'] 
    5858  end 
    59    
     59 
    6060  def test_put_xml 
    6161    process('PUT', 'application/xml', '<entry attributed="true"><summary>content...</summary></entry>') 
    62      
     62 
    6363    assert_equal 'entry', @controller.response.body 
    6464    assert @controller.params.has_key?(:entry) 
    6565    assert_equal 'content...', @controller.params["entry"]['summary'] 
    6666    assert_equal 'true', @controller.params["entry"]['attributed'] 
     67  end 
     68 
     69  def test_put_xml_using_a_type_node 
     70    process('PUT', 'application/xml', '<type attributed="true"><summary>content...</summary></type>') 
     71 
     72    assert_equal 'type', @controller.response.body 
     73    assert @controller.params.has_key?(:type) 
     74    assert_equal 'content...', @controller.params["type"]['summary'] 
     75    assert_equal 'true', @controller.params["type"]['attributed'] 
     76  end 
     77 
     78  def test_put_xml_using_a_type_node_and_attribute 
     79    process('PUT', 'application/xml', '<type attributed="true"><summary type="boolean">false</summary></type>') 
     80 
     81    assert_equal 'type', @controller.response.body 
     82    assert @controller.params.has_key?(:type) 
     83    assert_equal false, @controller.params["type"]['summary'] 
     84    assert_equal 'true', @controller.params["type"]['attributed'] 
     85  end 
     86 
     87  def test_post_xml_using_a_type_node 
     88    process('POST', 'application/xml', '<font attributed="true"><type>arial</type></font>') 
     89 
     90    assert_equal 'font', @controller.response.body 
     91    assert @controller.params.has_key?(:font) 
     92    assert_equal 'arial', @controller.params['font']['type'] 
     93    assert_equal 'true', @controller.params["font"]['attributed'] 
     94  end 
     95 
     96  def test_post_xml_using_a_root_node_named_type 
     97    process('POST', 'application/xml', '<type type="integer">33</type>') 
     98 
     99    assert @controller.params.has_key?(:type) 
     100    assert_equal 33, @controller.params['type'] 
     101  end 
     102 
     103  def test_post_xml_using_an_attributted_node_named_type 
     104    ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) } 
     105    process('POST', 'application/xml', '<request><type type="string">Arial,12</type><z>3</z></request>') 
     106 
     107    assert_equal 'type, z', @controller.response.body 
     108    assert @controller.params.has_key?(:type) 
     109    assert_equal 'string', @controller.params['type']['type'] 
     110    assert_equal 'Arial,12', @controller.params['type']['content'] 
     111    assert_equal '3', @controller.params['z'] 
    67112  end 
    68113 
  • trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb

    r8817 r8937  
    212212                    nil 
    213213                  # If the type is the only element which makes it then  
    214                   # this still makes the value nil 
    215                   elsif value['type'] && value.size == 1 
     214                  # this still makes the value nil, except if type is 
     215                  # a xml node(where type['value'] is a Hash) 
     216                  elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash) 
    216217                    nil 
    217218                  else