Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/docx/containers/text_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def text=(content)
elsif @text_nodes.empty?
new_t = Elements::Text.create_within(self)
new_t.content = content
@text_nodes << new_t
end
reset_text
end
Expand Down
21 changes: 21 additions & 0 deletions spec/docx/containers/text_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ def run(xml, document_properties = {})

expect(node.xpath('w:t').map(&:text)).to eq(['new'])
end

# Regression tests for #190
it 'reflects the new text when the run had no w:t' do
text_run = described_class.new(w_node('<w:r/>'))

text_run.text = 'new'

expect(text_run.text).to eq('new')
expect(text_run.to_html).to eq('new')
end

it 'keeps updating the same w:t on later assignments' do
node = w_node('<w:r/>')
text_run = described_class.new(node)

text_run.text = 'first'
text_run.text = 'second'

expect(text_run.text).to eq('second')
expect(node.xpath('w:t').map(&:text)).to eq(['second'])
end
end

describe '#substitute' do
Expand Down
Loading