Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 10194 Bytes
1 | require 'abstract_unit' |
2 | |
3 | Scroll = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at) |
4 | |
5 | class ScrollsController < ActionController::Base |
6 | FEEDS = {} |
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)) |
11 | |
12 | for scroll in @scrolls |
13 | feed.entry(scroll) do |entry| |
14 | entry.title(scroll.title) |
15 | entry.content(scroll.body, :type => 'html') |
16 | |
17 | entry.author do |author| |
18 | author.name("DHH") |
19 | end |
20 | end |
21 | end |
22 | end |
23 | EOT |
24 | FEEDS["entry_options"] = <<-EOT |
25 | atom_feed do |feed| |
26 | feed.title("My great blog!") |
27 | feed.updated((@scrolls.first.created_at)) |
28 | |
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') |
33 | |
34 | entry.author do |author| |
35 | author.name("DHH") |
36 | end |
37 | end |
38 | end |
39 | end |
40 | EOT |
41 | FEEDS["xml_block"] = <<-EOT |
42 | atom_feed do |feed| |
43 | feed.title("My great blog!") |
44 | feed.updated((@scrolls.first.created_at)) |
45 | |
46 | feed.author do |author| |
47 | author.name("DHH") |
48 | end |
49 | |
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') |
54 | end |
55 | end |
56 | end |
57 | EOT |
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)) |
63 | |
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) |
69 | |
70 | entry.author do |author| |
71 | author.name("DHH") |
72 | end |
73 | end |
74 | end |
75 | end |
76 | EOT |
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)) |
81 | |
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) |
87 | |
88 | entry.author do |author| |
89 | author.name("DHH") |
90 | end |
91 | end |
92 | end |
93 | end |
94 | EOT |
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)) |
100 | |
101 | for scroll in @scrolls |
102 | feed.entry(scroll) do |entry| |
103 | entry.title(scroll.title) |
104 | entry.content(scroll.body, :type => 'html') |
105 | |
106 | entry.author do |author| |
107 | author.name("DHH") |
108 | end |
109 | end |
110 | end |
111 | end |
112 | EOT |
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)) |
118 | |
119 | for scroll in @scrolls |
120 | feed.entry(scroll) do |entry| |
121 | entry.title(scroll.title) |
122 | entry.content(scroll.body, :type => 'html') |
123 | |
124 | entry.author do |author| |
125 | author.name("DHH") |
126 | end |
127 | end |
128 | end |
129 | end |
130 | EOT |
131 | FEEDS["feed_with_xhtml_content"] = <<-'EOT' |
132 | atom_feed do |feed| |
133 | feed.title("My great blog!") |
134 | feed.updated((@scrolls.first.created_at)) |
135 | |
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}" |
143 | end |
144 | entry.tag!('app:edited', Time.now) |
145 | |
146 | entry.author do |author| |
147 | author.name("DHH") |
148 | end |
149 | end |
150 | end |
151 | end |
152 | EOT |
153 | FEEDS["provide_builder"] = <<-'EOT' |
154 | # we pass in the new_xml to the helper so it doesn't |
155 | # call anything on the original builder |
156 | new_xml = Builder::XmlMarkup.new(:target=>'') |
157 | atom_feed(:xml => new_xml) do |feed| |
158 | feed.title("My great blog!") |
159 | feed.updated((@scrolls.first.created_at)) |
160 | |
161 | for scroll in @scrolls |
162 | feed.entry(scroll) do |entry| |
163 | entry.title(scroll.title) |
164 | entry.content(scroll.body, :type => 'html') |
165 | |
166 | entry.author do |author| |
167 | author.name("DHH") |
168 | end |
169 | end |
170 | end |
171 | end |
172 | EOT |
173 | def index |
174 | @scrolls = [ |
175 | Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)), |
176 | Scroll.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)), |
177 | ] |
178 | |
179 | render :inline => FEEDS[params[:id]], :type => :builder |
180 | end |
181 | |
182 | protected |
183 | |
184 | def rescue_action(e) |
185 | raise(e) |
186 | end |
187 | end |
188 | |
189 | class AtomFeedTest < ActionController::TestCase |
190 | tests ScrollsController |
191 | |
192 | def setup |
193 | @request.host = "www.nextangle.com" |
194 | end |
195 | |
196 | def test_feed_should_use_default_language_if_none_is_given |
197 | with_restful_routing(:scrolls) do |
198 | get :index, :id => "defaults" |
199 | assert_match %r{xml:lang="en-US"}, @response.body |
200 | end |
201 | end |
202 | |
203 | def test_feed_should_include_two_entries |
204 | with_restful_routing(:scrolls) do |
205 | get :index, :id => "defaults" |
206 | assert_select "entry", 2 |
207 | end |
208 | end |
209 | |
210 | def test_entry_should_only_use_published_if_created_at_is_present |
211 | with_restful_routing(:scrolls) do |
212 | get :index, :id => "defaults" |
213 | assert_select "published", 1 |
214 | end |
215 | end |
216 | |
217 | def test_providing_builder_to_atom_feed |
218 | with_restful_routing(:scrolls) do |
219 | get :index, :id=>"provide_builder" |
220 | # because we pass in the non-default builder, the content generated by the |
221 | # helper should go 'nowhere'. Leaving the response body blank. |
222 | assert @response.body.blank? |
223 | end |
224 | end |
225 | |
226 | def test_entry_with_prefilled_options_should_use_those_instead_of_querying_the_record |
227 | with_restful_routing(:scrolls) do |
228 | get :index, :id => "entry_options" |
229 | |
230 | assert_select "updated", Time.utc(2007, 1, 1).xmlschema |
231 | assert_select "updated", Time.utc(2007, 1, 2).xmlschema |
232 | end |
233 | end |
234 | |
235 | def test_self_url_should_default_to_current_request_url |
236 | with_restful_routing(:scrolls) do |
237 | get :index, :id => "defaults" |
238 | assert_select "link[rel=self][href=http://www.nextangle.com/scrolls?id=defaults]" |
239 | end |
240 | end |
241 | |
242 | def test_feed_id_should_be_a_valid_tag |
243 | with_restful_routing(:scrolls) do |
244 | get :index, :id => "defaults" |
245 | assert_select "id", :text => "tag:www.nextangle.com,2008:/scrolls?id=defaults" |
246 | end |
247 | end |
248 | |
249 | def test_entry_id_should_be_a_valid_tag |
250 | with_restful_routing(:scrolls) do |
251 | get :index, :id => "defaults" |
252 | assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/1" |
253 | assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/2" |
254 | end |
255 | end |
256 | |
257 | def test_feed_should_allow_nested_xml_blocks |
258 | with_restful_routing(:scrolls) do |
259 | get :index, :id => "xml_block" |
260 | assert_select "author name", :text => "DHH" |
261 | end |
262 | end |
263 | |
264 | def test_feed_should_include_atomPub_namespace |
265 | with_restful_routing(:scrolls) do |
266 | get :index, :id => "feed_with_atomPub_namespace" |
267 | assert_match %r{xml:lang="en-US"}, @response.body |
268 | assert_match %r{xmlns="http://www.w3.org/2005/Atom"}, @response.body |
269 | assert_match %r{xmlns:app="http://www.w3.org/2007/app"}, @response.body |
270 | end |
271 | end |
272 | |
273 | def test_feed_should_allow_overriding_ids |
274 | with_restful_routing(:scrolls) do |
275 | get :index, :id => "feed_with_overridden_ids" |
276 | assert_select "id", :text => "tag:test.rubyonrails.org,2008:test/" |
277 | assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:1" |
278 | assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:2" |
279 | end |
280 | end |
281 | |
282 | def test_feed_xml_processing_instructions |
283 | with_restful_routing(:scrolls) do |
284 | get :index, :id => 'feed_with_xml_processing_instructions' |
285 | assert_match %r{<\?xml-stylesheet [^\?]*type="text/css"}, @response.body |
286 | assert_match %r{<\?xml-stylesheet [^\?]*href="t.css"}, @response.body |
287 | end |
288 | end |
289 | |
290 | def test_feed_xml_processing_instructions_duplicate_targets |
291 | with_restful_routing(:scrolls) do |
292 | get :index, :id => 'feed_with_xml_processing_instructions_duplicate_targets' |
293 | assert_match %r{<\?target1 (a="1" b="2"|b="2" a="1")\?>}, @response.body |
294 | assert_match %r{<\?target1 (c="3" d="4"|d="4" c="3")\?>}, @response.body |
295 | end |
296 | end |
297 | |
298 | def test_feed_xhtml |
299 | with_restful_routing(:scrolls) do |
300 | get :index, :id => "feed_with_xhtml_content" |
301 | assert_match %r{xmlns="http://www.w3.org/1999/xhtml"}, @response.body |
302 | assert_select "summary div p", :text => "Something Boring" |
303 | assert_select "summary div p", :text => "after 2" |
304 | end |
305 | end |
306 | private |
307 | def with_restful_routing(resources) |
308 | with_routing do |set| |
309 | set.draw do |map| |
310 | map.resources(resources) |
311 | end |
312 | yield |
313 | end |
314 | end |
315 | end |