class ToXmlTest
Public Instance Methods
test_to_xml_dups_options()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 199 def test_to_xml_dups_options options = { skip_instruct: true } [].to_xml(options) # :builder, etc, shouldn't be added to options assert_equal({ skip_instruct: true }, options) end
test_to_xml_with_block()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 183 def test_to_xml_with_block xml = [ { name: "David", age: 26, age_in_millis: 820497600000 }, { name: "Jason", age: 31, age_in_millis: BigDecimal.new("1.0") } ].to_xml(skip_instruct: true, indent: 0) do |builder| builder.count 2 end assert_includes xml, %(<count>2</count>), xml end
test_to_xml_with_dasherize_false()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 153 def test_to_xml_with_dasherize_false xml = [ { name: "David", street_address: "Paulina" }, { name: "Jason", street_address: "Evergreen" } ].to_xml(skip_instruct: true, skip_types: true, indent: 0, dasherize: false) assert_equal "<objects><object>", xml.first(17) assert_includes xml, %(<street_address>Paulina</street_address>) assert_includes xml, %(<street_address>Evergreen</street_address>) end
test_to_xml_with_dasherize_true()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 163 def test_to_xml_with_dasherize_true xml = [ { name: "David", street_address: "Paulina" }, { name: "Jason", street_address: "Evergreen" } ].to_xml(skip_instruct: true, skip_types: true, indent: 0, dasherize: true) assert_equal "<objects><object>", xml.first(17) assert_includes xml, %(<street-address>Paulina</street-address>) assert_includes xml, %(<street-address>Evergreen</street-address>) end
test_to_xml_with_dedicated_name()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 121 def test_to_xml_with_dedicated_name xml = [ { 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) end
test_to_xml_with_empty()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 194 def test_to_xml_with_empty xml = [].to_xml assert_match(/type="array"\/>/, xml) end
test_to_xml_with_hash_elements()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 90 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") } ].to_xml(skip_instruct: true, indent: 0) assert_equal '<objects type="array"><object>', xml.first(30) assert_includes xml, %(<age type="integer">26</age>), xml assert_includes xml, %(<age-in-millis type="integer">820497600000</age-in-millis>), xml assert_includes xml, %(<name>David</name>), xml assert_includes xml, %(<age type="integer">31</age>), xml assert_includes xml, %(<age-in-millis type="decimal">1.0</age-in-millis>), xml assert_includes xml, %(<name>Jason</name>), xml end
test_to_xml_with_indent_set()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 141 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_includes xml, %(\n <street-address>Paulina</street-address>) assert_includes xml, %(\n <name>David</name>) assert_includes xml, %(\n <street-address>Evergreen</street-address>) assert_includes xml, %(\n <name>Jason</name>) end
test_to_xml_with_instruct()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 173 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") } ].to_xml(skip_instruct: false, indent: 0) assert_match(/^<\?xml [^>]*/, xml) assert_equal 0, xml.rindex(/<\?xml /) end
test_to_xml_with_non_hash_different_type_elements()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 112 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_includes xml, %(<object type="integer">1</object>), xml assert_includes xml, %(<object type="float">2.0</object>), xml assert_includes xml, %(object>3</object>), xml end
test_to_xml_with_non_hash_elements()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 105 def test_to_xml_with_non_hash_elements xml = %w[1 2 3].to_xml(skip_instruct: true, indent: 0) assert_equal '<strings type="array"><string', xml.first(29) assert_includes xml, %(<string>2</string>), xml end
test_to_xml_with_options()
click to toggle source
# File activesupport/test/core_ext/array/conversions_test.rb, line 129 def test_to_xml_with_options xml = [ { name: "David", street_address: "Paulina" }, { name: "Jason", street_address: "Evergreen" } ].to_xml(skip_instruct: true, skip_types: true, indent: 0) assert_equal "<objects><object>", xml.first(17) assert_includes xml, %(<street-address>Paulina</street-address>) assert_includes xml, %(<name>David</name>) assert_includes xml, %(<street-address>Evergreen</street-address>) assert_includes xml, %(<name>Jason</name>) end