Update owner when assign children
This commit is contained in:
parent
cf27b764e8
commit
36c11b2712
|
@ -46,6 +46,7 @@ module Oga
|
||||||
# @param [Oga::XML::NodeSet|Array] nodes
|
# @param [Oga::XML::NodeSet|Array] nodes
|
||||||
def children=(nodes)
|
def children=(nodes)
|
||||||
if nodes.is_a?(NodeSet)
|
if nodes.is_a?(NodeSet)
|
||||||
|
nodes.owner = self
|
||||||
@children = nodes
|
@children = nodes
|
||||||
else
|
else
|
||||||
@children = NodeSet.new(nodes, self)
|
@children = NodeSet.new(nodes, self)
|
||||||
|
|
|
@ -49,6 +49,7 @@ module Oga
|
||||||
# @param [Oga::XML::NodeSet|Array] nodes
|
# @param [Oga::XML::NodeSet|Array] nodes
|
||||||
def children=(nodes)
|
def children=(nodes)
|
||||||
if nodes.is_a?(NodeSet)
|
if nodes.is_a?(NodeSet)
|
||||||
|
nodes.owner = self
|
||||||
@children = nodes
|
@children = nodes
|
||||||
else
|
else
|
||||||
@children = NodeSet.new(nodes, self)
|
@children = NodeSet.new(nodes, self)
|
||||||
|
|
|
@ -22,6 +22,7 @@ describe Oga::XML::Document do
|
||||||
document.children = [child]
|
document.children = [child]
|
||||||
|
|
||||||
expect(document.children[0]).to eq(child)
|
expect(document.children[0]).to eq(child)
|
||||||
|
expect(document.children[0].parent).to eq(document)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the child nodes using a NodeSet' do
|
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])
|
document.children = Oga::XML::NodeSet.new([child])
|
||||||
|
|
||||||
expect(document.children[0]).to eq(child)
|
expect(document.children[0]).to eq(child)
|
||||||
|
expect(document.children[0].parent).to eq(document)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue