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

Ticket #9839: mixed_case_boolean_from_xml.patch

File mixed_case_boolean_from_xml.patch, 2.0 kB (added by dkubb, 1 year ago)
  • activesupport/test/core_ext/hash_ext_test.rb

    old new  
    529529 
    530530    assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] 
    531531  end 
    532    
     532 
     533  def test_mixed_case_boolean_from_xml 
     534    user_xml = <<-XML 
     535      <user> 
     536        <active type="boolean"> T </active> 
     537        <approved type="boolean"> True </approved> 
     538        <confirmed type="boolean"> t </confirmed> 
     539        <opted-in type="boolean"> true </opted-in> 
     540        <admin type="boolean"> 1 </admin> 
     541      </user> 
     542    XML 
     543 
     544    expected_user_hash = { 
     545      :approved  => true, 
     546      :confirmed => true, 
     547      :active    => true, 
     548      :opted_in  => true, 
     549      :admin     => true, 
     550    }.stringify_keys 
     551 
     552    assert_equal expected_user_hash, Hash.from_xml(user_xml)['user'] 
     553  end 
     554 
    533555  def test_empty_array_from_xml 
    534556    blog_xml = <<-XML 
    535557      <blog> 
  • activesupport/lib/active_support/core_ext/hash/conversions.rb

    old new  
    7272            "integer"      => Proc.new  { |integer| integer.to_i }, 
    7373            "float"        => Proc.new  { |float|   float.to_f }, 
    7474            "decimal"      => Proc.new  { |number|  BigDecimal(number) }, 
    75             "boolean"      => Proc.new  { |boolean| %w(1 true).include?(boolean.strip) }, 
     75            "boolean"      => Proc.new  { |boolean| %w(true t 1).include?(boolean.strip.downcase) }, 
    7676            "string"       => Proc.new  { |string|  string.to_s }, 
    7777            "yaml"         => Proc.new  { |yaml|    YAML::load(yaml) rescue yaml }, 
    7878            "base64Binary" => Proc.new  { |bin|     Base64.decode64(bin) },