Sha256: 8c46ca9cadfea16dcedc278e2f261a0f3322e29194b000a5cacfdcc51a4c0942

Contents?: true

Size: 883 Bytes

Versions: 3

Compression:

Stored size: 883 Bytes

Contents

require 'spec_helper'

module Sheep
  class Item
    include HappyMapper
  end

  class Navigator
    include HappyMapper
    tag 'navigator'

    # This is purposefully set to have the name 'items' with the tag 'item'.
    # The idea is that it should not find the empty items contained within the
    # xml and return an empty array. This exercises the order of how nodes
    # are searched for within an XML document.
    has_many :items, Item, tag: 'item'

    has_many :items_with_a_different_name, Item, tag: 'item'
  end
end

describe 'emptyness' do
  let(:xml) do
    <<-EOF
    <navigator>
      <items/>
    </navigator>
    EOF
  end

  let(:navigator) do
    Sheep::Navigator.parse(xml)
  end

  it 'returns an empty array' do
    navigator.items_with_a_different_name.should be_empty
  end

  it 'returns an empty array' do
    navigator.items.should be_empty
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blockscore-happymapper-0.6.2 spec/has_many_empty_array_spec.rb
blockscore-happymapper-0.6.1 spec/has_many_empty_array_spec.rb
blockscore-happymapper-0.6.0 spec/has_many_empty_array_spec.rb