1
1
require 'abstract_unit'
2
2
require 'active_support/core_ext/array'
3
3
require 'active_support/core_ext/big_decimal'
4
+ require 'active_support/core_ext/hash'
4
5
require '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'
8
7
9
8
class ArrayExtAccessTests < ActiveSupport ::TestCase
10
9
def test_from
@@ -234,7 +233,7 @@ def test_split_with_edge_values
234
233
end
235
234
236
235
class ArrayToXmlTests < ActiveSupport ::TestCase
237
- def test_to_xml
236
+ def test_to_xml_with_hash_elements
238
237
xml = [
239
238
{ :name => "David" , :age => 26 , :age_in_millis => 820497600000 } ,
240
239
{ :name => "Jason" , :age => 31 , :age_in_millis => BigDecimal . new ( '1.0' ) }
@@ -249,6 +248,22 @@ def test_to_xml
249
248
assert xml . include? ( %(<name>Jason</name>) ) , xml
250
249
end
251
250
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
+
252
267
def test_to_xml_with_dedicated_name
253
268
xml = [
254
269
{ :name => "David" , :age => 26 , :age_in_millis => 820497600000 } , { :name => "Jason" , :age => 31 }
@@ -269,6 +284,18 @@ def test_to_xml_with_options
269
284
assert xml . include? ( %(<name>Jason</name>) )
270
285
end
271
286
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
+
272
299
def test_to_xml_with_dasherize_false
273
300
xml = [
274
301
{ :name => "David" , :street_address => "Paulina" } , { :name => "Jason" , :street_address => "Evergreen" }
@@ -289,7 +316,7 @@ def test_to_xml_with_dasherize_true
289
316
assert xml . include? ( %(<street-address>Evergreen</street-address>) )
290
317
end
291
318
292
- def test_to_with_instruct
319
+ def test_to_xml_with_instruct
293
320
xml = [
294
321
{ :name => "David" , :age => 26 , :age_in_millis => 820497600000 } ,
295
322
{ :name => "Jason" , :age => 31 , :age_in_millis => BigDecimal . new ( '1.0' ) }
0 commit comments