Skip to content

Commit

Permalink
Add failing test to get sparklemotion#391 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecuyer committed Nov 15, 2015
1 parent 7c14888 commit 786644e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/files/contact.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gContact="http://schemas.google.com/contact/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
<entry>
<id>http://www.google.com/m8/feeds/contacts/</id>
<updated>2014-06-20T18:11:02.792Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
<title type="text">John DOE</title>
<gd:organization rel="http://schemas.google.com/g/2005#other">
<gd:orgName>HERE</gd:orgName>
</gd:organization>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#mobile">XXX XXX-XXX</gd:phoneNumber>
</entry>
</feed>
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TestCase < MiniTest::Spec
XML_ATOM_FILE = File.join(ASSETS_DIR, 'atom.xml')
XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
XPATH_FILE = File.join(ASSETS_DIR, 'slow-xpath.xml')
XML_CONTACT_FILE = File.join(ASSETS_DIR, 'contact.xml')

def teardown
if ENV['NOKOGIRI_GC']
Expand Down
36 changes: 36 additions & 0 deletions test/xml/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,42 @@ def test_builder_can_handle_namespace_override
assert_nil doc.at_xpath("//*[local-name() = 'products']").namespace
end

def test_builder_insert_node
xml = Nokogiri::XML(File.read(XML_CONTACT_FILE), XML_CONTACT_FILE)

entry = xml.xpath("//np:entry", np: "http://www.w3.org/2005/Atom")[0]

namespaces = {
'xmlns' => 'http://www.w3.org/2005/Atom',
'xmlns:gContact' => 'http://schemas.google.com/contact/2008',
'xmlns:gd' => 'http://schemas.google.com/g/2005',
'xmlns:batch' => 'http://schemas.google.com/gdata/batch'
}

builder = Nokogiri::XML::Builder.new do |xml|
xml.feed(namespaces) do
xml.parent << entry
end
end

expected_output = %{<?xml version=\"1.0\"?>
<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:gContact=\"http://schemas.google.com/contact/2008\" xmlns:gd=\"http://schemas.google.com/g/2005\" xmlns:batch=\"http://schemas.google.com/gdata/batch\">
<entry>
<id>http://www.google.com/m8/feeds/contacts/</id>
<updated>2014-06-20T18:11:02.792Z</updated>
<category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/contact/2008#contact\"/>
<title type=\"text\">John DOE</title>
<gd:organization rel=\"http://schemas.google.com/g/2005#other\">
<gd:orgName>HERE</gd:orgName>
</gd:organization>
<gd:phoneNumber rel=\"http://schemas.google.com/g/2005#mobile\">XXX XXX-XXX</gd:phoneNumber>
</entry>
</feed>
}

assert_equal expected_output, builder.to_xml
end

private

def namespaces_defined_on(node)
Expand Down

0 comments on commit 786644e

Please sign in to comment.