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/tag/tagname", :method => :get },
13 { :controller => "traces", :action => "index", :tag => "tagname" }
16 { :path => "/user/username/traces", :method => :get },
17 { :controller => "traces", :action => "index", :display_name => "username" }
20 { :path => "/user/username/traces/tag/tagname", :method => :get },
21 { :controller => "traces", :action => "index", :display_name => "username", :tag => "tagname" }
25 { :path => "/traces/mine", :method => :get },
26 { :controller => "traces", :action => "mine" }
29 { :path => "/traces/mine/tag/tagname", :method => :get },
30 { :controller => "traces", :action => "mine", :tag => "tagname" }
34 { :path => "/traces/rss", :method => :get },
35 { :controller => "traces", :action => "georss", :format => :rss }
38 { :path => "/traces/tag/tagname/rss", :method => :get },
39 { :controller => "traces", :action => "georss", :tag => "tagname", :format => :rss }
42 { :path => "/user/username/traces/rss", :method => :get },
43 { :controller => "traces", :action => "georss", :display_name => "username", :format => :rss }
46 { :path => "/user/username/traces/tag/tagname/rss", :method => :get },
47 { :controller => "traces", :action => "georss", :display_name => "username", :tag => "tagname", :format => :rss }
51 { :path => "/user/username/traces/1", :method => :get },
52 { :controller => "traces", :action => "show", :display_name => "username", :id => "1" }
56 { :path => "/traces/new", :method => :get },
57 { :controller => "traces", :action => "new" }
60 { :path => "/traces", :method => :post },
61 { :controller => "traces", :action => "create" }
64 { :path => "/trace/1/data", :method => :get },
65 { :controller => "traces", :action => "data", :id => "1" }
68 { :path => "/trace/1/data.xml", :method => :get },
69 { :controller => "traces", :action => "data", :id => "1", :format => "xml" }
72 { :path => "/traces/1/edit", :method => :get },
73 { :controller => "traces", :action => "edit", :id => "1" }
76 { :path => "/traces/1", :method => :put },
77 { :controller => "traces", :action => "update", :id => "1" }
80 { :path => "/traces/1", :method => :delete },
81 { :controller => "traces", :action => "destroy", :id => "1" }
85 assert_redirected_to "/traces"
87 get "/traces/tag/tagname/page/1"
88 assert_redirected_to "/traces/tag/tagname"
90 get "/user/username/traces/page/1"
91 assert_redirected_to "/user/username/traces"
93 get "/user/username/traces/tag/tagname/page/1"
94 assert_redirected_to "/user/username/traces/tag/tagname"
96 get "/traces/mine/page/1"
97 assert_redirected_to "/traces/mine"
99 get "/traces/mine/tag/tagname/page/1"
100 assert_redirected_to "/traces/mine/tag/tagname"
103 # Check that the index of traces is displayed
106 # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
107 trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
108 create(:tracetag, :trace => trace, :tag => "London")
110 trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
111 create(:tracetag, :trace => trace, :tag => "Birmingham")
113 trace_c = create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
114 create(:tracetag, :trace => trace, :tag => "London")
116 trace_d = create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
117 create(:tracetag, :trace => trace, :tag => "Birmingham")
120 # First with the public index
122 check_trace_index [trace_b, trace_a]
124 # Restrict traces to those with a given tag
125 get traces_path(:tag => "London")
126 check_trace_index [trace_a]
130 # Should see more when we are logged in
132 check_trace_index [trace_d, trace_c, trace_b, trace_a]
134 # Again, we should see more when we are logged in
135 get traces_path(:tag => "London")
136 check_trace_index [trace_c, trace_a]
139 # Check that I can get mine
142 create(:trace, :visibility => "public") do |trace|
143 create(:tracetag, :trace => trace, :tag => "Birmingham")
145 trace_b = create(:trace, :visibility => "private", :user => user) do |trace|
146 create(:tracetag, :trace => trace, :tag => "London")
149 # First try to get it when not logged in
151 assert_redirected_to login_path(:referer => "/traces/mine")
155 # Now try when logged in
157 assert_redirected_to :action => "index", :display_name => user.display_name
159 # Fetch the actual index
160 get traces_path(:display_name => user.display_name)
161 check_trace_index [trace_b]
164 # Check the index of traces for a specific user
167 checked_user_traces_path = url_for :only_path => true, :controller => "traces", :action => "index", :display_name => user.display_name
168 second_user = create(:user)
169 third_user = create(:user)
171 trace_b = create(:trace, :visibility => "public", :user => user)
172 trace_c = create(:trace, :visibility => "private", :user => user) do |trace|
173 create(:tracetag, :trace => trace, :tag => "London")
176 # Test a user with no traces
177 get traces_path(:display_name => second_user.display_name)
180 # Test the user with the traces - should see only public ones
181 get traces_path(:display_name => user.display_name)
182 check_trace_index [trace_b]
183 assert_dom ".nav-tabs" do
184 assert_dom "a[href='#{traces_path}']", :text => "All Traces", :count => 1
185 assert_dom "a[href='#{traces_mine_path}']", :text => "My Traces", :count => 0
186 assert_dom "a[href='#{checked_user_traces_path}']", :text => Regexp.new(Regexp.escape(user.display_name)), :count => 1
189 session_for(third_user)
191 # Should still see only public ones when authenticated as another user
192 get traces_path(:display_name => user.display_name)
193 check_trace_index [trace_b]
194 assert_dom ".nav-tabs" do
195 assert_dom "a[href='#{traces_path}']", :text => "All Traces", :count => 1
196 assert_dom "a[href='#{traces_mine_path}']", :text => "My Traces", :count => 1
197 assert_dom "a[href='#{checked_user_traces_path}']", :text => Regexp.new(Regexp.escape(user.display_name)), :count => 1
202 # Should see all traces when authenticated as the target user
203 get traces_path(:display_name => user.display_name)
204 check_trace_index [trace_c, trace_b]
205 assert_dom ".nav-tabs" do
206 assert_dom "a[href='#{traces_path}']", :text => "All Traces", :count => 1
207 assert_dom "a[href='#{traces_mine_path}']", :text => "My Traces", :count => 1
208 assert_dom "a[href='#{checked_user_traces_path}']", :text => Regexp.new(Regexp.escape(user.display_name)), :count => 0
211 # Should only see traces with the correct tag when a tag is specified
212 get traces_path(:display_name => user.display_name, :tag => "London")
213 check_trace_index [trace_c]
215 # Should get an error if the user does not exist
216 get traces_path(:display_name => "UnknownUser")
217 assert_response :not_found
218 assert_template "users/no_such_user"
221 # Check a multi-page index
223 # Create several pages worth of traces
224 create_list(:trace, 50)
226 # Try and get the index
228 assert_response :success
229 assert_select "table#trace_list tbody", :count => 1 do
230 assert_select "tr", :count => 20
232 assert_select "li.page-item.disabled span.page-link", :text => "Newer Traces", :count => 2
233 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
235 # Try and get the second page
236 get css_select("li.page-item a.page-link").last["href"]
237 assert_response :success
238 assert_select "table#trace_list tbody", :count => 1 do
239 assert_select "tr", :count => 20
241 assert_select "li.page-item a.page-link", :text => "Newer Traces", :count => 2
242 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
244 # Try and get the third page
245 get css_select("li.page-item a.page-link").last["href"]
246 assert_response :success
247 assert_select "table#trace_list tbody", :count => 1 do
248 assert_select "tr", :count => 10
250 assert_select "li.page-item a.page-link", :text => "Newer Traces", :count => 2
251 assert_select "li.page-item.disabled span.page-link", :text => "Older Traces", :count => 2
253 # Go back to the second page
254 get css_select("li.page-item a.page-link").first["href"]
255 assert_response :success
256 assert_select "table#trace_list tbody", :count => 1 do
257 assert_select "tr", :count => 20
259 assert_select "li.page-item a.page-link", :text => "Newer Traces", :count => 2
260 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
262 # Go back to the first page
263 get css_select("li.page-item a.page-link").first["href"]
264 assert_response :success
265 assert_select "table#trace_list tbody", :count => 1 do
266 assert_select "tr", :count => 20
268 assert_select "li.page-item.disabled span.page-link", :text => "Newer Traces", :count => 2
269 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
272 # Check a multi-page index of tagged traces
273 def test_index_tagged_paged
274 # Create several pages worth of traces
275 create_list(:trace, 100) do |trace, index|
276 create(:tracetag, :trace => trace, :tag => "London") if index.even?
279 # Try and get the index
280 get traces_path(:tag => "London")
281 assert_response :success
282 assert_select "table#trace_list tbody", :count => 1 do
283 assert_select "tr", :count => 20
285 assert_select "li.page-item.disabled span.page-link", :text => "Newer Traces", :count => 2
286 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
288 # Try and get the second page
289 get css_select("li.page-item a.page-link").last["href"]
290 assert_response :success
291 assert_select "table#trace_list tbody", :count => 1 do
292 assert_select "tr", :count => 20
294 assert_select "li.page-item a.page-link", :text => "Newer Traces", :count => 2
295 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
297 # Try and get the third page
298 get css_select("li.page-item a.page-link").last["href"]
299 assert_response :success
300 assert_select "table#trace_list tbody", :count => 1 do
301 assert_select "tr", :count => 10
303 assert_select "li.page-item a.page-link", :text => "Newer Traces", :count => 2
304 assert_select "li.page-item.disabled span.page-link", :text => "Older Traces", :count => 2
306 # Go back to the second page
307 get css_select("li.page-item a.page-link").first["href"]
308 assert_response :success
309 assert_select "table#trace_list tbody", :count => 1 do
310 assert_select "tr", :count => 20
312 assert_select "li.page-item a.page-link", :text => "Newer Traces", :count => 2
313 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
315 # Go back to the first page
316 get css_select("li.page-item a.page-link").first["href"]
317 assert_response :success
318 assert_select "table#trace_list tbody", :count => 1 do
319 assert_select "tr", :count => 20
321 assert_select "li.page-item.disabled span.page-link", :text => "Newer Traces", :count => 2
322 assert_select "li.page-item a.page-link", :text => "Older Traces", :count => 2
325 def test_index_invalid_paged
326 # Try some invalid paged accesses
327 %w[-1 0 fred].each do |id|
328 get traces_path(:before => id)
329 assert_redirected_to :controller => :errors, :action => :bad_request
331 get traces_path(:after => id)
332 assert_redirected_to :controller => :errors, :action => :bad_request
339 # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
340 trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
341 create(:tracetag, :trace => trace, :tag => "London")
343 trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
344 create(:tracetag, :trace => trace, :tag => "Birmingham")
346 create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
347 create(:tracetag, :trace => trace, :tag => "London")
349 create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
350 create(:tracetag, :trace => trace, :tag => "Birmingham")
353 # First with the public feed
355 check_trace_feed [trace_b, trace_a]
357 # Restrict traces to those with a given tag
358 get traces_rss_path(:tag => "London")
359 check_trace_feed [trace_a]
362 # Check the RSS feed for a specific user
365 second_user = create(:user)
368 trace_b = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago, :user => user)
369 trace_c = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago, :user => user) do |trace|
370 create(:tracetag, :trace => trace, :tag => "London")
372 create(:trace, :visibility => "private")
374 # Test a user with no traces
375 get traces_rss_path(:display_name => second_user.display_name)
378 # Test the user with the traces - should see only public ones
379 get traces_rss_path(:display_name => user.display_name)
380 check_trace_feed [trace_c, trace_b]
382 # Should only see traces with the correct tag when a tag is specified
383 get traces_rss_path(:display_name => user.display_name, :tag => "London")
384 check_trace_feed [trace_c]
386 # Should no traces if the user does not exist
387 get traces_rss_path(:display_name => "UnknownUser")
391 # Test showing a trace
393 public_trace_file = create(:trace, :visibility => "public")
395 # First with no auth, which should work since the trace is public
396 get show_trace_path(public_trace_file.user, public_trace_file)
397 check_trace_show public_trace_file
399 # Now with some other user, which should work since the trace is public
400 session_for(create(:user))
401 get show_trace_path(public_trace_file.user, public_trace_file)
402 check_trace_show public_trace_file
404 # And finally we should be able to do it with the owner of the trace
405 session_for(public_trace_file.user)
406 get show_trace_path(public_trace_file.user, public_trace_file)
407 check_trace_show public_trace_file
410 # Check an anonymous trace can't be viewed by another user
412 anon_trace_file = create(:trace, :visibility => "private")
415 get show_trace_path(anon_trace_file.user, anon_trace_file)
416 assert_redirected_to :action => :index
418 # Now with some other user, which should not work since the trace is anon
419 session_for(create(:user))
420 get show_trace_path(anon_trace_file.user, anon_trace_file)
421 assert_redirected_to :action => :index
423 # And finally we should be able to do it with the owner of the trace
424 session_for(anon_trace_file.user)
425 get show_trace_path(anon_trace_file.user, anon_trace_file)
426 check_trace_show anon_trace_file
429 # Test showing a trace that doesn't exist
430 def test_show_not_found
431 deleted_trace_file = create(:trace, :deleted)
433 # First with a trace that has never existed
434 get show_trace_path(create(:user), 0)
435 assert_redirected_to :action => :index
437 # Now with a trace that has been deleted
438 session_for(deleted_trace_file.user)
439 get show_trace_path(deleted_trace_file.user, deleted_trace_file)
440 assert_redirected_to :action => :index
443 # Test downloading a trace
445 public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
447 # First with no auth, which should work since the trace is public
448 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
451 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
453 # Now with some other user, which should work since the trace is public
454 session_for(create(:user))
455 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
458 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
460 # And finally we should be able to do it with the owner of the trace
461 session_for(public_trace_file.user)
462 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
465 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
468 # Test downloading a compressed trace
469 def test_data_compressed
470 identifiable_trace_file = create(:trace, :visibility => "identifiable", :fixture => "d")
472 # First get the data as is
473 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file)
476 check_trace_data identifiable_trace_file, "c6422a3d8750faae49ed70e7e8a51b93", "application/gzip", "gpx.gz"
478 # Now ask explicitly for XML format
479 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "xml")
480 check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d", "application/xml", "xml"
482 # Now ask explicitly for GPX format
483 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "gpx")
484 check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d"
487 # Check an anonymous trace can't be downloaded by another user
489 anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
492 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
493 assert_response :not_found
495 # Now with some other user, which shouldn't work since the trace is anon
496 session_for(create(:user))
497 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
498 assert_response :not_found
500 # And finally we should be able to do it with the owner of the trace
501 session_for(anon_trace_file.user)
502 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
505 check_trace_data anon_trace_file, "db4cb5ed2d7d2b627b3b504296c4f701"
508 # Test downloading a trace that doesn't exist
509 def test_data_not_found
510 deleted_trace_file = create(:trace, :deleted)
512 # First with a trace that has never existed
513 get trace_data_path(:display_name => create(:user).display_name, :id => 0)
514 assert_response :not_found
516 # Now with a trace that has been deleted
517 session_for(deleted_trace_file.user)
518 get trace_data_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
519 assert_response :not_found
522 # Test fetching the new trace page
526 assert_redirected_to login_path(:referer => new_trace_path)
528 # Now authenticated as a user with gps.trace.visibility set
530 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
533 assert_response :success
535 assert_select "select#trace_visibility option[value=identifiable][selected]", 1
537 # Now authenticated as a user with gps.trace.public set
538 second_user = create(:user)
539 create(:user_preference, :user => second_user, :k => "gps.trace.public", :v => "default")
540 session_for(second_user)
542 assert_response :success
544 assert_select "select#trace_visibility option[value=public][selected]", 1
546 # Now authenticated as a user with no preferences
547 third_user = create(:user)
548 session_for(third_user)
550 assert_response :success
552 assert_select "select#trace_visibility option[value=private][selected]", 1
555 # Test creating a trace
558 fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
559 file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
563 post traces_path(:trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" })
564 assert_response :forbidden
570 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
571 assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
573 post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }
574 assert_redirected_to :action => :index, :display_name => user.display_name
575 assert_match(/file has been uploaded/, flash[:notice])
576 trace = Trace.order(:id => :desc).first
577 assert_equal "a.gpx", trace.name
578 assert_equal "New Trace", trace.description
579 assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
580 assert_equal "trackable", trace.visibility
581 assert_not trace.inserted
582 assert_equal File.new(fixture).read, trace.file.blob.download
584 assert_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
587 # Test creating a trace with validation errors
588 def test_create_post_with_validation_errors
590 fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
591 file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
595 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
596 assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
598 post traces_path, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }
600 assert_match "is too short (minimum is 1 character)", response.body
603 # Test fetching the edit page for a trace using GET
605 public_trace_file = create(:trace, :visibility => "public")
606 deleted_trace_file = create(:trace, :deleted)
609 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
610 assert_redirected_to login_path(:referer => edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file.id))
612 # Now with some other user, which should fail
613 session_for(create(:user))
614 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
615 assert_response :forbidden
617 # Now with a trace which doesn't exist
618 session_for(create(:user))
619 get edit_trace_path(:display_name => create(:user).display_name, :id => 0)
620 assert_response :not_found
622 # Now with a trace which has been deleted
623 session_for(deleted_trace_file.user)
624 get edit_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
625 assert_response :not_found
627 # Finally with a trace that we are allowed to edit
628 session_for(public_trace_file.user)
629 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
630 assert_response :success
633 # Test saving edits to a trace
635 public_trace_file = create(:trace, :visibility => "public")
636 deleted_trace_file = create(:trace, :deleted)
639 new_details = { :description => "Changed description", :tagstring => "new_tag", :visibility => "private" }
642 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
643 assert_response :forbidden
645 # Now with some other user, which should fail
646 session_for(create(:user))
647 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
648 assert_response :forbidden
650 # Now with a trace which doesn't exist
651 session_for(create(:user))
652 put trace_path(:display_name => create(:user).display_name, :id => 0, :trace => new_details)
653 assert_response :not_found
655 # Now with a trace which has been deleted
656 session_for(deleted_trace_file.user)
657 put trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file, :trace => new_details)
658 assert_response :not_found
660 # Finally with a trace that we are allowed to edit
661 session_for(public_trace_file.user)
662 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
663 assert_redirected_to :action => :show, :display_name => public_trace_file.user.display_name
664 trace = Trace.find(public_trace_file.id)
665 assert_equal new_details[:description], trace.description
666 assert_equal new_details[:tagstring], trace.tagstring
667 assert_equal new_details[:visibility], trace.visibility
670 # Test destroying a trace
672 public_trace_file = create(:trace, :visibility => "public")
673 deleted_trace_file = create(:trace, :deleted)
676 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
677 assert_response :forbidden
679 # Now with some other user, which should fail
680 session_for(create(:user))
681 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
682 assert_response :forbidden
684 # Now with a trace which doesn't exist
685 session_for(create(:user))
686 delete trace_path(:display_name => create(:user).display_name, :id => 0)
687 assert_response :not_found
689 # Now with a trace has already been deleted
690 session_for(deleted_trace_file.user)
691 delete trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
692 assert_response :not_found
694 # Now with a trace that we are allowed to delete
695 session_for(public_trace_file.user)
696 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
697 assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
698 trace = Trace.find(public_trace_file.id)
699 assert_not trace.visible
701 # Finally with a trace that is destroyed by an admin
702 public_trace_file = create(:trace, :visibility => "public")
703 admin = create(:administrator_user)
705 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
706 assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
707 trace = Trace.find(public_trace_file.id)
708 assert_not trace.visible
713 def check_trace_feed(traces)
714 assert_response :success
715 assert_template "georss"
716 assert_equal "application/rss+xml", @response.media_type
717 assert_select "rss", :count => 1 do
718 assert_select "channel", :count => 1 do
719 assert_select "title"
720 assert_select "description"
722 assert_select "image"
723 assert_select "item", :count => traces.length do |items|
724 traces.zip(items).each do |trace, item|
725 assert_select item, "title", trace.name
726 assert_select item, "link", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
727 assert_select item, "guid", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
728 assert_select item, "description" do
729 assert_dom_encoded do
730 assert_select "img[src='#{trace_icon_url trace.user, trace}']"
733 # assert_select item, "dc:creator", trace.user.display_name
734 assert_select item, "pubDate", trace.timestamp.rfc822
741 def check_trace_index(traces)
742 assert_response :success
743 assert_template "index"
746 assert_select "h2", /Nothing here yet/
748 assert_select "table#trace_list tbody", :count => 1 do
749 assert_select "tr", :count => traces.length do |rows|
750 traces.zip(rows).each do |trace, row|
751 assert_select row, "a", Regexp.new(Regexp.escape(trace.name))
752 assert_select row, "li", Regexp.new(Regexp.escape("#{trace.size} points")) if trace.inserted?
753 assert_select row, "td", Regexp.new(Regexp.escape(trace.description))
754 assert_select row, "td", Regexp.new(Regexp.escape("by #{trace.user.display_name}"))
755 assert_select row, "a[href='#{user_path trace.user}']", :text => trace.user.display_name
762 def check_trace_show(trace)
763 assert_response :success
764 assert_template "show"
766 assert_select "table", :count => 1 do
767 assert_select "td", /^#{Regexp.quote(trace.name)} /
768 assert_select "td a[href='#{user_path trace.user}']", :text => trace.user.display_name
769 assert_select "td", trace.description
773 def check_trace_data(trace, digest, content_type = "application/gpx+xml", extension = "gpx")
774 assert_equal digest, Digest::MD5.hexdigest(response.body)
775 assert_equal content_type, response.media_type
776 assert_equal "attachment; filename=\"#{trace.id}.#{extension}\"; filename*=UTF-8''#{trace.id}.#{extension}", @response.header["Content-Disposition"]