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

Changeset 6532

Show
Ignore:
Timestamp:
04/16/07 22:17:59 (1 year ago)
Author:
david
Message:

Fixed that parameters from XML should also be presented in a hash with indifferent access [DHH] Hash#with_indifferent_access now also converts hashes kept in arrays to indifferent access (makes it easier to treat HTML and XML parameters the same) [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6522 r6532  
    11*SVN* 
     2 
     3* Fixed that parameters from XML should also be presented in a hash with indifferent access [DHH] 
    24 
    35* Tweak template format rules so that the ACCEPT header is only used if it's text/javascript.  This is so ajax actions without a :format param get recognized as Mime::JS. [Rick] 
  • trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb

    r6511 r6532  
    5050          strategy.call(raw_post_data) 
    5151        when :xml_simple, :xml_node 
    52           raw_post_data.blank? ? {} : Hash.from_xml(raw_post_data) 
     52          raw_post_data.blank? ? {} : Hash.from_xml(raw_post_data).with_indifferent_access 
    5353        when :yaml 
    5454          YAML.load(raw_post_data) 
  • trunk/activesupport/CHANGELOG

    r6444 r6532  
    11*SVN* 
     2 
     3* Hash#with_indifferent_access now also converts hashes kept in arrays to indifferent access (makes it easier to treat HTML and XML parameters the same) [DHH] 
    24 
    35* Hash#to_xml supports YAML attributes.  #7502 [jonathan] 
  • trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb

    r6444 r6532  
    112112              'keeproot'     => true, 
    113113              'contentkey'   => '__content__') 
    114             ))             
     114            )) 
    115115          end 
    116116           
  • trunk/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb

    r5725 r6532  
    7474      key.kind_of?(Symbol) ? key.to_s : key 
    7575    end 
     76 
    7677    def convert_value(value) 
    77       value.is_a?(Hash) ? value.with_indifferent_access : value 
     78      case value 
     79      when Hash 
     80        value.with_indifferent_access 
     81      when Array 
     82        value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e } 
     83      else 
     84        value 
     85      end 
    7886    end 
    7987end 
  • trunk/activesupport/test/core_ext/hash_ext_test.rb

    r6444 r6532  
    182182    assert_equal @strings, roundtrip 
    183183    assert_equal '1234', roundtrip.default 
     184  end 
     185 
     186  def test_indifferent_hash_with_array_of_hashes 
     187    hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] }}.with_indifferent_access 
     188    assert_equal "1", hash[:urls][:url].first[:address] 
    184189  end 
    185190