diff --git a/lib/diaspora_federation/parsers/xml_parser.rb b/lib/diaspora_federation/parsers/xml_parser.rb index 2e04418..d8295dc 100644 --- a/lib/diaspora_federation/parsers/xml_parser.rb +++ b/lib/diaspora_federation/parsers/xml_parser.rb @@ -12,7 +12,7 @@ module DiasporaFederation def parse(root_node) from_xml_sanity_validation(root_node) - hash = root_node.element_children.map {|child| + hash = root_node.element_children.uniq(&:name).map {|child| xml_name = child.name property = entity_type.find_property_for_xml_name(xml_name) if property diff --git a/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb b/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb index fdcf4b6..9183314 100644 --- a/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb +++ b/spec/lib/diaspora_federation/parsers/xml_parser_spec.rb @@ -149,6 +149,14 @@ XML expect(parsed[0][:multi].first.to_h).to eq(child_entity2.to_h) expect(parsed[0][:asdf]).to eq("QWERT") end + + it "parses array entities only once" do + expect(Entities::OtherEntity).to receive(:from_xml).twice.and_call_original + + parsed = Parsers::XmlParser.new(Entities::TestNestedEntity).parse(nested_payload) + + expect(parsed[0][:multi]).to have(2).items + end end it "doesn't drop extra properties" do