Skip to content

Commit

Permalink
Use namespace_name in Attribute#to_xml
Browse files Browse the repository at this point in the history
Instead of using `namespace.name` lets just use `namespace_name`. This fixes the
problem of serializing attributes where the namespace prefix is "xmlns" as the
namespace for this isn't registered by default.

This fixes #47.
  • Loading branch information
Yorick Peterse committed Sep 23, 2014
1 parent 00579ea commit 75f4e81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/oga/xml/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def text
#
def to_xml
if namespace_name
full_name = "#{namespace.name}:#{name}"
full_name = "#{namespace_name}:#{name}"
else
full_name = name
end
Expand Down
10 changes: 10 additions & 0 deletions spec/oga/xml/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@

attr.to_xml.should == 'foo:class="10"'
end

example 'include the "xmlns" namespace when present but not registered' do
attr = described_class.new(
:name => 'class',
:namespace_name => 'xmlns',
:element => Oga::XML::Element.new
)

attr.to_xml.should == 'xmlns:class=""'
end
end

context '#inspect' do
Expand Down

0 comments on commit 75f4e81

Please sign in to comment.