diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-06-05 14:09:15 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-06-05 14:09:15 +0000 |
commit | ed1ed9ed97f7d30ba8221079365634aa9c4bf24c (patch) | |
tree | 4564504ab18ee63adf2191595513141833430245 | |
parent | 319107ae40bc00772f4eaf91ab9531097bc537cb (diff) | |
download | rails-ed1ed9ed97f7d30ba8221079365634aa9c4bf24c.tar.gz rails-ed1ed9ed97f7d30ba8221079365634aa9c4bf24c.tar.bz2 rails-ed1ed9ed97f7d30ba8221079365634aa9c4bf24c.zip |
revert [6924]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6946 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activesupport/CHANGELOG | 23 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 14 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 39 |
5 files changed, 5 insertions, 77 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index b6f9534f47..40e811c7e0 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -8,29 +8,6 @@ * Readable Date and DateTime#inspect. #8570 [Geoff Buesing] -* Added proper handling of arrays #8537 [hasmanyjosh] - - Before: - Hash.from_xml '<images></images>' - # => {:images => nil} - - Hash.from_xml '<images><image>foo.jpg</image></images>' - # => {:images => {:image => "foo.jpg"}} - - Hash.from_xml '<images><image>foo.jpg</image><image>bar.jpg</image></images>' - # => {:images => {:image => ["foo.jpg", "bar.jpg"]}} - - After: - Hash.from_xml '<images type="array"></images>' - # => {:images => []} - - Hash.from_xml '<images type="array"><image>foo.jpg</image></images>' - # => {:images => ["foo.jpg"]} - - Hash.from_xml '<images type="array"><image>foo.jpg</image><image>bar.jpg</image></images>' - # => {:images => ["foo.jpg", "bar.jpg"]} - - * Move common DateTime calculations to Date. #8536 [Geoff Buesing] * Added Date#change (like Time#change) [DHH] diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 6950e21027..a4d056e81c 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -63,7 +63,7 @@ module ActiveSupport #:nodoc: opts = options.merge({ :root => children }) - options[:builder].tag!(root, options[:skip_types] ? {} : {:type => "array"}) { + options[:builder].tag!(root) { yield options[:builder] if block_given? each { |e| e.to_xml(opts.merge!({ :skip_instruct => true })) } } diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 2cccd9c30e..2334bb671b 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -163,20 +163,6 @@ module ActiveSupport #:nodoc: else content end - elsif value['type'] == 'array' - child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway - if entries.nil? - [] - else - case entries.class.to_s # something weird with classes not matching here. maybe singleton methods breaking is_a? - when "Array" - entries.collect { |v| typecast_xml_value(v) } - when "Hash" - [typecast_xml_value(entries)] - else - raise "can't typecast #{entries.inspect}" - end - end elsif value['type'] == 'string' && value['nil'] != 'true' "" else diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 8c5356ac78..e5ca4c424f 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -121,7 +121,7 @@ class ArrayToXmlTests < Test::Unit::TestCase { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } ].to_xml(:skip_instruct => true, :indent => 0) - assert_equal '<records type="array"><record>', xml.first(30) + assert_equal "<records><record>", xml.first(17), xml assert xml.include?(%(<age type="integer">26</age>)), xml assert xml.include?(%(<age-in-millis type="integer">820497600000</age-in-millis>)), xml assert xml.include?(%(<name>David</name>)), xml @@ -135,7 +135,7 @@ class ArrayToXmlTests < Test::Unit::TestCase { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 } ].to_xml(:skip_instruct => true, :indent => 0, :root => "people") - assert_equal '<people type="array"><person>', xml.first(29) + assert_equal "<people><person>", xml.first(16) end def test_to_xml_with_options diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 73b873aee8..a428fe5061 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -370,7 +370,7 @@ class HashToXmlTest < Test::Unit::TestCase def test_two_levels_with_array xml = { :name => "David", :addresses => [{ :street => "Paulina" }, { :street => "Evergreen" }] }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) - assert xml.include?(%(<addresses type="array"><address>)) + assert xml.include?(%(<addresses><address>)) assert xml.include?(%(<address><street>Paulina</street></address>)) assert xml.include?(%(<address><street>Evergreen</street></address>)) assert xml.include?(%(<name>David</name>)) @@ -378,7 +378,7 @@ class HashToXmlTest < Test::Unit::TestCase def test_three_levels_with_array xml = { :name => "David", :addresses => [{ :streets => [ { :name => "Paulina" }, { :name => "Paulina" } ] } ] }.to_xml(@xml_options) - assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>)) + assert xml.include?(%(<addresses><address><streets><street><name>)) end def test_single_record_from_xml @@ -516,41 +516,6 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] end - - def test_empty_array_from_xml - blog_xml = <<-XML - <blog> - <posts type="array"></posts> - </blog> - XML - expected_blog_hash = {"blog" => {"posts" => []}} - assert_equal expected_blog_hash, Hash.from_xml(blog_xml) - end - - def test_array_with_one_entry_from_xml - blog_xml = <<-XML - <blog> - <posts type="array"> - <post>a post</post> - </posts> - </blog> - XML - expected_blog_hash = {"blog" => {"posts" => ["a post"]}} - assert_equal expected_blog_hash, Hash.from_xml(blog_xml) - end - - def test_array_with_multiple_entries_from_xml - blog_xml = <<-XML - <blog> - <posts type="array"> - <post>a post</post> - <post>another post</post> - </posts> - </blog> - XML - expected_blog_hash = {"blog" => {"posts" => ["a post", "another post"]}} - assert_equal expected_blog_hash, Hash.from_xml(blog_xml) - end def test_xsd_like_types_from_xml bacon_xml = <<-EOT |