Skip to content

Fix Element#prepend_to always raising NoMethodError - #193

Merged
satoryu merged 1 commit into
masterfrom
fix-189-prepend-to
Oct 17, 2026
Merged

satoryu merged 1 commit into
masterfrom
fix-189-prepend-to

Conversation

@satoryu

@satoryu satoryu commented Oct 17, 2026

Copy link
Copy Markdown
Member

Bug

Element#prepend_to called element.node.properties, but Nokogiri nodes have no properties method, so every call raised NoMethodError.

Fix

Use the target's own properties (the Container method, e.g. w:pPr for a paragraph) when the target has one, and insert after it. Otherwise (no properties node, or a non-container element), insert the node as the first child with prepend_child.

Tests

New unit specs for #prepend_to in spec/docx/elements/element_spec.rb:

  • paragraph with w:pPr → the run is inserted after it
  • paragraph without properties → the run becomes the first child
  • non-container element → the run becomes the first child

Closes #189

🤖 Generated with Claude Code

prepend_to called element.node.properties, which does not exist on a
Nokogiri node, so it always raised NoMethodError. Use the container's
properties (w:pPr etc.) when present and insert after them; otherwise
insert the node as the first child.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@satoryu
satoryu merged commit 5f56c66 into master Oct 17, 2026
6 checks passed
@satoryu
satoryu deleted the fix-189-prepend-to branch October 17, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Element#prepend_to always raises NoMethodError

1 participant