Only parse each nested element name once
A child elements should only appear once or it is part of a nested array (photos, poll answers). So each element name only needs to be parsed once, because the way `parse_array_from_node` works is, that it already parses the full array with one call, so calling it multiple times again parses the full array a second time. closes #118
This commit is contained in:
parent
5fffefd3b6
commit
85e12cea93
2 changed files with 9 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue