3 class TracesControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/traces", :method => :get },
9 { :controller => "traces", :action => "index" }
12 { :path => "/traces/page/1", :method => :get },
13 { :controller => "traces", :action => "index", :page => "1" }
16 { :path => "/traces/tag/tagname", :method => :get },
17 { :controller => "traces", :action => "index", :tag => "tagname" }
20 { :path => "/traces/tag/tagname/page/1", :method => :get },
21 { :controller => "traces", :action => "index", :tag => "tagname", :page => "1" }
24 { :path => "/user/username/traces", :method => :get },
25 { :controller => "traces", :action => "index", :display_name => "username" }
28 { :path => "/user/username/traces/page/1", :method => :get },
29 { :controller => "traces", :action => "index", :display_name => "username", :page => "1" }
32 { :path => "/user/username/traces/tag/tagname", :method => :get },
33 { :controller => "traces", :action => "index", :display_name => "username", :tag => "tagname" }
36 { :path => "/user/username/traces/tag/tagname/page/1", :method => :get },
37 { :controller => "traces", :action => "index", :display_name => "username", :tag => "tagname", :page => "1" }
41 { :path => "/traces/mine", :method => :get },
42 { :controller => "traces", :action => "mine" }
45 { :path => "/traces/mine/page/1", :method => :get },
46 { :controller => "traces", :action => "mine", :page => "1" }
49 { :path => "/traces/mine/tag/tagname", :method => :get },
50 { :controller => "traces", :action => "mine", :tag => "tagname" }
53 { :path => "/traces/mine/tag/tagname/page/1", :method => :get },
54 { :controller => "traces", :action => "mine", :tag => "tagname", :page => "1" }
58 { :path => "/traces/rss", :method => :get },
59 { :controller => "traces", :action => "georss", :format => :rss }
62 { :path => "/traces/tag/tagname/rss", :method => :get },
63 { :controller => "traces", :action => "georss", :tag => "tagname", :format => :rss }
66 { :path => "/user/username/traces/rss", :method => :get },
67 { :controller => "traces", :action => "georss", :display_name => "username", :format => :rss }
70 { :path => "/user/username/traces/tag/tagname/rss", :method => :get },
71 { :controller => "traces", :action => "georss", :display_name => "username", :tag => "tagname", :format => :rss }
75 { :path => "/user/username/traces/1", :method => :get },
76 { :controller => "traces", :action => "show", :display_name => "username", :id => "1" }
79 { :path => "/user/username/traces/1/picture", :method => :get },
80 { :controller => "traces", :action => "picture", :display_name => "username", :id => "1" }
83 { :path => "/user/username/traces/1/icon", :method => :get },
84 { :controller => "traces", :action => "icon", :display_name => "username", :id => "1" }
88 { :path => "/traces/new", :method => :get },
89 { :controller => "traces", :action => "new" }
92 { :path => "/traces", :method => :post },
93 { :controller => "traces", :action => "create" }
96 { :path => "/trace/1/data", :method => :get },
97 { :controller => "traces", :action => "data", :id => "1" }
100 { :path => "/trace/1/data.xml", :method => :get },
101 { :controller => "traces", :action => "data", :id => "1", :format => "xml" }
104 { :path => "/traces/1/edit", :method => :get },
105 { :controller => "traces", :action => "edit", :id => "1" }
108 { :path => "/traces/1", :method => :put },
109 { :controller => "traces", :action => "update", :id => "1" }
112 { :path => "/traces/1", :method => :delete },
113 { :controller => "traces", :action => "destroy", :id => "1" }
117 # Check that the index of traces is displayed
120 # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
121 trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
122 create(:tracetag, :trace => trace, :tag => "London")
124 trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
125 create(:tracetag, :trace => trace, :tag => "Birmingham")
127 trace_c = create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
128 create(:tracetag, :trace => trace, :tag => "London")
130 trace_d = create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
131 create(:tracetag, :trace => trace, :tag => "Birmingham")
134 # First with the public index
136 check_trace_index [trace_b, trace_a]
138 # Restrict traces to those with a given tag
139 get traces_path(:tag => "London")
140 check_trace_index [trace_a]
144 # Should see more when we are logged in
146 check_trace_index [trace_d, trace_c, trace_b, trace_a]
148 # Again, we should see more when we are logged in
149 get traces_path(:tag => "London")
150 check_trace_index [trace_c, trace_a]
153 # Check that I can get mine
156 create(:trace, :visibility => "public") do |trace|
157 create(:tracetag, :trace => trace, :tag => "Birmingham")
159 trace_b = create(:trace, :visibility => "private", :user => user) do |trace|
160 create(:tracetag, :trace => trace, :tag => "London")
163 # First try to get it when not logged in
165 assert_redirected_to login_path(:referer => "/traces/mine")
169 # Now try when logged in
171 assert_redirected_to :action => "index", :display_name => user.display_name
173 # Fetch the actual index
174 get traces_path(:display_name => user.display_name)
175 check_trace_index [trace_b]
178 # Check the index of traces for a specific user
181 second_user = create(:user)
182 third_user = create(:user)
184 trace_b = create(:trace, :visibility => "public", :user => user)
185 trace_c = create(:trace, :visibility => "private", :user => user) do |trace|
186 create(:tracetag, :trace => trace, :tag => "London")
189 # Test a user with no traces
190 get traces_path(:display_name => second_user.display_name)
193 # Test the user with the traces - should see only public ones
194 get traces_path(:display_name => user.display_name)
195 check_trace_index [trace_b]
197 session_for(third_user)
199 # Should still see only public ones when authenticated as another user
200 get traces_path(:display_name => user.display_name)
201 check_trace_index [trace_b]
205 # Should see all traces when authenticated as the target user
206 get traces_path(:display_name => user.display_name)
207 check_trace_index [trace_c, trace_b]
209 # Should only see traces with the correct tag when a tag is specified
210 get traces_path(:display_name => user.display_name, :tag => "London")
211 check_trace_index [trace_c]
213 # Should get an error if the user does not exist
214 get traces_path(:display_name => "UnknownUser")
215 assert_response :not_found
216 assert_template "users/no_such_user"
219 # Check a multi-page index
221 # Create several pages worth of traces
222 create_list(:trace, 50)
224 # Try and get the index
226 assert_response :success
227 assert_select "table#trace_list tbody", :count => 1 do
228 assert_select "tr", :count => 20
231 # Try and get the second page
232 get traces_path(:page => 2)
233 assert_response :success
234 assert_select "table#trace_list tbody", :count => 1 do
235 assert_select "tr", :count => 20
242 # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
243 trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
244 create(:tracetag, :trace => trace, :tag => "London")
246 trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
247 create(:tracetag, :trace => trace, :tag => "Birmingham")
249 create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
250 create(:tracetag, :trace => trace, :tag => "London")
252 create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
253 create(:tracetag, :trace => trace, :tag => "Birmingham")
256 # First with the public feed
258 check_trace_feed [trace_b, trace_a]
260 # Restrict traces to those with a given tag
261 get traces_rss_path(:tag => "London")
262 check_trace_feed [trace_a]
265 # Check the RSS feed for a specific user
268 second_user = create(:user)
271 trace_b = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago, :user => user)
272 trace_c = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago, :user => user) do |trace|
273 create(:tracetag, :trace => trace, :tag => "London")
275 create(:trace, :visibility => "private")
277 # Test a user with no traces
278 get traces_rss_path(:display_name => second_user.display_name)
281 # Test the user with the traces - should see only public ones
282 get traces_rss_path(:display_name => user.display_name)
283 check_trace_feed [trace_c, trace_b]
285 # Should only see traces with the correct tag when a tag is specified
286 get traces_rss_path(:display_name => user.display_name, :tag => "London")
287 check_trace_feed [trace_c]
289 # Should no traces if the user does not exist
290 get traces_rss_path(:display_name => "UnknownUser")
294 # Test showing a trace
296 public_trace_file = create(:trace, :visibility => "public")
298 # First with no auth, which should work since the trace is public
299 get show_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
300 check_trace_show public_trace_file
302 # Now with some other user, which should work since the trace is public
303 session_for(create(:user))
304 get show_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
305 check_trace_show public_trace_file
307 # And finally we should be able to do it with the owner of the trace
308 session_for(public_trace_file.user)
309 get show_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
310 check_trace_show public_trace_file
313 # Check an anonymous trace can't be viewed by another user
315 anon_trace_file = create(:trace, :visibility => "private")
318 get show_trace_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
319 assert_response :redirect
320 assert_redirected_to :action => :index
322 # Now with some other user, which should not work since the trace is anon
323 session_for(create(:user))
324 get show_trace_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
325 assert_response :redirect
326 assert_redirected_to :action => :index
328 # And finally we should be able to do it with the owner of the trace
329 session_for(anon_trace_file.user)
330 get show_trace_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
331 check_trace_show anon_trace_file
334 # Test showing a trace that doesn't exist
335 def test_show_not_found
336 deleted_trace_file = create(:trace, :deleted)
338 # First with a trace that has never existed
339 get show_trace_path(:display_name => create(:user).display_name, :id => 0)
340 assert_response :redirect
341 assert_redirected_to :action => :index
343 # Now with a trace that has been deleted
344 session_for(deleted_trace_file.user)
345 get show_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
346 assert_response :redirect
347 assert_redirected_to :action => :index
350 # Test downloading a trace
352 public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
354 # First with no auth, which should work since the trace is public
355 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
358 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
360 # Now with some other user, which should work since the trace is public
361 session_for(create(:user))
362 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
365 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
367 # And finally we should be able to do it with the owner of the trace
368 session_for(public_trace_file.user)
369 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
372 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
375 # Test downloading a compressed trace
376 def test_data_compressed
377 identifiable_trace_file = create(:trace, :visibility => "identifiable", :fixture => "d")
379 # First get the data as is
380 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file)
383 check_trace_data identifiable_trace_file, "c6422a3d8750faae49ed70e7e8a51b93", "application/gzip", "gpx.gz"
385 # Now ask explicitly for XML format
386 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "xml")
387 check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d", "application/xml", "xml"
389 # Now ask explicitly for GPX format
390 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "gpx")
391 check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d"
394 # Check an anonymous trace can't be downloaded by another user
396 anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
399 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
400 assert_response :not_found
402 # Now with some other user, which shouldn't work since the trace is anon
403 session_for(create(:user))
404 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
405 assert_response :not_found
407 # And finally we should be able to do it with the owner of the trace
408 session_for(anon_trace_file.user)
409 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
412 check_trace_data anon_trace_file, "db4cb5ed2d7d2b627b3b504296c4f701"
415 # Test downloading a trace that doesn't exist
416 def test_data_not_found
417 deleted_trace_file = create(:trace, :deleted)
419 # First with a trace that has never existed
420 get trace_data_path(:display_name => create(:user).display_name, :id => 0)
421 assert_response :not_found
423 # Now with a trace that has been deleted
424 session_for(deleted_trace_file.user)
425 get trace_data_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
426 assert_response :not_found
429 # Test downloading the picture for a trace
431 public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
433 # First with no auth, which should work since the trace is public
434 get trace_picture_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
435 check_trace_picture public_trace_file
437 # Now with some other user, which should work since the trace is public
438 session_for(create(:user))
439 get trace_picture_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
440 check_trace_picture public_trace_file
442 # And finally we should be able to do it with the owner of the trace
443 session_for(public_trace_file.user)
444 get trace_picture_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
445 check_trace_picture public_trace_file
448 # Check the picture for an anonymous trace can't be downloaded by another user
449 def test_picture_anon
450 anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
453 get trace_picture_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
454 assert_response :forbidden
456 # Now with some other user, which shouldn't work since the trace is anon
457 session_for(create(:user))
458 get trace_picture_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
459 assert_response :forbidden
461 # And finally we should be able to do it with the owner of the trace
462 session_for(anon_trace_file.user)
463 get trace_picture_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
464 check_trace_picture anon_trace_file
467 # Test downloading the picture for a trace that doesn't exist
468 def test_picture_not_found
469 deleted_trace_file = create(:trace, :deleted)
471 # First with a trace that has never existed
472 get trace_picture_path(:display_name => create(:user).display_name, :id => 0)
473 assert_response :not_found
475 # Now with a trace that has been deleted
476 session_for(deleted_trace_file.user)
477 get trace_picture_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
478 assert_response :not_found
481 # Test downloading the icon for a trace
483 public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
485 # First with no auth, which should work since the trace is public
486 get trace_icon_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
487 check_trace_icon public_trace_file
489 # Now with some other user, which should work since the trace is public
490 session_for(create(:user))
491 get trace_icon_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
492 check_trace_icon public_trace_file
494 # And finally we should be able to do it with the owner of the trace
495 session_for(public_trace_file.user)
496 get trace_icon_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
497 check_trace_icon public_trace_file
500 # Check the icon for an anonymous trace can't be downloaded by another user
502 anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
505 get trace_icon_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
506 assert_response :forbidden
508 # Now with some other user, which shouldn't work since the trace is anon
509 session_for(create(:user))
510 get trace_icon_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
511 assert_response :forbidden
513 # And finally we should be able to do it with the owner of the trace
514 session_for(anon_trace_file.user)
515 get trace_icon_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
516 check_trace_icon anon_trace_file
519 # Test downloading the icon for a trace that doesn't exist
520 def test_icon_not_found
521 deleted_trace_file = create(:trace, :deleted)
523 # First with a trace that has never existed
524 get trace_icon_path(:display_name => create(:user).display_name, :id => 0)
525 assert_response :not_found
527 # Now with a trace that has been deleted
528 session_for(deleted_trace_file.user)
529 get trace_icon_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
530 assert_response :not_found
533 # Test fetching the new trace page
537 assert_response :redirect
538 assert_redirected_to login_path(:referer => new_trace_path)
540 # Now authenticated as a user with gps.trace.visibility set
542 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
545 assert_response :success
547 assert_select "select#trace_visibility option[value=identifiable][selected]", 1
549 # Now authenticated as a user with gps.trace.public set
550 second_user = create(:user)
551 create(:user_preference, :user => second_user, :k => "gps.trace.public", :v => "default")
552 session_for(second_user)
554 assert_response :success
556 assert_select "select#trace_visibility option[value=public][selected]", 1
558 # Now authenticated as a user with no preferences
559 third_user = create(:user)
560 session_for(third_user)
562 assert_response :success
564 assert_select "select#trace_visibility option[value=private][selected]", 1
567 # Test creating a trace
570 fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
571 file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
575 post traces_path(:trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" })
576 assert_response :forbidden
582 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
583 assert_not_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v
585 post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }
586 assert_response :redirect
587 assert_redirected_to :action => :index, :display_name => user.display_name
588 assert_match(/file has been uploaded/, flash[:notice])
589 trace = Trace.order(:id => :desc).first
590 assert_equal "a.gpx", trace.name
591 assert_equal "New Trace", trace.description
592 assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
593 assert_equal "trackable", trace.visibility
594 assert_not trace.inserted
595 assert_equal File.new(fixture).read, trace.file.blob.download
597 assert_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v
600 # Test creating a trace with validation errors
601 def test_create_post_with_validation_errors
603 fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
604 file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
608 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
609 assert_not_equal "trackable", user.preferences.where(:k => "gps.trace.visibility").first.v
611 post traces_path, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }
613 assert_match "is too short (minimum is 1 character)", response.body
616 # Test fetching the edit page for a trace using GET
618 public_trace_file = create(:trace, :visibility => "public")
619 deleted_trace_file = create(:trace, :deleted)
622 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
623 assert_response :redirect
624 assert_redirected_to login_path(:referer => edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file.id))
626 # Now with some other user, which should fail
627 session_for(create(:user))
628 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
629 assert_response :forbidden
631 # Now with a trace which doesn't exist
632 session_for(create(:user))
633 get edit_trace_path(:display_name => create(:user).display_name, :id => 0)
634 assert_response :not_found
636 # Now with a trace which has been deleted
637 session_for(deleted_trace_file.user)
638 get edit_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
639 assert_response :not_found
641 # Finally with a trace that we are allowed to edit
642 session_for(public_trace_file.user)
643 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
644 assert_response :success
647 # Test saving edits to a trace
649 public_trace_file = create(:trace, :visibility => "public")
650 deleted_trace_file = create(:trace, :deleted)
653 new_details = { :description => "Changed description", :tagstring => "new_tag", :visibility => "private" }
656 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
657 assert_response :forbidden
659 # Now with some other user, which should fail
660 session_for(create(:user))
661 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
662 assert_response :forbidden
664 # Now with a trace which doesn't exist
665 session_for(create(:user))
666 put trace_path(:display_name => create(:user).display_name, :id => 0, :trace => new_details)
667 assert_response :not_found
669 # Now with a trace which has been deleted
670 session_for(deleted_trace_file.user)
671 put trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file, :trace => new_details)
672 assert_response :not_found
674 # Finally with a trace that we are allowed to edit
675 session_for(public_trace_file.user)
676 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
677 assert_response :redirect
678 assert_redirected_to :action => :show, :display_name => public_trace_file.user.display_name
679 trace = Trace.find(public_trace_file.id)
680 assert_equal new_details[:description], trace.description
681 assert_equal new_details[:tagstring], trace.tagstring
682 assert_equal new_details[:visibility], trace.visibility
685 # Test destroying a trace
687 public_trace_file = create(:trace, :visibility => "public")
688 deleted_trace_file = create(:trace, :deleted)
691 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
692 assert_response :forbidden
694 # Now with some other user, which should fail
695 session_for(create(:user))
696 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
697 assert_response :forbidden
699 # Now with a trace which doesn't exist
700 session_for(create(:user))
701 delete trace_path(:display_name => create(:user).display_name, :id => 0)
702 assert_response :not_found
704 # Now with a trace has already been deleted
705 session_for(deleted_trace_file.user)
706 delete trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
707 assert_response :not_found
709 # Now with a trace that we are allowed to delete
710 session_for(public_trace_file.user)
711 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
712 assert_response :redirect
713 assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
714 trace = Trace.find(public_trace_file.id)
715 assert_not trace.visible
717 # Finally with a trace that is destroyed by an admin
718 public_trace_file = create(:trace, :visibility => "public")
719 admin = create(:administrator_user)
721 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
722 assert_response :redirect
723 assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
724 trace = Trace.find(public_trace_file.id)
725 assert_not trace.visible
730 def check_trace_feed(traces)
731 assert_response :success
732 assert_template "georss"
733 assert_equal "application/rss+xml", @response.media_type
734 assert_select "rss", :count => 1 do
735 assert_select "channel", :count => 1 do
736 assert_select "title"
737 assert_select "description"
739 assert_select "image"
740 assert_select "item", :count => traces.length do |items|
741 traces.zip(items).each do |trace, item|
742 assert_select item, "title", trace.name
743 assert_select item, "link", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
744 assert_select item, "guid", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
745 assert_select item, "description"
746 # assert_select item, "dc:creator", trace.user.display_name
747 assert_select item, "pubDate", trace.timestamp.rfc822
754 def check_trace_index(traces)
755 assert_response :success
756 assert_template "index"
759 assert_select "h2", /Nothing here yet/
761 assert_select "table#trace_list tbody", :count => 1 do
762 assert_select "tr", :count => traces.length do |rows|
763 traces.zip(rows).each do |trace, row|
764 assert_select row, "a", Regexp.new(Regexp.escape(trace.name))
765 assert_select row, "li", Regexp.new(Regexp.escape("#{trace.size} points")) if trace.inserted?
766 assert_select row, "td", Regexp.new(Regexp.escape(trace.description))
767 assert_select row, "td", Regexp.new(Regexp.escape("by #{trace.user.display_name}"))
774 def check_trace_show(trace)
775 assert_response :success
776 assert_template "show"
778 assert_select "table", :count => 1 do
779 assert_select "td", /^#{Regexp.quote(trace.name)} /
780 assert_select "td", trace.user.display_name
781 assert_select "td", trace.description
785 def check_trace_data(trace, digest, content_type = "application/gpx+xml", extension = "gpx")
786 assert_equal digest, Digest::MD5.hexdigest(response.body)
787 assert_equal content_type, response.media_type
788 assert_equal "attachment; filename=\"#{trace.id}.#{extension}\"; filename*=UTF-8''#{trace.id}.#{extension}", @response.header["Content-Disposition"]
791 def check_trace_picture(trace)
794 assert_response :success
795 assert_equal "image/gif", response.media_type
796 assert_equal trace.large_picture, response.body
799 def check_trace_icon(trace)
802 assert_response :success
803 assert_equal "image/gif", response.media_type
804 assert_equal trace.icon_picture, response.body