11require 'abstract_unit'
22require 'active_support/core_ext/array'
33require 'active_support/core_ext/big_decimal'
4+ require 'active_support/core_ext/hash'
45require 'active_support/core_ext/object/conversions'
5-
6- require 'active_support/core_ext' # FIXME: pulling in all to_xml extensions
7- require 'active_support/hash_with_indifferent_access'
6+ require 'active_support/core_ext/string'
87
98class ArrayExtAccessTests < ActiveSupport ::TestCase
109 def test_from
@@ -234,7 +233,7 @@ def test_split_with_edge_values
234233end
235234
236235class ArrayToXmlTests < ActiveSupport ::TestCase
237- def test_to_xml
236+ def test_to_xml_with_hash_elements
238237 xml = [
239238 { :name => "David" , :age => 26 , :age_in_millis => 820497600000 } ,
240239 { :name => "Jason" , :age => 31 , :age_in_millis => BigDecimal . new ( '1.0' ) }
@@ -249,6 +248,22 @@ def test_to_xml
249248 assert xml . include? ( %(<name>Jason</name>) ) , xml
250249 end
251250
251+ def test_to_xml_with_non_hash_elements
252+ xml = [ 1 , 2 , 3 ] . to_xml ( :skip_instruct => true , :indent => 0 )
253+
254+ assert_equal '<fixnums type="array"><fixnum' , xml . first ( 29 )
255+ assert xml . include? ( %(<fixnum type="integer">2</fixnum>) ) , xml
256+ end
257+
258+ def test_to_xml_with_non_hash_different_type_elements
259+ xml = [ 1 , 2.0 , '3' ] . to_xml ( :skip_instruct => true , :indent => 0 )
260+
261+ assert_equal '<objects type="array"><object' , xml . first ( 29 )
262+ assert xml . include? ( %(<object type="integer">1</object>) ) , xml
263+ assert xml . include? ( %(<object type="float">2.0</object>) ) , xml
264+ assert xml . include? ( %(object>3</object>) ) , xml
265+ end
266+
252267 def test_to_xml_with_dedicated_name
253268 xml = [
254269 { :name => "David" , :age => 26 , :age_in_millis => 820497600000 } , { :name => "Jason" , :age => 31 }
@@ -269,6 +284,18 @@ def test_to_xml_with_options
269284 assert xml . include? ( %(<name>Jason</name>) )
270285 end
271286
287+ def test_to_xml_with_indent_set
288+ xml = [
289+ { :name => "David" , :street_address => "Paulina" } , { :name => "Jason" , :street_address => "Evergreen" }
290+ ] . to_xml ( :skip_instruct => true , :skip_types => true , :indent => 4 )
291+
292+ assert_equal "<objects>\n <object>" , xml . first ( 22 )
293+ assert xml . include? ( %(\n <street-address>Paulina</street-address>) )
294+ assert xml . include? ( %(\n <name>David</name>) )
295+ assert xml . include? ( %(\n <street-address>Evergreen</street-address>) )
296+ assert xml . include? ( %(\n <name>Jason</name>) )
297+ end
298+
272299 def test_to_xml_with_dasherize_false
273300 xml = [
274301 { :name => "David" , :street_address => "Paulina" } , { :name => "Jason" , :street_address => "Evergreen" }
@@ -289,7 +316,7 @@ def test_to_xml_with_dasherize_true
289316 assert xml . include? ( %(<street-address>Evergreen</street-address>) )
290317 end
291318
292- def test_to_with_instruct
319+ def test_to_xml_with_instruct
293320 xml = [
294321 { :name => "David" , :age => 26 , :age_in_millis => 820497600000 } ,
295322 { :name => "Jason" , :age => 31 , :age_in_millis => BigDecimal . new ( '1.0' ) }
0 commit comments