Sha256: 95a4bdea18174430138ef5e201da8736bbd54cca3a7339e4b78cf506f5f513ae

Contents?: true

Size: 1.54 KB

Versions: 14

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

module XML
  module Mapping

    class ArrayNodeSpecElem
      include ::XML::Mapping

      root_element_name 'array_node_spec_elem'

      array_node :child_nodes, 'child_nodes', 'child_node', class: String
    end

    describe ArrayNode do
      it 'reads nested nodes' do
        xml_str = '<array_node_spec_elem>
                     <child_nodes>
                       <child_node>foo</child_node>
                       <child_node>bar</child_node>
                     </child_nodes>
                   </array_node_spec_elem>'
        xml = REXML::Document.new(xml_str).root
        elem = ArrayNodeSpecElem.load_from_xml(xml)
        expect(elem.child_nodes).to eq(%w(foo bar))
      end

      it 'writes nested nodes' do
        elem = ArrayNodeSpecElem.new
        elem.child_nodes = %w(foo bar)
        xml = elem.save_to_xml
        expected_xml = '<array_node_spec_elem>
                          <child_nodes>
                            <child_node>foo</child_node>
                            <child_node>bar</child_node>
                          </child_nodes>
                        </array_node_spec_elem>'
        expect(xml).to be_xml(expected_xml)
      end

      it 'writes empty intermediate nodes for empty arrays' do
        elem = ArrayNodeSpecElem.new
        elem.child_nodes = []
        xml = elem.save_to_xml
        expected_xml = '<array_node_spec_elem>
                          <child_nodes/>
                        </array_node_spec_elem>'
        expect(xml).to be_xml(expected_xml)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
xml-mapping_extensions-0.4.7 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.6 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.5 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.4 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.3 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.2 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.1 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.4.0 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.3.7 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.3.6 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.3.5 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.3.4 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.3.3 spec/unit/xml/mapping_extensions/array_node_spec.rb
xml-mapping_extensions-0.3.2 spec/unit/xml/mapping_extensions/array_node_spec.rb