1 require 'abstract_unit'
3 Scroll
= Struct
.new(:id, :to_param, :title, :body, :updated_at, :created_at)
5 class ScrollsController
< ActionController
::Base
7 FEEDS
["defaults"] = <<-EOT
8 atom_feed(:schema_date => '2008') do |feed|
9 feed.title("My great blog!")
10 feed.updated((@scrolls.first.created_at))
12 for scroll in @scrolls
13 feed.entry(scroll) do |entry|
14 entry.title(scroll.title)
15 entry.content(scroll.body, :type => 'html')
17 entry.author do |author|
24 FEEDS
["entry_options"] = <<-EOT
26 feed.title("My great blog!")
27 feed.updated((@scrolls.first.created_at))
29 for scroll in @scrolls
30 feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
31 entry.title(scroll.title)
32 entry.content(scroll.body, :type => 'html')
34 entry.author do |author|
41 FEEDS
["xml_block"] = <<-EOT
43 feed.title("My great blog!")
44 feed.updated((@scrolls.first.created_at))
46 feed.author do |author|
50 for scroll in @scrolls
51 feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
52 entry.title(scroll.title)
53 entry.content(scroll.body, :type => 'html')
58 FEEDS
["feed_with_atomPub_namespace"] = <<-EOT
59 atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
60 'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
61 feed.title("My great blog!")
62 feed.updated((@scrolls.first.created_at))
64 for scroll in @scrolls
65 feed.entry(scroll) do |entry|
66 entry.title(scroll.title)
67 entry.content(scroll.body, :type => 'html')
68 entry.tag!('app:edited', Time.now)
70 entry.author do |author|
77 FEEDS
["feed_with_overridden_ids"] = <<-EOT
78 atom_feed({:id => 'tag:test.rubyonrails.org,2008:test/'}) do |feed|
79 feed.title("My great blog!")
80 feed.updated((@scrolls.first.created_at))
82 for scroll in @scrolls
83 feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry|
84 entry.title(scroll.title)
85 entry.content(scroll.body, :type => 'html')
86 entry.tag!('app:edited', Time.now)
88 entry.author do |author|
95 FEEDS
["feed_with_xml_processing_instructions"] = <<-EOT
96 atom_feed(:schema_date => '2008',
97 :instruct => {'xml-stylesheet' => { :href=> 't.css', :type => 'text/css' }}) do |feed|
98 feed.title("My great blog!")
99 feed.updated((@scrolls.first.created_at))
101 for scroll in @scrolls
102 feed.entry(scroll) do |entry|
103 entry.title(scroll.title)
104 entry.content(scroll.body, :type => 'html')
106 entry.author do |author|
113 FEEDS
["feed_with_xml_processing_instructions_duplicate_targets"] = <<-EOT
114 atom_feed(:schema_date => '2008',
115 :instruct => {'target1' => [{ :a => '1', :b => '2' }, { :c => '3', :d => '4' }]}) do |feed|
116 feed.title("My great blog!")
117 feed.updated((@scrolls.first.created_at))
119 for scroll in @scrolls
120 feed.entry(scroll) do |entry|
121 entry.title(scroll.title)
122 entry.content(scroll.body, :type => 'html')
124 entry.author do |author|
131 FEEDS
["feed_with_xhtml_content"] = <<-'EOT'
133 feed
.title("My great blog!")
134 feed.updated((@scrolls.first.created_at))
136 for scroll in @scrolls
137 feed.entry(scroll) do |entry|
138 entry.title(scroll.title)
139 entry.summary(:type => 'xhtml') do |xhtml|
140 xhtml.p "before
#{scroll.id}"
141 xhtml.p {xhtml << scroll.body}
142 xhtml.p "after
#{scroll.id}"
144 entry.tag!('app:edited', Time
.now
)
146 entry
.author
do |author
|
155 Scroll
.new(1, "1", "Hello One", "Something <i>COOL!</i
>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)),
156 Scroll.new(2, "2", "Hello Two
", "Something Boring
", Time.utc(2007, 12, 12, 15)),
159 render :inline => FEEDS[params[:id]], :type => :builder
169 class AtomFeedTest < Test::Unit::TestCase
171 @request = ActionController::TestRequest.new
172 @response = ActionController::TestResponse.new
173 @controller = ScrollsController.new
175 @request.host = "www
.nextangle
.com
"
178 def test_feed_should_use_default_language_if_none_is_given
179 with_restful_routing(:scrolls) do
180 get :index, :id => "defaults
"
181 assert_match %r{xml:lang="en-US
"}, @response.body
185 def test_feed_should_include_two_entries
186 with_restful_routing(:scrolls) do
187 get :index, :id => "defaults
"
188 assert_select "entry
", 2
192 def test_entry_should_only_use_published_if_created_at_is_present
193 with_restful_routing(:scrolls) do
194 get :index, :id => "defaults
"
195 assert_select "published
", 1
199 def test_entry_with_prefilled_options_should_use_those_instead_of_querying_the_record
200 with_restful_routing(:scrolls) do
201 get :index, :id => "entry_options
"
203 assert_select "updated
", Time.utc(2007, 1, 1).xmlschema
204 assert_select "updated
", Time.utc(2007, 1, 2).xmlschema
208 def test_self_url_should_default_to_current_request_url
209 with_restful_routing(:scrolls) do
210 get :index, :id => "defaults
"
211 assert_select "link
[rel
=self][href
=http
://www
.nextangle
.com
/scrolls
?id
=defaults
]"
215 def test_feed_id_should_be_a_valid_tag
216 with_restful_routing(:scrolls) do
217 get :index, :id => "defaults
"
218 assert_select "id
", :text => "tag
:www.nextangle
.com
,2008:/scrolls
?id
=defaults
"
222 def test_entry_id_should_be_a_valid_tag
223 with_restful_routing(:scrolls) do
224 get :index, :id => "defaults
"
225 assert_select "entry id
", :text => "tag
:www.nextangle
.com
,2008:Scroll/1"
226 assert_select "entry id
", :text => "tag
:www.nextangle
.com
,2008:Scroll/2"
230 def test_feed_should_allow_nested_xml_blocks
231 with_restful_routing(:scrolls) do
232 get :index, :id => "xml_block
"
233 assert_select "author name
", :text => "DHH
"
237 def test_feed_should_include_atomPub_namespace
238 with_restful_routing(:scrolls) do
239 get :index, :id => "feed_with_atomPub_namespace
"
240 assert_match %r{xml:lang="en-US
"}, @response.body
241 assert_match %r{xmlns="http
://www
.w3
.org
/2005/Atom
"}, @response.body
242 assert_match %r{xmlns:app="http
://www
.w3
.org
/2007/app
"}, @response.body
246 def test_feed_should_allow_overriding_ids
247 with_restful_routing(:scrolls) do
248 get :index, :id => "feed_with_overridden_ids
"
249 assert_select "id
", :text => "tag
:test.rubyonrails
.org
,2008:test/"
250 assert_select "entry id
", :text => "tag
:test.rubyonrails
.org
,2008:1"
251 assert_select "entry id
", :text => "tag
:test.rubyonrails
.org
,2008:2"
255 def test_feed_xml_processing_instructions
256 with_restful_routing(:scrolls) do
257 get :index, :id => 'feed_with_xml_processing_instructions'
258 assert_match %r{<\?xml-stylesheet [^\?]*type="text
/css
"}, @response.body
259 assert_match %r{<\?xml-stylesheet [^\?]*href="t
.css
"}, @response.body
263 def test_feed_xml_processing_instructions_duplicate_targets
264 with_restful_routing(:scrolls) do
265 get :index, :id => 'feed_with_xml_processing_instructions_duplicate_targets'
266 assert_match %r{<\?target1 (a="1" b="2"|b="2" a="1")\?>}, @response.body
267 assert_match %r{<\?target1 (c="3" d="4"|d="4" c="3")\?>}, @response.body
272 with_restful_routing(:scrolls) do
273 get :index, :id => "feed_with_xhtml_content
"
274 assert_match %r{xmlns="http
://www
.w3
.org
/1999/xhtml
"}, @response.body
275 assert_select "summary div p
", :text => "Something Boring
"
276 assert_select "summary div p
", :text => "after
2"
280 def with_restful_routing(resources)
281 with_routing do |set|
283 map.resources(resources)