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
328 # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
329 trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
330 create(:tracetag, :trace => trace, :tag => "London")
332 trace_b = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago) do |trace|
333 create(:tracetag, :trace => trace, :tag => "Birmingham")
335 create(:trace, :visibility => "private", :user => user, :timestamp => 2.seconds.ago) do |trace|
336 create(:tracetag, :trace => trace, :tag => "London")
338 create(:trace, :visibility => "private", :user => user, :timestamp => 1.second.ago) do |trace|
339 create(:tracetag, :trace => trace, :tag => "Birmingham")
342 # First with the public feed
344 check_trace_feed [trace_b, trace_a]
346 # Restrict traces to those with a given tag
347 get traces_rss_path(:tag => "London")
348 check_trace_feed [trace_a]
351 # Check the RSS feed for a specific user
354 second_user = create(:user)
357 trace_b = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago, :user => user)
358 trace_c = create(:trace, :visibility => "public", :timestamp => 3.seconds.ago, :user => user) do |trace|
359 create(:tracetag, :trace => trace, :tag => "London")
361 create(:trace, :visibility => "private")
363 # Test a user with no traces
364 get traces_rss_path(:display_name => second_user.display_name)
367 # Test the user with the traces - should see only public ones
368 get traces_rss_path(:display_name => user.display_name)
369 check_trace_feed [trace_c, trace_b]
371 # Should only see traces with the correct tag when a tag is specified
372 get traces_rss_path(:display_name => user.display_name, :tag => "London")
373 check_trace_feed [trace_c]
375 # Should no traces if the user does not exist
376 get traces_rss_path(:display_name => "UnknownUser")
380 # Test showing a trace
382 public_trace_file = create(:trace, :visibility => "public")
384 # First with no auth, which should work since the trace is public
385 get show_trace_path(public_trace_file.user, public_trace_file)
386 check_trace_show public_trace_file
388 # Now with some other user, which should work since the trace is public
389 session_for(create(:user))
390 get show_trace_path(public_trace_file.user, public_trace_file)
391 check_trace_show public_trace_file
393 # And finally we should be able to do it with the owner of the trace
394 session_for(public_trace_file.user)
395 get show_trace_path(public_trace_file.user, public_trace_file)
396 check_trace_show public_trace_file
399 # Check an anonymous trace can't be viewed by another user
401 anon_trace_file = create(:trace, :visibility => "private")
404 get show_trace_path(anon_trace_file.user, anon_trace_file)
405 assert_redirected_to :action => :index
407 # Now with some other user, which should not work since the trace is anon
408 session_for(create(:user))
409 get show_trace_path(anon_trace_file.user, anon_trace_file)
410 assert_redirected_to :action => :index
412 # And finally we should be able to do it with the owner of the trace
413 session_for(anon_trace_file.user)
414 get show_trace_path(anon_trace_file.user, anon_trace_file)
415 check_trace_show anon_trace_file
418 # Test showing a trace that doesn't exist
419 def test_show_not_found
420 deleted_trace_file = create(:trace, :deleted)
422 # First with a trace that has never existed
423 get show_trace_path(create(:user), 0)
424 assert_redirected_to :action => :index
426 # Now with a trace that has been deleted
427 session_for(deleted_trace_file.user)
428 get show_trace_path(deleted_trace_file.user, deleted_trace_file)
429 assert_redirected_to :action => :index
432 # Test downloading a trace
434 public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
436 # First with no auth, which should work since the trace is public
437 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
440 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
442 # Now with some other user, which should work since the trace is public
443 session_for(create(:user))
444 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
447 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
449 # And finally we should be able to do it with the owner of the trace
450 session_for(public_trace_file.user)
451 get trace_data_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
454 check_trace_data public_trace_file, "848caa72f2f456d1bd6a0fdf228aa1b9"
457 # Test downloading a compressed trace
458 def test_data_compressed
459 identifiable_trace_file = create(:trace, :visibility => "identifiable", :fixture => "d")
461 # First get the data as is
462 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file)
465 check_trace_data identifiable_trace_file, "c6422a3d8750faae49ed70e7e8a51b93", "application/gzip", "gpx.gz"
467 # Now ask explicitly for XML format
468 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "xml")
469 check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d", "application/xml", "xml"
471 # Now ask explicitly for GPX format
472 get trace_data_path(:display_name => identifiable_trace_file.user.display_name, :id => identifiable_trace_file.id, :format => "gpx")
473 check_trace_data identifiable_trace_file, "abd6675fdf3024a84fc0a1deac147c0d"
476 # Check an anonymous trace can't be downloaded by another user
478 anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
481 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
482 assert_response :not_found
484 # Now with some other user, which shouldn't work since the trace is anon
485 session_for(create(:user))
486 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
487 assert_response :not_found
489 # And finally we should be able to do it with the owner of the trace
490 session_for(anon_trace_file.user)
491 get trace_data_path(:display_name => anon_trace_file.user.display_name, :id => anon_trace_file)
494 check_trace_data anon_trace_file, "db4cb5ed2d7d2b627b3b504296c4f701"
497 # Test downloading a trace that doesn't exist
498 def test_data_not_found
499 deleted_trace_file = create(:trace, :deleted)
501 # First with a trace that has never existed
502 get trace_data_path(:display_name => create(:user).display_name, :id => 0)
503 assert_response :not_found
505 # Now with a trace that has been deleted
506 session_for(deleted_trace_file.user)
507 get trace_data_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
508 assert_response :not_found
511 # Test fetching the new trace page
515 assert_redirected_to login_path(:referer => new_trace_path)
517 # Now authenticated as a user with gps.trace.visibility set
519 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
522 assert_response :success
524 assert_select "select#trace_visibility option[value=identifiable][selected]", 1
526 # Now authenticated as a user with gps.trace.public set
527 second_user = create(:user)
528 create(:user_preference, :user => second_user, :k => "gps.trace.public", :v => "default")
529 session_for(second_user)
531 assert_response :success
533 assert_select "select#trace_visibility option[value=public][selected]", 1
535 # Now authenticated as a user with no preferences
536 third_user = create(:user)
537 session_for(third_user)
539 assert_response :success
541 assert_select "select#trace_visibility option[value=private][selected]", 1
544 # Test creating a trace
547 fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
548 file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
552 post traces_path(:trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" })
553 assert_response :forbidden
559 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
560 assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
562 post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }
563 assert_redirected_to :action => :index, :display_name => user.display_name
564 assert_match(/file has been uploaded/, flash[:notice])
565 trace = Trace.order(:id => :desc).first
566 assert_equal "a.gpx", trace.name
567 assert_equal "New Trace", trace.description
568 assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
569 assert_equal "trackable", trace.visibility
570 assert_not trace.inserted
571 assert_equal File.new(fixture).read, trace.file.blob.download
573 assert_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
576 # Test creating a trace with validation errors
577 def test_create_post_with_validation_errors
579 fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
580 file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
584 create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
585 assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
587 post traces_path, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }
589 assert_match "is too short (minimum is 1 character)", response.body
592 # Test fetching the edit page for a trace using GET
594 public_trace_file = create(:trace, :visibility => "public")
595 deleted_trace_file = create(:trace, :deleted)
598 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
599 assert_redirected_to login_path(:referer => edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file.id))
601 # Now with some other user, which should fail
602 session_for(create(:user))
603 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
604 assert_response :forbidden
606 # Now with a trace which doesn't exist
607 session_for(create(:user))
608 get edit_trace_path(:display_name => create(:user).display_name, :id => 0)
609 assert_response :not_found
611 # Now with a trace which has been deleted
612 session_for(deleted_trace_file.user)
613 get edit_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
614 assert_response :not_found
616 # Finally with a trace that we are allowed to edit
617 session_for(public_trace_file.user)
618 get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
619 assert_response :success
622 # Test saving edits to a trace
624 public_trace_file = create(:trace, :visibility => "public")
625 deleted_trace_file = create(:trace, :deleted)
628 new_details = { :description => "Changed description", :tagstring => "new_tag", :visibility => "private" }
631 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
632 assert_response :forbidden
634 # Now with some other user, which should fail
635 session_for(create(:user))
636 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
637 assert_response :forbidden
639 # Now with a trace which doesn't exist
640 session_for(create(:user))
641 put trace_path(:display_name => create(:user).display_name, :id => 0, :trace => new_details)
642 assert_response :not_found
644 # Now with a trace which has been deleted
645 session_for(deleted_trace_file.user)
646 put trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file, :trace => new_details)
647 assert_response :not_found
649 # Finally with a trace that we are allowed to edit
650 session_for(public_trace_file.user)
651 put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
652 assert_redirected_to :action => :show, :display_name => public_trace_file.user.display_name
653 trace = Trace.find(public_trace_file.id)
654 assert_equal new_details[:description], trace.description
655 assert_equal new_details[:tagstring], trace.tagstring
656 assert_equal new_details[:visibility], trace.visibility
659 # Test destroying a trace
661 public_trace_file = create(:trace, :visibility => "public")
662 deleted_trace_file = create(:trace, :deleted)
665 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
666 assert_response :forbidden
668 # Now with some other user, which should fail
669 session_for(create(:user))
670 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
671 assert_response :forbidden
673 # Now with a trace which doesn't exist
674 session_for(create(:user))
675 delete trace_path(:display_name => create(:user).display_name, :id => 0)
676 assert_response :not_found
678 # Now with a trace has already been deleted
679 session_for(deleted_trace_file.user)
680 delete trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
681 assert_response :not_found
683 # Now with a trace that we are allowed to delete
684 session_for(public_trace_file.user)
685 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
686 assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
687 trace = Trace.find(public_trace_file.id)
688 assert_not trace.visible
690 # Finally with a trace that is destroyed by an admin
691 public_trace_file = create(:trace, :visibility => "public")
692 admin = create(:administrator_user)
694 delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
695 assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
696 trace = Trace.find(public_trace_file.id)
697 assert_not trace.visible
702 def check_trace_feed(traces)
703 assert_response :success
704 assert_template "georss"
705 assert_equal "application/rss+xml", @response.media_type
706 assert_select "rss", :count => 1 do
707 assert_select "channel", :count => 1 do
708 assert_select "title"
709 assert_select "description"
711 assert_select "image"
712 assert_select "item", :count => traces.length do |items|
713 traces.zip(items).each do |trace, item|
714 assert_select item, "title", trace.name
715 assert_select item, "link", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
716 assert_select item, "guid", "http://www.example.com/user/#{ERB::Util.u(trace.user.display_name)}/traces/#{trace.id}"
717 assert_select item, "description" do
718 assert_dom_encoded do
719 assert_select "img[src='#{trace_icon_url trace.user, trace}']"
722 # assert_select item, "dc:creator", trace.user.display_name
723 assert_select item, "pubDate", trace.timestamp.rfc822
730 def check_trace_index(traces)
731 assert_response :success
732 assert_template "index"
735 assert_select "h2", /Nothing here yet/
737 assert_select "table#trace_list tbody", :count => 1 do
738 assert_select "tr", :count => traces.length do |rows|
739 traces.zip(rows).each do |trace, row|
740 assert_select row, "a", Regexp.new(Regexp.escape(trace.name))
741 assert_select row, "li", Regexp.new(Regexp.escape("#{trace.size} points")) if trace.inserted?
742 assert_select row, "td", Regexp.new(Regexp.escape(trace.description))
743 assert_select row, "td", Regexp.new(Regexp.escape("by #{trace.user.display_name}"))
744 assert_select row, "a[href='#{user_path trace.user}']", :text => trace.user.display_name
751 def check_trace_show(trace)
752 assert_response :success
753 assert_template "show"
755 assert_select "table", :count => 1 do
756 assert_select "td", /^#{Regexp.quote(trace.name)} /
757 assert_select "td a[href='#{user_path trace.user}']", :text => trace.user.display_name
758 assert_select "td", trace.description
762 def check_trace_data(trace, digest, content_type = "application/gpx+xml", extension = "gpx")
763 assert_equal digest, Digest::MD5.hexdigest(response.body)
764 assert_equal content_type, response.media_type
765 assert_equal "attachment; filename=\"#{trace.id}.#{extension}\"; filename*=UTF-8''#{trace.id}.#{extension}", @response.header["Content-Disposition"]