aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-13 16:11:21 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-13 16:11:21 -0300
commit0626543f6d4c45250da15f41d715754c3be5a67e (patch)
tree474f2fe2e186163966faa5e97e11d55662799d14
parent89d97560e76fa3839a033ae09d7a00d894af7362 (diff)
parent70710c976436d525d398f01a948e5d62328f9a3b (diff)
downloadrails-0626543f6d4c45250da15f41d715754c3be5a67e.tar.gz
rails-0626543f6d4c45250da15f41d715754c3be5a67e.tar.bz2
rails-0626543f6d4c45250da15f41d715754c3be5a67e.zip
Merge pull request #15073 from ifyouseewendy/master
Update and add tests in array_ext_test.rb
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb37
1 files changed, 32 insertions, 5 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 57722fd52a..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
@@ -234,7 +233,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 +248,22 @@ class ArrayToXmlTests < ActiveSupport::TestCase
assert xml.include?(%(<name>Jason</name>)), xml
end
+ def test_to_xml_with_non_hash_elements
+ xml = [1, 2, 3].to_xml(:skip_instruct => true, :indent => 0)
+
+ assert_equal '<fixnums type="array"><fixnum', xml.first(29)
+ assert xml.include?(%(<fixnum type="integer">2</fixnum>)), 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 '<objects type="array"><object', xml.first(29)
+ assert xml.include?(%(<object type="integer">1</object>)), xml
+ assert xml.include?(%(<object type="float">2.0</object>)), xml
+ assert xml.include?(%(object>3</object>)), xml
+ end
+
def test_to_xml_with_dedicated_name
xml = [
{ :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31 }
@@ -269,6 +284,18 @@ class ArrayToXmlTests < ActiveSupport::TestCase
assert xml.include?(%(<name>Jason</name>))
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 "<objects>\n <object>", xml.first(22)
+ assert xml.include?(%(\n <street-address>Paulina</street-address>))
+ assert xml.include?(%(\n <name>David</name>))
+ assert xml.include?(%(\n <street-address>Evergreen</street-address>))
+ assert xml.include?(%(\n <name>Jason</name>))
+ end
+
def test_to_xml_with_dasherize_false
xml = [
{ :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" }
@@ -289,7 +316,7 @@ class ArrayToXmlTests < ActiveSupport::TestCase
assert xml.include?(%(<street-address>Evergreen</street-address>))
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') }