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 529 529 530 530 assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] 531 531 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 533 555 def test_empty_array_from_xml 534 556 blog_xml = <<-XML 535 557 <blog> -
activesupport/lib/active_support/core_ext/hash/conversions.rb
old new 72 72 "integer" => Proc.new { |integer| integer.to_i }, 73 73 "float" => Proc.new { |float| float.to_f }, 74 74 "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) }, 76 76 "string" => Proc.new { |string| string.to_s }, 77 77 "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, 78 78 "base64Binary" => Proc.new { |bin| Base64.decode64(bin) },