Browse files

atom serialization working

  • Loading branch information...
1 parent 40752d5 commit 686ed867c6e192022932939cb318ee7fb6714313 @guilhermesilveira guilhermesilveira committed Dec 20, 2009
Showing with 68 additions and 51 deletions.
  1. +9 −7 lib/restfulie/server/atom_media_type.rb
  2. +59 −44 spec/server/atom_media_type_spec.rb
View
16 lib/restfulie/server/atom_media_type.rb
@@ -39,16 +39,18 @@ def title(title)
self
end
- def to_atom
+ def to_atom(controller)
last_modified = updated_at
xml = items_to_atom_xml
'<?xml version="1.0"?>
- <feed xmlns="http://www.w3.org/2005/Atom">
- <id>urn:uuid:d0b4f914-30e9-418c-8628-7d9b7815060f</id>' +
- "\n <title type=\"text\">#{@title}</title>
- <updated>" + last_modified.strftime("%Y-%m-%dT%H:%M:%S-08:00") + '</updated>
- <generator uri="http://caelumtravel.com">Hotels Service</generator>' +
- self_link(nil) + xml + '</feed>'
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <id>urn:uuid:d0b4f914-30e9-418c-8628-7d9b7815060f</id>' +
+ "\n <title type=\"text\">#{@title}</title>
+ <updated>" + last_modified.strftime("%Y-%m-%dT%H:%M:%S-08:00") + """</updated>
+ <generator uri=\"http://caelumtravel.com\">Hotels Service</generator>
+ #{self_link(controller)}
+ #{xml}
+ </feed>"""
end
def self_link(controller)
View
103 spec/server/atom_media_type_spec.rb
@@ -14,50 +14,6 @@ class City
it "should support atom feed media type by default" do
Array.media_type_representations.include?('application/atom+xml').should be_true
end
-
- it "array serialization to atom will serialize every element" do
- first_entry = '<city>1</city>'
- second_entry = '<city>2</city>'
- expected = '<?xml version="1.0"?>
- <feed xmlns="http://www.w3.org/2005/Atom">
- <id>urn:uuid:d0b4f914-30e9-418c-8628-7d9b7815060f</id>
- <title type="text">Hotels list</title>
- <updated>' + @now.strftime('%Y-%m-%dT%H:%M:%S-08:00') + '</updated>
- <generator uri="http://caelumtravel.com">Hotels Service</generator>
- <link rel="self" href="http://caelumtravel.com/hotels"/>
- <entry>
- <id>urn:uuid:aa990d44-fce0-4823-a971-d23facc8d7c6</id>
- <title type="text">hotel</title>
- <updated>2009-07-01T11:58:00Z</updated>
- <author>
- <name>caelum travel</name>
- </author>
- <link rel="self" href="http://caelumtravel.com/hotels/1"/>
- <content type="application/vnd.hotel+xml">
- ' + first_entry + '
- </content>
- </entry>
- <entry>
- <id>urn:uuid:6fa8eca3-48ee-44a9-a899-37d047a3c5f2</id>
- <title type="text">order</title>
- <updated>2009-07-01T11:25:00Z</updated>
- <author>
- <name>caelum travel</name>
- </author>
- <link rel="self" href="http://caelumtravel.com/hotels/2"/>
- <content type="application/vnd.hotel+xml">
- ' + second_entry + '
- </content>
- </entry>
- </feed>'
- first = City.new
- first.should_receive(:updated_at).and_return(@now)
- first.should_receive(:to_xml).and_return(first_entry)
- second = City.new
- second.should_receive(:updated_at).and_return(@now)
- second.should_receive(:to_xml).and_return(second_entry)
- AtomFeed.new([first, second]).title('Hotels list').to_atom.should eql(expected)
- end
context AtomFeed do
@@ -67,6 +23,65 @@ class City
controller.should_receive(:url_for).with({}).and_return(uri)
AtomFeed.new(nil).self_link(controller).should eql("<link rel=\"self\" href=\"#{uri}\"/>")
end
+
+ it "array serialization to atom will serialize every element" do
+ expected = '<?xml version="1.0"?>
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <id>urn:uuid:d0b4f914-30e9-418c-8628-7d9b7815060f</id>
+ <title type="text">Hotels list</title>
+ <updated>' + @now.strftime('%Y-%m-%dT%H:%M:%S-08:00') + '</updated>
+ <generator uri="http://caelumtravel.com">Hotels Service</generator>
+ <link rel="self" href="http://caelumtravel.com/hotels"/>
+ <items/>
+ </feed>'
+ first = City.new
+ first.should_receive(:updated_at).and_return(@now)
+ second = City.new
+ second.should_receive(:updated_at).and_return(@now)
+
+ controller = Object.new
+ feed = AtomFeed.new([first, second])
+ feed.should_receive(:items_to_atom_xml).and_return("<items/>")
+ feed.should_receive(:self_link).with(controller).and_return("<link rel=\"self\" href=\"http://caelumtravel.com/hotels\"/>")
+ feed.title('Hotels list').to_atom(controller).should eql(expected)
+ end
+
+ # first_entry = '<city>1</city>'
+ # second_entry = '<city>2</city>'
+ # first.should_receive(:to_xml).and_return(first_entry)
+ # second.should_receive(:to_xml).and_return(second_entry)
+ # expected = '<?xml version="1.0"?>
+ # <feed xmlns="http://www.w3.org/2005/Atom">
+ # <id>urn:uuid:d0b4f914-30e9-418c-8628-7d9b7815060f</id>
+ # <title type="text">Hotels list</title>
+ # <updated>' + @now.strftime('%Y-%m-%dT%H:%M:%S-08:00') + '</updated>
+ # <generator uri="http://caelumtravel.com">Hotels Service</generator>
+ # <link rel="self" href="http://caelumtravel.com/hotels"/>
+ # <entry>
+ # <id>urn:uuid:aa990d44-fce0-4823-a971-d23facc8d7c6</id>
+ # <title type="text">hotel</title>
+ # <updated>2009-07-01T11:58:00Z</updated>
+ # <author>
+ # <name>caelum travel</name>
+ # </author>
+ # <link rel="self" href="http://caelumtravel.com/hotels/1"/>
+ # <content type="application/vnd.hotel+xml">
+ # ' + first_entry + '
+ # </content>
+ # </entry>
+ # <entry>
+ # <id>urn:uuid:6fa8eca3-48ee-44a9-a899-37d047a3c5f2</id>
+ # <title type="text">order</title>
+ # <updated>2009-07-01T11:25:00Z</updated>
+ # <author>
+ # <name>caelum travel</name>
+ # </author>
+ # <link rel="self" href="http://caelumtravel.com/hotels/2"/>
+ # <content type="application/vnd.hotel+xml">
+ # ' + second_entry + '
+ # </content>
+ # </entry>
+ # </feed>'
end

0 comments on commit 686ed86

Please sign in to comment.