Include namespaces when converting attrs to XML.
This commit is contained in:
parent
32a7abd8c2
commit
319d622fa5
|
@ -81,7 +81,13 @@ module Oga
|
|||
# @return [String]
|
||||
#
|
||||
def to_xml
|
||||
return %Q(#{name}="#{value}")
|
||||
if namespace_name
|
||||
full_name = "#{namespace.name}:#{name}"
|
||||
else
|
||||
full_name = name
|
||||
end
|
||||
|
||||
return %Q(#{full_name}="#{value}")
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -48,11 +48,26 @@ describe Oga::XML::Attribute do
|
|||
end
|
||||
|
||||
context '#to_xml' do
|
||||
example 'return a key/value pair for an XML document' do
|
||||
example 'convert an attribute to XML' do
|
||||
attr = described_class.new(:name => 'foo', :value => 'bar')
|
||||
|
||||
attr.to_xml.should == 'foo="bar"'
|
||||
end
|
||||
|
||||
example 'include the namespace when converting an attribute to XML' do
|
||||
element = Oga::XML::Element.new
|
||||
|
||||
element.register_namespace('foo', 'http://foo')
|
||||
|
||||
attr = described_class.new(
|
||||
:name => 'class',
|
||||
:namespace_name => 'foo',
|
||||
:value => '10',
|
||||
:element => element
|
||||
)
|
||||
|
||||
attr.to_xml.should == 'foo:class="10"'
|
||||
end
|
||||
end
|
||||
|
||||
context '#inspect' do
|
||||
|
|
Loading…
Reference in New Issue