Fixed serializing of elements to XML.
This commit is contained in:
parent
e0bbc81351
commit
8e8ea64206
|
@ -38,6 +38,13 @@ module Oga
|
|||
return value.to_s
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
#
|
||||
def to_xml
|
||||
return %Q(#{name}="#{value}")
|
||||
end
|
||||
|
||||
##
|
||||
# @return [String]
|
||||
#
|
||||
|
|
|
@ -94,8 +94,8 @@ module Oga
|
|||
body = children.map(&:to_xml).join('')
|
||||
attrs = ''
|
||||
|
||||
attributes.each do |key, value|
|
||||
attrs << "#{key}=#{value.inspect}"
|
||||
attributes.each do |attr|
|
||||
attrs << attr.to_xml
|
||||
end
|
||||
|
||||
attrs = " #{attrs}" unless attrs.empty?
|
||||
|
|
|
@ -25,6 +25,14 @@ describe Oga::XML::Attribute do
|
|||
end
|
||||
end
|
||||
|
||||
context '#to_xml' do
|
||||
example 'return a key/value pair for an XML document' do
|
||||
attr = described_class.new(:name => 'foo', :value => 'bar')
|
||||
|
||||
attr.to_xml.should == 'foo="bar"'
|
||||
end
|
||||
end
|
||||
|
||||
context '#inspect' do
|
||||
example 'return the inspect value' do
|
||||
obj = described_class.new(:name => 'a', :namespace => 'b', :value => 'c')
|
||||
|
|
|
@ -111,7 +111,9 @@ describe Oga::XML::Element do
|
|||
example 'include the attributes if present' do
|
||||
instance = described_class.new(
|
||||
:name => 'p',
|
||||
:attributes => {:key => 'value'}
|
||||
:attributes => [
|
||||
Oga::XML::Attribute.new(:name => 'key', :value => 'value')
|
||||
]
|
||||
)
|
||||
|
||||
instance.to_xml.should == '<p key="value"></p>'
|
||||
|
|
Loading…
Reference in New Issue