From 9eadf528e9c61ec7fb1beb7a6466e89a8caeacd8 Mon Sep 17 00:00:00 2001 From: wendi Date: Tue, 13 May 2014 00:39:48 +0800 Subject: Update and add tests in array_ext_test.rb - Fix `test_to_with_instruct` typo to `test_to_xml_with_instruct` - Rename `test_to_xml` to `test_to_xml_with_hash_elements` to make test name more specific. - Add `test_to_xml_with_non_hash_elements` and `test_to_xml_with_non_hash_different_type_elements` `to_xml` behaves different when containing elements are same and different types. - Add `test_to_xml_with_indent_set` --- activesupport/test/core_ext/array_ext_test.rb | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'activesupport/test/core_ext/array_ext_test.rb') diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 57722fd52a..8c344b89cc 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -234,7 +234,7 @@ class ArraySplitTests < ActiveSupport::TestCase end class ArrayToXmlTests < ActiveSupport::TestCase - def test_to_xml + def test_to_xml_with_hash_elements xml = [ { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } @@ -249,6 +249,22 @@ class ArrayToXmlTests < ActiveSupport::TestCase assert xml.include?(%(Jason)), xml end + def test_to_xml_with_non_hash_elements + xml = [1, 2, 3].to_xml(:skip_instruct => true, :indent => 0) + + assert_equal '2)), xml + end + + def test_to_xml_with_non_hash_different_type_elements + xml = [1, 2.0, '3'].to_xml(:skip_instruct => true, :indent => 0) + + assert_equal '1)), xml + assert xml.include?(%(2.0)), xml + assert xml.include?(%(object>3)), xml + end + def test_to_xml_with_dedicated_name xml = [ { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 } @@ -269,6 +285,18 @@ class ArrayToXmlTests < ActiveSupport::TestCase assert xml.include?(%(Jason)) end + def test_to_xml_with_indent_set + xml = [ + { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } + ].to_xml(:skip_instruct => true, :skip_types => true, :indent => 4) + + assert_equal "\n ", xml.first(22) + assert xml.include?(%(\n Paulina)) + assert xml.include?(%(\n David)) + assert xml.include?(%(\n Evergreen)) + assert xml.include?(%(\n Jason)) + end + def test_to_xml_with_dasherize_false xml = [ { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } @@ -289,7 +317,7 @@ class ArrayToXmlTests < ActiveSupport::TestCase assert xml.include?(%(Evergreen)) end - def test_to_with_instruct + def test_to_xml_with_instruct xml = [ { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } -- cgit v1.2.3 From 70710c976436d525d398f01a948e5d62328f9a3b Mon Sep 17 00:00:00 2001 From: wendi Date: Tue, 13 May 2014 02:11:49 +0800 Subject: Update require in `array_ext_test.rb` Removed `FIMXE` tag to require necessary file but not the whole core_ext --- activesupport/test/core_ext/array_ext_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activesupport/test/core_ext/array_ext_test.rb') diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 8c344b89cc..e0e54f47e4 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -1,10 +1,9 @@ require 'abstract_unit' require 'active_support/core_ext/array' require 'active_support/core_ext/big_decimal' +require 'active_support/core_ext/hash' require 'active_support/core_ext/object/conversions' - -require 'active_support/core_ext' # FIXME: pulling in all to_xml extensions -require 'active_support/hash_with_indifferent_access' +require 'active_support/core_ext/string' class ArrayExtAccessTests < ActiveSupport::TestCase def test_from -- cgit v1.2.3