Remove all nodes when calling Element#inner_text=

This fixes #64.
This commit is contained in:
Yorick Peterse 2014-12-14 23:32:43 +01:00
parent 739f885078
commit 746c8052dd
3 changed files with 16 additions and 7 deletions

View File

@ -3,6 +3,16 @@
This document contains details of the various releases and their release dates.
Dates are in the format `yyyy-mm-dd`.
## 0.3.0 - Unreleased
### Element Inner Text
When setting the inner text of an element using `Oga::XML::Element#inner_text=`
_all_ child nodes of the element are now removed first, instead of only text
nodes being removed.
See <https://github.com/YorickPeterse/oga/issues/64> for more information.
## 0.2.0 - 2014-11-17
### CSS Selector Support

View File

@ -212,11 +212,8 @@ module Oga
# @param [String] text
#
def inner_text=(text)
children.each do |child|
child.remove if child.is_a?(Text)
end
children << XML::Text.new(:text => text)
text_node = XML::Text.new(:text => text)
@children = NodeSet.new([text_node])
end
##

View File

@ -260,11 +260,13 @@ describe Oga::XML::Element do
@element.inner_text.should == 'foo'
end
example 'remove existing text nodes before inserting new nodes' do
example 'remove all existing nodes before inserting a new text node' do
@element.children << Oga::XML::Text.new(:text => 'foo')
@element.children << Oga::XML::Element.new(:name => 'x')
@element.inner_text = 'bar'
@element.inner_text.should == 'bar'
@element.children.length.should == 1
end
end