]> git.openstreetmap.org Git - rails.git/blob - test/functional/notes_controller_test.rb
Improve functional tests for notes#show
[rails.git] / test / functional / notes_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class NotesControllerTest < ActionController::TestCase
4   fixtures :users, :notes, :note_comments
5
6   ##
7   # test all routes which lead to this controller
8   def test_routes
9     assert_routing(
10       { :path => "/api/0.6/notes", :method => :post },
11       { :controller => "notes", :action => "create", :format => "xml" }
12     )
13     assert_routing(
14       { :path => "/api/0.6/notes/1", :method => :get },
15       { :controller => "notes", :action => "show", :id => "1", :format => "xml" }
16     )
17     assert_recognizes(
18       { :controller => "notes", :action => "show", :id => "1", :format => "xml" },
19       { :path => "/api/0.6/notes/1.xml", :method => :get }
20     )
21     assert_routing(
22       { :path => "/api/0.6/notes/1.rss", :method => :get },
23       { :controller => "notes", :action => "show", :id => "1", :format => "rss" }
24     )
25     assert_routing(
26       { :path => "/api/0.6/notes/1.json", :method => :get },
27       { :controller => "notes", :action => "show", :id => "1", :format => "json" }
28     )
29     assert_routing(
30       { :path => "/api/0.6/notes/1.gpx", :method => :get },
31       { :controller => "notes", :action => "show", :id => "1", :format => "gpx" }
32     )
33     assert_routing(
34       { :path => "/api/0.6/notes/1/comment", :method => :post },
35       { :controller => "notes", :action => "comment", :id => "1", :format => "xml" }
36     )
37     assert_routing(
38       { :path => "/api/0.6/notes/1/close", :method => :post },
39       { :controller => "notes", :action => "close", :id => "1", :format => "xml" }
40     )
41     assert_routing(
42       { :path => "/api/0.6/notes/1", :method => :delete },
43       { :controller => "notes", :action => "destroy", :id => "1", :format => "xml" }
44     )
45
46     assert_routing(
47       { :path => "/api/0.6/notes", :method => :get },
48       { :controller => "notes", :action => "index", :format => "xml" }
49     )
50     assert_recognizes(
51       { :controller => "notes", :action => "index", :format => "xml" },
52       { :path => "/api/0.6/notes.xml", :method => :get }
53     )
54     assert_routing(
55       { :path => "/api/0.6/notes.rss", :method => :get },
56       { :controller => "notes", :action => "index", :format => "rss" }
57     )
58     assert_routing(
59       { :path => "/api/0.6/notes.json", :method => :get },
60       { :controller => "notes", :action => "index", :format => "json" }
61     )
62     assert_routing(
63       { :path => "/api/0.6/notes.gpx", :method => :get },
64       { :controller => "notes", :action => "index", :format => "gpx" }
65     )
66
67     assert_routing(
68       { :path => "/api/0.6/notes/search", :method => :get },
69       { :controller => "notes", :action => "search", :format => "xml" }
70     )
71     assert_recognizes(
72       { :controller => "notes", :action => "search", :format => "xml" },
73       { :path => "/api/0.6/notes/search.xml", :method => :get }
74     )
75     assert_routing(
76       { :path => "/api/0.6/notes/search.rss", :method => :get },
77       { :controller => "notes", :action => "search", :format => "rss" }
78     )
79     assert_routing(
80       { :path => "/api/0.6/notes/search.json", :method => :get },
81       { :controller => "notes", :action => "search", :format => "json" }
82     )
83     assert_routing(
84       { :path => "/api/0.6/notes/search.gpx", :method => :get },
85       { :controller => "notes", :action => "search", :format => "gpx" }
86     )
87
88     assert_routing(
89       { :path => "/api/0.6/notes/feed", :method => :get },
90       { :controller => "notes", :action => "feed", :format => "rss" }
91     )
92
93     assert_recognizes(
94       { :controller => "notes", :action => "create" },
95       { :path => "/api/0.6/notes/addPOIexec", :method => :post }
96     )
97     assert_recognizes(
98       { :controller => "notes", :action => "close" },
99       { :path => "/api/0.6/notes/closePOIexec", :method => :post }
100     )
101     assert_recognizes(
102       { :controller => "notes", :action => "comment" },
103       { :path => "/api/0.6/notes/editPOIexec", :method => :post }
104     )
105     assert_recognizes(
106       { :controller => "notes", :action => "index", :format => "gpx" },
107       { :path => "/api/0.6/notes/getGPX", :method => :get }
108     )
109     assert_recognizes(
110       { :controller => "notes", :action => "feed", :format => "rss" },
111       { :path => "/api/0.6/notes/getRSSfeed", :method => :get }
112     )
113
114     assert_routing(
115       { :path => "/user/username/notes", :method => :get },
116       { :controller => "notes", :action => "mine", :display_name => "username" }
117     )
118   end
119
120   def test_create_success
121     assert_difference('Note.count') do
122       assert_difference('NoteComment.count') do
123         post :create, {:lat => -1.0, :lon => -1.0, :text => "This is a comment", :format => "json"}
124       end
125     end
126     assert_response :success
127     js = ActiveSupport::JSON.decode(@response.body)
128     assert_not_nil js
129     assert_equal "Feature", js["type"]
130     assert_equal "Point", js["geometry"]["type"]
131     assert_equal [-1.0, -1.0], js["geometry"]["coordinates"]
132     assert_equal "open", js["properties"]["status"]
133     assert_equal 1, js["properties"]["comments"].count
134     assert_equal "opened", js["properties"]["comments"].last["action"]
135     assert_equal "This is a comment", js["properties"]["comments"].last["text"]
136     assert_nil js["properties"]["comments"].last["user"]
137     id = js["properties"]["id"]
138
139     get :show, {:id => id, :format => "json"}
140     assert_response :success
141     js = ActiveSupport::JSON.decode(@response.body)
142     assert_not_nil js
143     assert_equal "Feature", js["type"]
144     assert_equal "Point", js["geometry"]["type"]
145     assert_equal [-1.0, -1.0], js["geometry"]["coordinates"]
146     assert_equal id, js["properties"]["id"]
147     assert_equal "open", js["properties"]["status"]
148     assert_equal 1, js["properties"]["comments"].count
149     assert_equal "opened", js["properties"]["comments"].last["action"]
150     assert_equal "This is a comment", js["properties"]["comments"].last["text"]
151     assert_nil js["properties"]["comments"].last["user"]
152   end
153
154   def test_create_fail
155     assert_no_difference('Note.count') do
156       assert_no_difference('NoteComment.count') do
157         post :create, {:lon => -1.0, :text => "This is a comment"}
158       end
159     end
160     assert_response :bad_request
161
162     assert_no_difference('Note.count') do
163       assert_no_difference('NoteComment.count') do
164         post :create, {:lat => -1.0, :text => "This is a comment"}
165       end
166     end
167     assert_response :bad_request
168
169     assert_no_difference('Note.count') do
170       assert_no_difference('NoteComment.count') do
171         post :create, {:lat => -1.0, :lon => -1.0}
172       end
173     end
174     assert_response :bad_request
175
176     assert_no_difference('Note.count') do
177       assert_no_difference('NoteComment.count') do
178         post :create, {:lat => -1.0, :lon => -1.0, :text => ""}
179       end
180     end
181     assert_response :bad_request
182
183     assert_no_difference('Note.count') do
184       assert_no_difference('NoteComment.count') do
185         post :create, {:lat => -100.0, :lon => -1.0, :text => "This is a comment"}
186       end
187     end
188     assert_response :bad_request
189
190     assert_no_difference('Note.count') do
191       assert_no_difference('NoteComment.count') do
192         post :create, {:lat => -1.0, :lon => -200.0, :text => "This is a comment"}
193       end
194     end
195     assert_response :bad_request
196   end
197
198   def test_comment_success
199     assert_difference('NoteComment.count') do
200       post :comment, {:id => notes(:open_note_with_comment).id, :text => "This is an additional comment", :format => "json"}
201     end
202     assert_response :success
203     js = ActiveSupport::JSON.decode(@response.body)
204     assert_not_nil js
205     assert_equal "Feature", js["type"]
206     assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
207     assert_equal "open", js["properties"]["status"]
208     assert_equal 3, js["properties"]["comments"].count
209     assert_equal "commented", js["properties"]["comments"].last["action"]
210     assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
211     assert_nil js["properties"]["comments"].last["user"]
212
213     get :show, {:id => notes(:open_note_with_comment).id, :format => "json"}
214     assert_response :success
215     js = ActiveSupport::JSON.decode(@response.body)
216     assert_not_nil js
217     assert_equal "Feature", js["type"]
218     assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
219     assert_equal "open", js["properties"]["status"]
220     assert_equal 3, js["properties"]["comments"].count
221     assert_equal "commented", js["properties"]["comments"].last["action"]
222     assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
223     assert_nil js["properties"]["comments"].last["user"]
224   end
225
226   def test_comment_fail
227     assert_no_difference('NoteComment.count') do
228       post :comment, {:text => "This is an additional comment"}
229     end
230     assert_response :bad_request
231
232     assert_no_difference('NoteComment.count') do
233       post :comment, {:id => notes(:open_note_with_comment).id}
234     end
235     assert_response :bad_request
236
237     assert_no_difference('NoteComment.count') do
238       post :comment, {:id => notes(:open_note_with_comment).id, :text => ""}
239     end
240     assert_response :bad_request
241
242     assert_no_difference('NoteComment.count') do
243       post :comment, {:id => 12345, :text => "This is an additional comment"}
244     end
245     assert_response :not_found
246
247     assert_no_difference('NoteComment.count') do
248       post :comment, {:id => notes(:hidden_note_with_comment).id, :text => "This is an additional comment"}
249     end
250     assert_response :gone
251
252     assert_no_difference('NoteComment.count') do
253       post :comment, {:id => notes(:closed_note_with_comment).id, :text => "This is an additional comment"}
254     end
255     assert_response :conflict
256   end
257
258   def test_close_success
259     post :close, {:id => notes(:open_note_with_comment).id, :text => "This is a close comment", :format => "json"}
260     assert_response :unauthorized
261
262     basic_authorization(users(:public_user).email, "test")
263
264     post :close, {:id => notes(:open_note_with_comment).id, :text => "This is a close comment", :format => "json"}
265     assert_response :success
266     js = ActiveSupport::JSON.decode(@response.body)
267     assert_not_nil js
268     assert_equal "Feature", js["type"]
269     assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
270     assert_equal "closed", js["properties"]["status"]
271     assert_equal 3, js["properties"]["comments"].count
272     assert_equal "closed", js["properties"]["comments"].last["action"]
273     assert_equal "This is a close comment", js["properties"]["comments"].last["text"]
274     assert_equal "test2", js["properties"]["comments"].last["user"]
275
276     get :show, {:id => notes(:open_note_with_comment).id, :format => "json"}
277     assert_response :success
278     js = ActiveSupport::JSON.decode(@response.body)
279     assert_not_nil js
280     assert_equal "Feature", js["type"]
281     assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
282     assert_equal "closed", js["properties"]["status"]
283     assert_equal 3, js["properties"]["comments"].count
284     assert_equal "closed", js["properties"]["comments"].last["action"]
285     assert_equal "This is a close comment", js["properties"]["comments"].last["text"]
286     assert_equal "test2", js["properties"]["comments"].last["user"]
287   end
288
289   def test_close_fail
290     post :close
291     assert_response :unauthorized
292
293     basic_authorization(users(:public_user).email, "test")
294
295     post :close
296     assert_response :bad_request
297
298     post :close, {:id => 12345}
299     assert_response :not_found
300
301     post :close, {:id => notes(:hidden_note_with_comment).id}
302     assert_response :gone
303
304     post :close, {:id => notes(:closed_note_with_comment).id}
305     assert_response :conflict
306   end
307
308   def test_show_success
309     get :show, {:id => notes(:open_note).id, :format => "xml"}
310     assert_response :success
311     assert_equal "application/xml", @response.content_type
312     assert_select "osm", :count => 1 do
313       assert_select "note[lat=#{notes(:open_note).lat}][lon=#{notes(:open_note).lon}]", :count => 1 do
314         assert_select "id", notes(:open_note).id
315         assert_select "url", note_url(notes(:open_note), :format => "xml")
316         assert_select "comment_url", comment_note_url(notes(:open_note), :format => "xml")
317         assert_select "close_url", close_note_url(notes(:open_note), :format => "xml")
318         assert_select "date_created", notes(:open_note).created_at.to_s
319         assert_select "status", notes(:open_note).status
320         assert_select "comments", :count => 1 do
321           assert_select "comment", :count => 1
322         end
323       end
324     end
325
326     get :show, {:id => notes(:open_note).id, :format => "rss"}
327     assert_response :success
328     assert_equal "application/rss+xml", @response.content_type
329     assert_select "rss", :count => 1 do
330       assert_select "channel", :count => 1 do
331         assert_select "item", :count => 1 do
332           assert_select "link", browse_note_url(notes(:open_note))
333           assert_select "guid", note_url(notes(:open_note))
334           assert_select "pubDate", notes(:open_note).created_at.to_s(:rfc822)
335 #          assert_select "geo:lat", notes(:open_note).lat.to_s
336 #          assert_select "geo:long", notes(:open_note).lon
337 #          assert_select "georss:point", "#{notes(:open_note).lon} #{notes(:open_note).lon}"
338         end
339       end
340     end
341
342     get :show, {:id => notes(:open_note).id, :format => "json"}
343     assert_response :success
344     assert_equal "application/json", @response.content_type
345     js = ActiveSupport::JSON.decode(@response.body)
346     assert_not_nil js
347     assert_equal "Feature", js["type"]
348     assert_equal "Point", js["geometry"]["type"]
349     assert_equal notes(:open_note).lat, js["geometry"]["coordinates"][0]
350     assert_equal notes(:open_note).lon, js["geometry"]["coordinates"][1]
351     assert_equal notes(:open_note).id, js["properties"]["id"]
352     assert_equal note_url(notes(:open_note), :format => "json"), js["properties"]["url"]
353     assert_equal comment_note_url(notes(:open_note), :format => "json"), js["properties"]["comment_url"]
354     assert_equal close_note_url(notes(:open_note), :format => "json"), js["properties"]["close_url"]
355     assert_equal notes(:open_note).created_at, js["properties"]["date_created"]
356     assert_equal notes(:open_note).status, js["properties"]["status"]
357
358     get :show, {:id => notes(:open_note).id, :format => "gpx"}
359     assert_response :success
360     assert_equal "application/gpx+xml", @response.content_type
361     assert_select "gpx", :count => 1 do
362       assert_select "wpt[lat=#{notes(:open_note).lat}][lon=#{notes(:open_note).lon}]", :count => 1 do
363         assert_select "extension", :count => 1 do
364           assert_select "id", notes(:open_note).id
365           assert_select "url", note_url(notes(:open_note), :format => "gpx")
366           assert_select "comment_url", comment_note_url(notes(:open_note), :format => "gpx")
367           assert_select "close_url", close_note_url(notes(:open_note), :format => "gpx")
368         end
369       end
370     end
371   end
372
373   def test_show_hidden_comment
374     get :show, {:id => notes(:note_with_hidden_comment).id, :format => "json"}
375     assert_response :success
376     js = ActiveSupport::JSON.decode(@response.body)
377     assert_not_nil js
378     assert_equal "Feature", js["type"]
379     assert_equal notes(:note_with_hidden_comment).id, js["properties"]["id"]
380     assert_equal 2, js["properties"]["comments"].count
381     assert_equal "Valid comment for note 5", js["properties"]["comments"][0]["text"]
382     assert_equal "Another valid comment for note 5", js["properties"]["comments"][1]["text"]
383   end
384
385   def test_show_fail
386     get :show, {:id => 12345}
387     assert_response :not_found
388
389     get :show, {:id => notes(:hidden_note_with_comment).id}
390     assert_response :gone
391   end
392
393   def test_destroy_success
394     delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
395     assert_response :unauthorized
396
397     basic_authorization(users(:public_user).email, "test")
398
399     delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
400     assert_response :forbidden
401
402     basic_authorization(users(:moderator_user).email, "test")
403
404     delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
405     assert_response :success
406     js = ActiveSupport::JSON.decode(@response.body)
407     assert_not_nil js
408     assert_equal "Feature", js["type"]
409     assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
410     assert_equal "hidden", js["properties"]["status"]
411     assert_equal 3, js["properties"]["comments"].count
412     assert_equal "hidden", js["properties"]["comments"].last["action"]
413     assert_equal "This is a hide comment", js["properties"]["comments"].last["text"]
414     assert_equal "moderator", js["properties"]["comments"].last["user"]
415
416     get :show, {:id => notes(:open_note_with_comment).id, :format => 'json'}
417     assert_response :gone
418   end
419
420   def test_destroy_fail
421     delete :destroy, {:id => 12345, :format => "json"}
422     assert_response :unauthorized
423
424     basic_authorization(users(:public_user).email, "test")
425
426     delete :destroy, {:id => 12345, :format => "json"}
427     assert_response :forbidden
428
429     basic_authorization(users(:moderator_user).email, "test")
430
431     delete :destroy, {:id => 12345, :format => "json"}
432     assert_response :not_found
433
434     delete :destroy, {:id => notes(:hidden_note_with_comment).id, :format => "json"}
435     assert_response :gone
436   end
437
438   def test_index_success
439     get :index, {:bbox => '1,1,1.2,1.2', :format => 'rss'}
440     assert_response :success
441     assert_equal "application/rss+xml", @response.content_type
442     assert_select "rss", :count => 1 do
443       assert_select "channel", :count => 1 do
444         assert_select "item", :count => 2
445       end
446     end
447
448     get :index, {:bbox => '1,1,1.2,1.2', :format => 'json'}
449     assert_response :success
450     assert_equal "application/json", @response.content_type
451     js = ActiveSupport::JSON.decode(@response.body)
452     assert_not_nil js
453     assert_equal "FeatureCollection", js["type"]
454     assert_equal 2, js["features"].count
455
456     get :index, {:bbox => '1,1,1.2,1.2', :format => 'xml'}
457     assert_response :success
458     assert_equal "application/xml", @response.content_type
459     assert_select "osm", :count => 1 do
460       assert_select "note", :count => 2
461     end
462
463     get :index, {:bbox => '1,1,1.2,1.2', :format => 'gpx'}
464     assert_response :success
465     assert_equal "application/gpx+xml", @response.content_type
466     assert_select "gpx", :count => 1 do
467       assert_select "wpt", :count => 2
468     end
469   end
470
471   def test_index_empty_area
472     get :index, {:bbox => '5,5,5.1,5.1', :format => 'rss'}
473     assert_response :success
474     assert_equal "application/rss+xml", @response.content_type
475     assert_select "rss", :count => 1 do
476       assert_select "channel", :count => 1 do
477         assert_select "item", :count => 0
478       end
479     end
480
481     get :index, {:bbox => '5,5,5.1,5.1', :format => 'json'}
482     assert_response :success
483     assert_equal "application/json", @response.content_type
484     js = ActiveSupport::JSON.decode(@response.body)
485     assert_not_nil js
486     assert_equal "FeatureCollection", js["type"]
487     assert_equal 0, js["features"].count
488
489     get :index, {:bbox => '5,5,5.1,5.1', :format => 'xml'}
490     assert_response :success
491     assert_equal "application/xml", @response.content_type
492     assert_select "osm", :count => 1 do
493       assert_select "note", :count => 0
494     end
495
496     get :index, {:bbox => '5,5,5.1,5.1', :format => 'gpx'}
497     assert_response :success
498     assert_equal "application/gpx+xml", @response.content_type
499     assert_select "gpx", :count => 1 do
500       assert_select "wpt", :count => 0
501     end
502   end
503
504   def test_index_large_area
505     get :index, {:bbox => '-2.5,-2.5,2.5,2.5', :format => :json}
506     assert_response :success
507     assert_equal "application/json", @response.content_type
508
509     get :index, {:l => '-2.5', :b => '-2.5', :r => '2.5', :t => '2.5', :format => :json}
510     assert_response :success
511     assert_equal "application/json", @response.content_type
512
513     get :index, {:bbox => '-10,-10,12,12', :format => :json}
514     assert_response :bad_request
515     assert_equal "text/plain", @response.content_type
516
517     get :index, {:l => '-10', :b => '-10', :r => '12', :t => '12', :format => :json}
518     assert_response :bad_request
519     assert_equal "text/plain", @response.content_type
520   end
521
522   def test_index_closed
523     get :index, {:bbox => '1,1,1.7,1.7', :closed => '7', :format => 'json'}
524     assert_response :success
525     assert_equal "application/json", @response.content_type
526     js = ActiveSupport::JSON.decode(@response.body)
527     assert_not_nil js
528     assert_equal "FeatureCollection", js["type"]
529     assert_equal 4, js["features"].count
530
531     get :index, {:bbox => '1,1,1.7,1.7', :closed => '0', :format => 'json'}
532     assert_response :success
533     assert_equal "application/json", @response.content_type
534     js = ActiveSupport::JSON.decode(@response.body)
535     assert_not_nil js
536     assert_equal "FeatureCollection", js["type"]
537     assert_equal 4, js["features"].count
538
539     get :index, {:bbox => '1,1,1.7,1.7', :closed => '-1', :format => 'json'}
540     assert_response :success
541     assert_equal "application/json", @response.content_type
542     js = ActiveSupport::JSON.decode(@response.body)
543     assert_not_nil js
544     assert_equal "FeatureCollection", js["type"]
545     assert_equal 6, js["features"].count
546   end
547
548   def test_index_bad_params
549     get :index, {:bbox => '-2.5,-2.5,2.5'}
550     assert_response :bad_request
551
552     get :index, {:bbox => '-2.5,-2.5,2.5,2.5,2.5'}
553     assert_response :bad_request
554
555     get :index, {:b => '-2.5', :r => '2.5', :t => '2.5'}
556     assert_response :bad_request
557
558     get :index, {:l => '-2.5', :r => '2.5', :t => '2.5'}
559     assert_response :bad_request
560
561     get :index, {:l => '-2.5', :b => '-2.5', :t => '2.5'}
562     assert_response :bad_request
563
564     get :index, {:l => '-2.5', :b => '-2.5', :r => '2.5'}
565     assert_response :bad_request
566   end
567
568   def test_search_success
569     get :search, {:q => 'note 1', :format => 'xml'}
570     assert_response :success
571     assert_equal "application/xml", @response.content_type
572     assert_select "osm", :count => 1 do
573       assert_select "note", :count => 1
574     end
575
576     get :search, {:q => 'note 1', :format => 'json'}
577     assert_response :success
578     assert_equal "application/json", @response.content_type
579     js = ActiveSupport::JSON.decode(@response.body)
580     assert_not_nil js
581     assert_equal "FeatureCollection", js["type"]
582     assert_equal 1, js["features"].count
583
584     get :search, {:q => 'note 1', :format => 'rss'}
585     assert_response :success
586     assert_equal "application/rss+xml", @response.content_type
587     assert_select "rss", :count => 1 do
588       assert_select "channel", :count => 1 do
589         assert_select "item", :count => 1
590       end
591     end
592
593     get :search, {:q => 'note 1', :format => 'gpx'}
594     assert_response :success
595     assert_equal "application/gpx+xml", @response.content_type
596     assert_select "gpx", :count => 1 do
597       assert_select "wpt", :count => 1
598     end
599   end
600
601   def test_search_no_match
602     get :search, {:q => 'no match', :format => 'xml'}
603     assert_response :success
604     assert_equal "application/xml", @response.content_type
605     assert_select "osm", :count => 1 do
606       assert_select "note", :count => 0
607     end
608
609     get :search, {:q => 'no match', :format => 'json'}
610     assert_response :success
611     assert_equal "application/json", @response.content_type
612     js = ActiveSupport::JSON.decode(@response.body)
613     assert_not_nil js
614     assert_equal "FeatureCollection", js["type"]
615     assert_equal 0, js["features"].count
616
617     get :search, {:q => 'no match', :format => 'rss'}
618     assert_response :success
619     assert_equal "application/rss+xml", @response.content_type
620     assert_select "rss", :count => 1 do
621       assert_select "channel", :count => 1 do
622         assert_select "item", :count => 0
623       end
624     end
625
626     get :search, {:q => 'no match', :format => 'gpx'}
627     assert_response :success
628     assert_equal "application/gpx+xml", @response.content_type
629     assert_select "gpx", :count => 1 do
630       assert_select "wpt", :count => 0
631     end
632   end
633
634   def test_search_bad_params
635     get :search
636     assert_response :bad_request
637   end
638
639   def test_feed_success
640     get :feed, {:format => "rss"}
641     assert_response :success
642     assert_equal "application/rss+xml", @response.content_type
643
644     get :feed, {:bbox => "1,1,1.2,1.2", :format => "rss"}
645     assert_response :success    
646     assert_equal "application/rss+xml", @response.content_type
647   end
648
649   def test_feed_fail
650     get :feed, {:bbox => "1,1,1.2"}
651     assert_response :bad_request
652
653     get :feed, {:bbox => "1,1,1.2,1.2,1.2"}
654     assert_response :bad_request
655   end
656
657   def test_mine_success
658     get :mine, {:display_name => "test"}
659     assert_response :success
660
661     get :mine, {:display_name => "pulibc_test2"}
662     assert_response :success
663
664     get :mine, {:display_name => "non-existent"}
665     assert_response :not_found  
666   end
667 end