Skip to content

Commit

Permalink
add first test from @bradleybeddoes #1444
Browse files Browse the repository at this point in the history
and adding tests for reparented nodes' namespaces

related to #1332
  • Loading branch information
flavorjones committed May 30, 2016
1 parent e6c3b04 commit 0233c48
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/xml/test_node_reparenting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,16 @@ class TestNodeReparenting < Nokogiri::TestCase
assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
assert reparented.namespace_definitions.empty?
assert_equal @ns, reparented.namespace
assert_equal(
{
"xmlns" =>"http://tenderlovemaking.com/",
"xmlns:foo" =>"http://flavorjon.es/",
},
reparented.namespaces)
end
end

describe "but with a different prefix" do
describe "as the default prefix" do
before do
@ns = @child.add_namespace(nil, 'http://flavorjon.es/')
@child.namespace = @ns
Expand All @@ -253,6 +259,33 @@ class TestNodeReparenting < Nokogiri::TestCase
assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
assert reparented.namespace_definitions.include?(@ns)
assert_equal @ns, reparented.namespace
assert_equal(
{
"xmlns" =>"http://flavorjon.es/",
"xmlns:foo" =>"http://flavorjon.es/",
},
reparented.namespaces)
end
end

describe "but with a different prefix" do
before do
@ns = @child.add_namespace('baz', 'http://flavorjon.es/')
@child.namespace = @ns
end

it "inserts a node that keeps its namespace" do
@node.add_child(@child)
assert reparented = @doc.at('//bar:second', "bar" => "http://flavorjon.es/")
assert reparented.namespace_definitions.include?(@ns)
assert_equal @ns, reparented.namespace
assert_equal(
{
"xmlns" =>"http://tenderlovemaking.com/",
"xmlns:foo" =>"http://flavorjon.es/",
"xmlns:baz" =>"http://flavorjon.es/",
},
reparented.namespaces)
end
end
end
Expand Down

0 comments on commit 0233c48

Please sign in to comment.