Permalink
Browse files

Fix to_xml in order to receive a block

  • Loading branch information...
1 parent efbea7b commit 60da2545dee176470febdaf8cae55c12afd0fd87 @rnaveiras rnaveiras committed Mar 21, 2012
Showing with 9 additions and 3 deletions.
  1. +3 −3 lib/almodovar/to_xml.rb
  2. +6 −0 spec/unit/to_xml_spec.rb
@@ -1,9 +1,9 @@
module Almodovar
module ArrayToXml
- def to_xml_with_links(options = {})
- return to_xml_without_links(options) unless options[:convert_links]
+ def to_xml_with_links(options = {}, &block)
+ return to_xml_without_links(options, &block) unless options[:convert_links]
options[:builder].tag!(:link, :rel => options[:root]) do |xml|
- to_xml_without_links options.merge(:builder => xml)
+ to_xml_without_links options.merge(:builder => xml), &block
end
end
end
@@ -51,6 +51,12 @@
[].to_xml.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<nil-classes type=\"array\"/>\n"
end
+ it "should be able to receive a block" do
+ [{}].to_xml do |xml|
+ xml.wadus "Almodovar"
+ end.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<records type=\"array\">\n <wadus>Almodovar</wadus>\n <record>\n </record>\n</records>\n"
+ end
+
end
end

0 comments on commit 60da254

Please sign in to comment.