3 class NotesControllerTest < ActionController::TestCase
4 fixtures :users, :user_roles, :notes, :note_comments
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/notes", :method => :post },
11 { :controller => "notes", :action => "create", :format => "xml" }
14 { :path => "/api/0.6/notes/1", :method => :get },
15 { :controller => "notes", :action => "show", :id => "1", :format => "xml" }
18 { :controller => "notes", :action => "show", :id => "1", :format => "xml" },
19 { :path => "/api/0.6/notes/1.xml", :method => :get }
22 { :path => "/api/0.6/notes/1.rss", :method => :get },
23 { :controller => "notes", :action => "show", :id => "1", :format => "rss" }
26 { :path => "/api/0.6/notes/1.json", :method => :get },
27 { :controller => "notes", :action => "show", :id => "1", :format => "json" }
30 { :path => "/api/0.6/notes/1.gpx", :method => :get },
31 { :controller => "notes", :action => "show", :id => "1", :format => "gpx" }
34 { :path => "/api/0.6/notes/1/comment", :method => :post },
35 { :controller => "notes", :action => "comment", :id => "1", :format => "xml" }
38 { :path => "/api/0.6/notes/1/close", :method => :post },
39 { :controller => "notes", :action => "close", :id => "1", :format => "xml" }
42 { :path => "/api/0.6/notes/1/reopen", :method => :post },
43 { :controller => "notes", :action => "reopen", :id => "1", :format => "xml" }
46 { :path => "/api/0.6/notes/1", :method => :delete },
47 { :controller => "notes", :action => "destroy", :id => "1", :format => "xml" }
51 { :path => "/api/0.6/notes", :method => :get },
52 { :controller => "notes", :action => "index", :format => "xml" }
55 { :controller => "notes", :action => "index", :format => "xml" },
56 { :path => "/api/0.6/notes.xml", :method => :get }
59 { :path => "/api/0.6/notes.rss", :method => :get },
60 { :controller => "notes", :action => "index", :format => "rss" }
63 { :path => "/api/0.6/notes.json", :method => :get },
64 { :controller => "notes", :action => "index", :format => "json" }
67 { :path => "/api/0.6/notes.gpx", :method => :get },
68 { :controller => "notes", :action => "index", :format => "gpx" }
72 { :path => "/api/0.6/notes/search", :method => :get },
73 { :controller => "notes", :action => "search", :format => "xml" }
76 { :controller => "notes", :action => "search", :format => "xml" },
77 { :path => "/api/0.6/notes/search.xml", :method => :get }
80 { :path => "/api/0.6/notes/search.rss", :method => :get },
81 { :controller => "notes", :action => "search", :format => "rss" }
84 { :path => "/api/0.6/notes/search.json", :method => :get },
85 { :controller => "notes", :action => "search", :format => "json" }
88 { :path => "/api/0.6/notes/search.gpx", :method => :get },
89 { :controller => "notes", :action => "search", :format => "gpx" }
93 { :path => "/api/0.6/notes/feed", :method => :get },
94 { :controller => "notes", :action => "feed", :format => "rss" }
98 { :controller => "notes", :action => "create" },
99 { :path => "/api/0.6/notes/addPOIexec", :method => :post }
102 { :controller => "notes", :action => "close" },
103 { :path => "/api/0.6/notes/closePOIexec", :method => :post }
106 { :controller => "notes", :action => "comment" },
107 { :path => "/api/0.6/notes/editPOIexec", :method => :post }
110 { :controller => "notes", :action => "index", :format => "gpx" },
111 { :path => "/api/0.6/notes/getGPX", :method => :get }
114 { :controller => "notes", :action => "feed", :format => "rss" },
115 { :path => "/api/0.6/notes/getRSSfeed", :method => :get }
119 { :path => "/user/username/notes", :method => :get },
120 { :controller => "notes", :action => "mine", :display_name => "username" }
124 def test_create_success
125 assert_difference "Note.count", 1 do
126 assert_difference "NoteComment.count", 1 do
127 post :create, :lat => -1.0, :lon => -1.0, :text => "This is a comment", :format => "json"
130 assert_response :success
131 js = ActiveSupport::JSON.decode(@response.body)
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"]
143 get :show, :id => id, :format => "json"
144 assert_response :success
145 js = ActiveSupport::JSON.decode(@response.body)
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"]
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"
164 assert_response :bad_request
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"
171 assert_response :bad_request
173 assert_no_difference "Note.count" do
174 assert_no_difference "NoteComment.count" do
175 post :create, :lat => -1.0, :lon => -1.0
178 assert_response :bad_request
180 assert_no_difference "Note.count" do
181 assert_no_difference "NoteComment.count" do
182 post :create, :lat => -1.0, :lon => -1.0, :text => ""
185 assert_response :bad_request
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"
192 assert_response :bad_request
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"
199 assert_response :bad_request
201 assert_no_difference "Note.count" do
202 assert_no_difference "NoteComment.count" do
203 post :create, :lat => "abc", :lon => -1.0, :text => "This is a comment"
206 assert_response :bad_request
208 assert_no_difference "Note.count" do
209 assert_no_difference "NoteComment.count" do
210 post :create, :lat => -1.0, :lon => "abc", :text => "This is a comment"
213 assert_response :bad_request
216 def test_comment_success
217 assert_difference "NoteComment.count", 1 do
218 assert_no_difference "ActionMailer::Base.deliveries.size" do
219 post :comment, :id => notes(:open_note_with_comment).id, :text => "This is an additional comment", :format => "json"
222 assert_response :success
223 js = ActiveSupport::JSON.decode(@response.body)
225 assert_equal "Feature", js["type"]
226 assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
227 assert_equal "open", js["properties"]["status"]
228 assert_equal 3, js["properties"]["comments"].count
229 assert_equal "commented", js["properties"]["comments"].last["action"]
230 assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
231 assert_nil js["properties"]["comments"].last["user"]
233 get :show, :id => notes(:open_note_with_comment).id, :format => "json"
234 assert_response :success
235 js = ActiveSupport::JSON.decode(@response.body)
237 assert_equal "Feature", js["type"]
238 assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
239 assert_equal "open", js["properties"]["status"]
240 assert_equal 3, js["properties"]["comments"].count
241 assert_equal "commented", js["properties"]["comments"].last["action"]
242 assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
243 assert_nil js["properties"]["comments"].last["user"]
245 assert_difference "NoteComment.count", 1 do
246 assert_difference "ActionMailer::Base.deliveries.size", 2 do
247 post :comment, :id => notes(:note_with_comments_by_users).id, :text => "This is an additional comment", :format => "json"
250 assert_response :success
251 js = ActiveSupport::JSON.decode(@response.body)
253 assert_equal "Feature", js["type"]
254 assert_equal notes(:note_with_comments_by_users).id, js["properties"]["id"]
255 assert_equal "open", js["properties"]["status"]
256 assert_equal 3, js["properties"]["comments"].count
257 assert_equal "commented", js["properties"]["comments"].last["action"]
258 assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
259 assert_nil js["properties"]["comments"].last["user"]
261 email = ActionMailer::Base.deliveries.find { |e| e.to.first == "test@openstreetmap.org" }
263 assert_equal 1, email.to.length
264 assert_equal "[OpenStreetMap] An anonymous user has commented on one of your notes", email.subject
266 email = ActionMailer::Base.deliveries.find { |e| e.to.first == "public@OpenStreetMap.org" }
268 assert_equal 1, email.to.length
269 assert_equal "[OpenStreetMap] An anonymous user has commented on a note you are interested in", email.subject
271 get :show, :id => notes(:note_with_comments_by_users).id, :format => "json"
272 assert_response :success
273 js = ActiveSupport::JSON.decode(@response.body)
275 assert_equal "Feature", js["type"]
276 assert_equal notes(:note_with_comments_by_users).id, js["properties"]["id"]
277 assert_equal "open", js["properties"]["status"]
278 assert_equal 3, js["properties"]["comments"].count
279 assert_equal "commented", js["properties"]["comments"].last["action"]
280 assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
281 assert_nil js["properties"]["comments"].last["user"]
283 ActionMailer::Base.deliveries.clear
285 basic_authorization(users(:public_user).email, "test")
287 assert_difference "NoteComment.count", 1 do
288 assert_difference "ActionMailer::Base.deliveries.size", 2 do
289 post :comment, :id => notes(:note_with_comments_by_users).id, :text => "This is an additional comment", :format => "json"
292 assert_response :success
293 js = ActiveSupport::JSON.decode(@response.body)
295 assert_equal "Feature", js["type"]
296 assert_equal notes(:note_with_comments_by_users).id, js["properties"]["id"]
297 assert_equal "open", js["properties"]["status"]
298 assert_equal 4, js["properties"]["comments"].count
299 assert_equal "commented", js["properties"]["comments"].last["action"]
300 assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
301 assert_equal "test2", js["properties"]["comments"].last["user"]
303 email = ActionMailer::Base.deliveries.find { |e| e.to.first == "test@openstreetmap.org" }
305 assert_equal 1, email.to.length
306 assert_equal "[OpenStreetMap] test2 has commented on one of your notes", email.subject
307 assert_equal "test@openstreetmap.org", email.to.first
309 email = ActionMailer::Base.deliveries.find { |e| e.to.first == "public@OpenStreetMap.org" }
311 assert_equal 1, email.to.length
312 assert_equal "[OpenStreetMap] test2 has commented on a note you are interested in", email.subject
314 get :show, :id => notes(:note_with_comments_by_users).id, :format => "json"
315 assert_response :success
316 js = ActiveSupport::JSON.decode(@response.body)
318 assert_equal "Feature", js["type"]
319 assert_equal notes(:note_with_comments_by_users).id, js["properties"]["id"]
320 assert_equal "open", js["properties"]["status"]
321 assert_equal 4, js["properties"]["comments"].count
322 assert_equal "commented", js["properties"]["comments"].last["action"]
323 assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
324 assert_equal "test2", js["properties"]["comments"].last["user"]
326 ActionMailer::Base.deliveries.clear
329 def test_comment_fail
330 assert_no_difference "NoteComment.count" do
331 post :comment, :text => "This is an additional comment"
333 assert_response :bad_request
335 assert_no_difference "NoteComment.count" do
336 post :comment, :id => notes(:open_note_with_comment).id
338 assert_response :bad_request
340 assert_no_difference "NoteComment.count" do
341 post :comment, :id => notes(:open_note_with_comment).id, :text => ""
343 assert_response :bad_request
345 assert_no_difference "NoteComment.count" do
346 post :comment, :id => 12345, :text => "This is an additional comment"
348 assert_response :not_found
350 assert_no_difference "NoteComment.count" do
351 post :comment, :id => notes(:hidden_note_with_comment).id, :text => "This is an additional comment"
353 assert_response :gone
355 assert_no_difference "NoteComment.count" do
356 post :comment, :id => notes(:closed_note_with_comment).id, :text => "This is an additional comment"
358 assert_response :conflict
361 def test_close_success
362 post :close, :id => notes(:open_note_with_comment).id, :text => "This is a close comment", :format => "json"
363 assert_response :unauthorized
365 basic_authorization(users(:public_user).email, "test")
367 post :close, :id => notes(:open_note_with_comment).id, :text => "This is a close comment", :format => "json"
368 assert_response :success
369 js = ActiveSupport::JSON.decode(@response.body)
371 assert_equal "Feature", js["type"]
372 assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
373 assert_equal "closed", js["properties"]["status"]
374 assert_equal 3, js["properties"]["comments"].count
375 assert_equal "closed", js["properties"]["comments"].last["action"]
376 assert_equal "This is a close comment", js["properties"]["comments"].last["text"]
377 assert_equal "test2", js["properties"]["comments"].last["user"]
379 get :show, :id => notes(:open_note_with_comment).id, :format => "json"
380 assert_response :success
381 js = ActiveSupport::JSON.decode(@response.body)
383 assert_equal "Feature", js["type"]
384 assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
385 assert_equal "closed", js["properties"]["status"]
386 assert_equal 3, js["properties"]["comments"].count
387 assert_equal "closed", js["properties"]["comments"].last["action"]
388 assert_equal "This is a close comment", js["properties"]["comments"].last["text"]
389 assert_equal "test2", js["properties"]["comments"].last["user"]
394 assert_response :unauthorized
396 basic_authorization(users(:public_user).email, "test")
399 assert_response :bad_request
401 post :close, :id => 12345
402 assert_response :not_found
404 post :close, :id => notes(:hidden_note_with_comment).id
405 assert_response :gone
407 post :close, :id => notes(:closed_note_with_comment).id
408 assert_response :conflict
411 def test_reopen_success
412 post :reopen, :id => notes(:closed_note_with_comment).id, :text => "This is a reopen comment", :format => "json"
413 assert_response :unauthorized
415 basic_authorization(users(:public_user).email, "test")
417 post :reopen, :id => notes(:closed_note_with_comment).id, :text => "This is a reopen comment", :format => "json"
418 assert_response :success
419 js = ActiveSupport::JSON.decode(@response.body)
421 assert_equal "Feature", js["type"]
422 assert_equal notes(:closed_note_with_comment).id, js["properties"]["id"]
423 assert_equal "open", js["properties"]["status"]
424 assert_equal 2, js["properties"]["comments"].count
425 assert_equal "reopened", js["properties"]["comments"].last["action"]
426 assert_equal "This is a reopen comment", js["properties"]["comments"].last["text"]
427 assert_equal "test2", js["properties"]["comments"].last["user"]
429 get :show, :id => notes(:closed_note_with_comment).id, :format => "json"
430 assert_response :success
431 js = ActiveSupport::JSON.decode(@response.body)
433 assert_equal "Feature", js["type"]
434 assert_equal notes(:closed_note_with_comment).id, js["properties"]["id"]
435 assert_equal "open", js["properties"]["status"]
436 assert_equal 2, js["properties"]["comments"].count
437 assert_equal "reopened", js["properties"]["comments"].last["action"]
438 assert_equal "This is a reopen comment", js["properties"]["comments"].last["text"]
439 assert_equal "test2", js["properties"]["comments"].last["user"]
443 post :reopen, :id => notes(:hidden_note_with_comment).id
444 assert_response :unauthorized
446 basic_authorization(users(:public_user).email, "test")
448 post :reopen, :id => 12345
449 assert_response :not_found
451 post :reopen, :id => notes(:hidden_note_with_comment).id
452 assert_response :gone
454 post :reopen, :id => notes(:open_note_with_comment).id
455 assert_response :conflict
458 def test_show_success
459 get :show, :id => notes(:open_note).id, :format => "xml"
460 assert_response :success
461 assert_equal "application/xml", @response.content_type
462 assert_select "osm", :count => 1 do
463 assert_select "note[lat='#{notes(:open_note).lat}'][lon='#{notes(:open_note).lon}']", :count => 1 do
464 assert_select "id", notes(:open_note).id
465 assert_select "url", note_url(notes(:open_note), :format => "xml")
466 assert_select "comment_url", comment_note_url(notes(:open_note), :format => "xml")
467 assert_select "close_url", close_note_url(notes(:open_note), :format => "xml")
468 assert_select "date_created", notes(:open_note).created_at.to_s
469 assert_select "status", notes(:open_note).status
470 assert_select "comments", :count => 1 do
471 assert_select "comment", :count => 1
476 get :show, :id => notes(:open_note).id, :format => "rss"
477 assert_response :success
478 assert_equal "application/rss+xml", @response.content_type
479 assert_select "rss", :count => 1 do
480 assert_select "channel", :count => 1 do
481 assert_select "item", :count => 1 do
482 assert_select "link", browse_note_url(notes(:open_note))
483 assert_select "guid", note_url(notes(:open_note))
484 assert_select "pubDate", notes(:open_note).created_at.to_s(:rfc822)
485 # assert_select "geo:lat", notes(:open_note).lat.to_s
486 # assert_select "geo:long", notes(:open_note).lon
487 # assert_select "georss:point", "#{notes(:open_note).lon} #{notes(:open_note).lon}"
492 get :show, :id => notes(:open_note).id, :format => "json"
493 assert_response :success
494 assert_equal "application/json", @response.content_type
495 js = ActiveSupport::JSON.decode(@response.body)
497 assert_equal "Feature", js["type"]
498 assert_equal "Point", js["geometry"]["type"]
499 assert_equal notes(:open_note).lat, js["geometry"]["coordinates"][0]
500 assert_equal notes(:open_note).lon, js["geometry"]["coordinates"][1]
501 assert_equal notes(:open_note).id, js["properties"]["id"]
502 assert_equal note_url(notes(:open_note), :format => "json"), js["properties"]["url"]
503 assert_equal comment_note_url(notes(:open_note), :format => "json"), js["properties"]["comment_url"]
504 assert_equal close_note_url(notes(:open_note), :format => "json"), js["properties"]["close_url"]
505 assert_equal notes(:open_note).created_at, js["properties"]["date_created"]
506 assert_equal notes(:open_note).status, js["properties"]["status"]
508 get :show, :id => notes(:open_note).id, :format => "gpx"
509 assert_response :success
510 assert_equal "application/gpx+xml", @response.content_type
511 assert_select "gpx", :count => 1 do
512 assert_select "wpt[lat='#{notes(:open_note).lat}'][lon='#{notes(:open_note).lon}']", :count => 1 do
513 assert_select "extensions", :count => 1 do
514 assert_select "id", notes(:open_note).id
515 assert_select "url", note_url(notes(:open_note), :format => "gpx")
516 assert_select "comment_url", comment_note_url(notes(:open_note), :format => "gpx")
517 assert_select "close_url", close_note_url(notes(:open_note), :format => "gpx")
523 def test_show_hidden_comment
524 get :show, :id => notes(:note_with_hidden_comment).id, :format => "json"
525 assert_response :success
526 js = ActiveSupport::JSON.decode(@response.body)
528 assert_equal "Feature", js["type"]
529 assert_equal notes(:note_with_hidden_comment).id, js["properties"]["id"]
530 assert_equal 2, js["properties"]["comments"].count
531 assert_equal "Valid comment for note 5", js["properties"]["comments"][0]["text"]
532 assert_equal "Another valid comment for note 5", js["properties"]["comments"][1]["text"]
536 get :show, :id => 12345
537 assert_response :not_found
539 get :show, :id => notes(:hidden_note_with_comment).id
540 assert_response :gone
543 def test_destroy_success
544 delete :destroy, :id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"
545 assert_response :unauthorized
547 basic_authorization(users(:public_user).email, "test")
549 delete :destroy, :id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"
550 assert_response :forbidden
552 basic_authorization(users(:moderator_user).email, "test")
554 delete :destroy, :id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"
555 assert_response :success
556 js = ActiveSupport::JSON.decode(@response.body)
558 assert_equal "Feature", js["type"]
559 assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
560 assert_equal "hidden", js["properties"]["status"]
561 assert_equal 3, js["properties"]["comments"].count
562 assert_equal "hidden", js["properties"]["comments"].last["action"]
563 assert_equal "This is a hide comment", js["properties"]["comments"].last["text"]
564 assert_equal "moderator", js["properties"]["comments"].last["user"]
566 get :show, :id => notes(:open_note_with_comment).id, :format => "json"
567 assert_response :gone
570 def test_destroy_fail
571 delete :destroy, :id => 12345, :format => "json"
572 assert_response :unauthorized
574 basic_authorization(users(:public_user).email, "test")
576 delete :destroy, :id => 12345, :format => "json"
577 assert_response :forbidden
579 basic_authorization(users(:moderator_user).email, "test")
581 delete :destroy, :id => 12345, :format => "json"
582 assert_response :not_found
584 delete :destroy, :id => notes(:hidden_note_with_comment).id, :format => "json"
585 assert_response :gone
588 def test_index_success
589 get :index, :bbox => "1,1,1.2,1.2", :format => "rss"
590 assert_response :success
591 assert_equal "application/rss+xml", @response.content_type
592 assert_select "rss", :count => 1 do
593 assert_select "channel", :count => 1 do
594 assert_select "item", :count => 2
598 get :index, :bbox => "1,1,1.2,1.2", :format => "json"
599 assert_response :success
600 assert_equal "application/json", @response.content_type
601 js = ActiveSupport::JSON.decode(@response.body)
603 assert_equal "FeatureCollection", js["type"]
604 assert_equal 2, js["features"].count
606 get :index, :bbox => "1,1,1.2,1.2", :format => "xml"
607 assert_response :success
608 assert_equal "application/xml", @response.content_type
609 assert_select "osm", :count => 1 do
610 assert_select "note", :count => 2
613 get :index, :bbox => "1,1,1.2,1.2", :format => "gpx"
614 assert_response :success
615 assert_equal "application/gpx+xml", @response.content_type
616 assert_select "gpx", :count => 1 do
617 assert_select "wpt", :count => 2
622 get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "rss"
623 assert_response :success
624 assert_equal "application/rss+xml", @response.content_type
625 assert_select "rss", :count => 1 do
626 assert_select "channel", :count => 1 do
627 assert_select "item", :count => 1
631 get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "json"
632 assert_response :success
633 assert_equal "application/json", @response.content_type
634 js = ActiveSupport::JSON.decode(@response.body)
636 assert_equal "FeatureCollection", js["type"]
637 assert_equal 1, js["features"].count
639 get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "xml"
640 assert_response :success
641 assert_equal "application/xml", @response.content_type
642 assert_select "osm", :count => 1 do
643 assert_select "note", :count => 1
646 get :index, :bbox => "1,1,1.2,1.2", :limit => 1, :format => "gpx"
647 assert_response :success
648 assert_equal "application/gpx+xml", @response.content_type
649 assert_select "gpx", :count => 1 do
650 assert_select "wpt", :count => 1
654 def test_index_empty_area
655 get :index, :bbox => "5,5,5.1,5.1", :format => "rss"
656 assert_response :success
657 assert_equal "application/rss+xml", @response.content_type
658 assert_select "rss", :count => 1 do
659 assert_select "channel", :count => 1 do
660 assert_select "item", :count => 0
664 get :index, :bbox => "5,5,5.1,5.1", :format => "json"
665 assert_response :success
666 assert_equal "application/json", @response.content_type
667 js = ActiveSupport::JSON.decode(@response.body)
669 assert_equal "FeatureCollection", js["type"]
670 assert_equal 0, js["features"].count
672 get :index, :bbox => "5,5,5.1,5.1", :format => "xml"
673 assert_response :success
674 assert_equal "application/xml", @response.content_type
675 assert_select "osm", :count => 1 do
676 assert_select "note", :count => 0
679 get :index, :bbox => "5,5,5.1,5.1", :format => "gpx"
680 assert_response :success
681 assert_equal "application/gpx+xml", @response.content_type
682 assert_select "gpx", :count => 1 do
683 assert_select "wpt", :count => 0
687 def test_index_large_area
688 get :index, :bbox => "-2.5,-2.5,2.5,2.5", :format => :json
689 assert_response :success
690 assert_equal "application/json", @response.content_type
692 get :index, :l => "-2.5", :b => "-2.5", :r => "2.5", :t => "2.5", :format => :json
693 assert_response :success
694 assert_equal "application/json", @response.content_type
696 get :index, :bbox => "-10,-10,12,12", :format => :json
697 assert_response :bad_request
698 assert_equal "text/plain", @response.content_type
700 get :index, :l => "-10", :b => "-10", :r => "12", :t => "12", :format => :json
701 assert_response :bad_request
702 assert_equal "text/plain", @response.content_type
705 def test_index_closed
706 get :index, :bbox => "1,1,1.7,1.7", :closed => "7", :format => "json"
707 assert_response :success
708 assert_equal "application/json", @response.content_type
709 js = ActiveSupport::JSON.decode(@response.body)
711 assert_equal "FeatureCollection", js["type"]
712 assert_equal 4, js["features"].count
714 get :index, :bbox => "1,1,1.7,1.7", :closed => "0", :format => "json"
715 assert_response :success
716 assert_equal "application/json", @response.content_type
717 js = ActiveSupport::JSON.decode(@response.body)
719 assert_equal "FeatureCollection", js["type"]
720 assert_equal 4, js["features"].count
722 get :index, :bbox => "1,1,1.7,1.7", :closed => "-1", :format => "json"
723 assert_response :success
724 assert_equal "application/json", @response.content_type
725 js = ActiveSupport::JSON.decode(@response.body)
727 assert_equal "FeatureCollection", js["type"]
728 assert_equal 6, js["features"].count
731 def test_index_bad_params
732 get :index, :bbox => "-2.5,-2.5,2.5"
733 assert_response :bad_request
735 get :index, :bbox => "-2.5,-2.5,2.5,2.5,2.5"
736 assert_response :bad_request
738 get :index, :b => "-2.5", :r => "2.5", :t => "2.5"
739 assert_response :bad_request
741 get :index, :l => "-2.5", :r => "2.5", :t => "2.5"
742 assert_response :bad_request
744 get :index, :l => "-2.5", :b => "-2.5", :t => "2.5"
745 assert_response :bad_request
747 get :index, :l => "-2.5", :b => "-2.5", :r => "2.5"
748 assert_response :bad_request
750 get :index, :bbox => "1,1,1.7,1.7", :limit => "0", :format => "json"
751 assert_response :bad_request
753 get :index, :bbox => "1,1,1.7,1.7", :limit => "10001", :format => "json"
754 assert_response :bad_request
757 def test_search_success
758 get :search, :q => "note 1", :format => "xml"
759 assert_response :success
760 assert_equal "application/xml", @response.content_type
761 assert_select "osm", :count => 1 do
762 assert_select "note", :count => 1
765 get :search, :q => "note 1", :format => "json"
766 assert_response :success
767 assert_equal "application/json", @response.content_type
768 js = ActiveSupport::JSON.decode(@response.body)
770 assert_equal "FeatureCollection", js["type"]
771 assert_equal 1, js["features"].count
773 get :search, :q => "note 1", :format => "rss"
774 assert_response :success
775 assert_equal "application/rss+xml", @response.content_type
776 assert_select "rss", :count => 1 do
777 assert_select "channel", :count => 1 do
778 assert_select "item", :count => 1
782 get :search, :q => "note 1", :format => "gpx"
783 assert_response :success
784 assert_equal "application/gpx+xml", @response.content_type
785 assert_select "gpx", :count => 1 do
786 assert_select "wpt", :count => 1
790 def test_search_no_match
791 get :search, :q => "no match", :format => "xml"
792 assert_response :success
793 assert_equal "application/xml", @response.content_type
794 assert_select "osm", :count => 1 do
795 assert_select "note", :count => 0
798 get :search, :q => "no match", :format => "json"
799 assert_response :success
800 assert_equal "application/json", @response.content_type
801 js = ActiveSupport::JSON.decode(@response.body)
803 assert_equal "FeatureCollection", js["type"]
804 assert_equal 0, js["features"].count
806 get :search, :q => "no match", :format => "rss"
807 assert_response :success
808 assert_equal "application/rss+xml", @response.content_type
809 assert_select "rss", :count => 1 do
810 assert_select "channel", :count => 1 do
811 assert_select "item", :count => 0
815 get :search, :q => "no match", :format => "gpx"
816 assert_response :success
817 assert_equal "application/gpx+xml", @response.content_type
818 assert_select "gpx", :count => 1 do
819 assert_select "wpt", :count => 0
823 def test_search_bad_params
825 assert_response :bad_request
827 get :search, :q => "no match", :limit => "0", :format => "json"
828 assert_response :bad_request
830 get :search, :q => "no match", :limit => "10001", :format => "json"
831 assert_response :bad_request
834 def test_feed_success
835 get :feed, :format => "rss"
836 assert_response :success
837 assert_equal "application/rss+xml", @response.content_type
838 assert_select "rss", :count => 1 do
839 assert_select "channel", :count => 1 do
840 assert_select "item", :count => 8
844 get :feed, :bbox => "1,1,1.2,1.2", :format => "rss"
845 assert_response :success
846 assert_equal "application/rss+xml", @response.content_type
847 assert_select "rss", :count => 1 do
848 assert_select "channel", :count => 1 do
849 assert_select "item", :count => 3
855 get :feed, :bbox => "1,1,1.2", :format => "rss"
856 assert_response :bad_request
858 get :feed, :bbox => "1,1,1.2,1.2,1.2", :format => "rss"
859 assert_response :bad_request
861 get :feed, :bbox => "1,1,1.2,1.2", :limit => "0", :format => "rss"
862 assert_response :bad_request
864 get :feed, :bbox => "1,1,1.2,1.2", :limit => "10001", :format => "rss"
865 assert_response :bad_request
868 def test_mine_success
869 get :mine, :display_name => "test"
870 assert_response :success
872 get :mine, :display_name => "pulibc_test2"
873 assert_response :success
875 get :mine, :display_name => "non-existent"
876 assert_response :not_found