Update owner when assign children

This commit is contained in:
lulalala 2022-07-13 21:24:00 +08:00
parent cf27b764e8
commit 36c11b2712
3 changed files with 4 additions and 0 deletions

View File

@ -46,6 +46,7 @@ module Oga
# @param [Oga::XML::NodeSet|Array] nodes
def children=(nodes)
if nodes.is_a?(NodeSet)
nodes.owner = self
@children = nodes
else
@children = NodeSet.new(nodes, self)

View File

@ -49,6 +49,7 @@ module Oga
# @param [Oga::XML::NodeSet|Array] nodes
def children=(nodes)
if nodes.is_a?(NodeSet)
nodes.owner = self
@children = nodes
else
@children = NodeSet.new(nodes, self)

View File

@ -22,6 +22,7 @@ describe Oga::XML::Document do
document.children = [child]
expect(document.children[0]).to eq(child)
expect(document.children[0].parent).to eq(document)
end
it 'sets the child nodes using a NodeSet' do
@ -31,6 +32,7 @@ describe Oga::XML::Document do
document.children = Oga::XML::NodeSet.new([child])
expect(document.children[0]).to eq(child)
expect(document.children[0].parent).to eq(document)
end
end