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