Skip to content

Commit

Permalink
Replace queries using at_css with at_xpath to prevent incompatibility…
Browse files Browse the repository at this point in the history
… with new version of Nokogiri. See #120
  • Loading branch information
sandrods committed Feb 23, 2022
1 parent 16f5b38 commit 1fb39e1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/odf-report/section.rb
Expand Up @@ -26,11 +26,11 @@ def replace!(doc)
private

def find_section_node(doc)
@section_node = doc.at_css("text|section[@text|name='#{@name}']")
@section_node = doc.at_xpath("//text:section[@text:name='#{@name}']")
end

def deep_clone(node)
Nokogiri::XML(wrap_with_ns(node)).at("text|section")
Nokogiri::XML(wrap_with_ns(node)).at_xpath("//text:section")
.tap { |n| n.attribute('name').content = SecureRandom.uuid }

end
Expand Down
5 changes: 2 additions & 3 deletions lib/odf-report/table.rb
Expand Up @@ -60,7 +60,6 @@ def get_next_row
end

return deep_clone(ret)
# return ret.dup
end

def get_start_node
Expand All @@ -72,11 +71,11 @@ def template_length
end

def find_table_node(doc)
doc.at_css("table|table[@table|name='#{@name}']")
doc.at_xpath("//table:table[@table:name='#{@name}']")
end

def deep_clone(node)
Nokogiri::XML(wrap_with_ns(node)).at("table|table-row")
Nokogiri::XML(wrap_with_ns(node)).at_xpath("//table:table-row")
end

end
Expand Down
4 changes: 2 additions & 2 deletions spec/images_spec.rb
Expand Up @@ -116,8 +116,8 @@
end

it "removes nil images in report" do
expect(@data.xml.at_css("draw|frame[@draw|name='IMAGE_01']")).to be
expect(@data.xml.at_css("draw|frame[@draw|name='IMAGE_02']")).to be_nil
expect(@data.xml.at_xpath(".//draw:frame[@draw:name='IMAGE_01']")).to be
expect(@data.xml.at_xpath(".//draw:frame[@draw:name='IMAGE_02']")).to be_nil
end

it "removes nil images in tables" do
Expand Down
4 changes: 2 additions & 2 deletions spec/sections_spec.rb
Expand Up @@ -38,12 +38,12 @@
end

it "should remove section with empty collection" do
section = @data.xml.at_css("text|section[@text|name='SECTION_02']")
section = @data.xml.at_xpath("//text:section[@text:name='SECTION_02']")
expect(section).to be_nil
end

it "should remove section with nil collection" do
section = @data.xml.at_css("text|section[@text|name='SECTION_03']")
section = @data.xml.at_xpath("//text:section[@text:name='SECTION_03']")
expect(section).to be_nil
end

Expand Down

1 comment on commit 1fb39e1

@sandrods
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closes #120

Please sign in to comment.