]> git.openstreetmap.org Git - rails.git/blob - test/controllers/traces_controller_test.rb
Merge remote-tracking branch 'upstream/pull/7650'
[rails.git] / test / controllers / traces_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class TracesControllerTest < ActionDispatch::IntegrationTest
6   ##
7   # test all routes which lead to this controller
8   def test_routes
9     assert_routing(
10       { :path => "/traces", :method => :get },
11       { :controller => "traces", :action => "index" }
12     )
13     assert_routing(
14       { :path => "/traces/tag/tagname", :method => :get },
15       { :controller => "traces", :action => "index", :tag => "tagname" }
16     )
17     assert_routing(
18       { :path => "/user/username/traces", :method => :get },
19       { :controller => "traces", :action => "index", :display_name => "username" }
20     )
21     assert_routing(
22       { :path => "/user/username/traces/tag/tagname", :method => :get },
23       { :controller => "traces", :action => "index", :display_name => "username", :tag => "tagname" }
24     )
25
26     assert_routing(
27       { :path => "/traces/mine", :method => :get },
28       { :controller => "traces", :action => "mine" }
29     )
30     assert_routing(
31       { :path => "/traces/mine/tag/tagname", :method => :get },
32       { :controller => "traces", :action => "mine", :tag => "tagname" }
33     )
34
35     assert_routing(
36       { :path => "/user/username/traces/1", :method => :get },
37       { :controller => "traces", :action => "show", :display_name => "username", :id => "1" }
38     )
39
40     assert_routing(
41       { :path => "/traces/new", :method => :get },
42       { :controller => "traces", :action => "new" }
43     )
44     assert_routing(
45       { :path => "/traces", :method => :post },
46       { :controller => "traces", :action => "create" }
47     )
48     assert_routing(
49       { :path => "/traces/1/edit", :method => :get },
50       { :controller => "traces", :action => "edit", :id => "1" }
51     )
52     assert_routing(
53       { :path => "/traces/1", :method => :put },
54       { :controller => "traces", :action => "update", :id => "1" }
55     )
56     assert_routing(
57       { :path => "/traces/1", :method => :delete },
58       { :controller => "traces", :action => "destroy", :id => "1" }
59     )
60
61     get "/traces/page/1"
62     assert_redirected_to "/traces"
63
64     get "/traces/tag/tagname/page/1"
65     assert_redirected_to "/traces/tag/tagname"
66
67     get "/user/username/traces/page/1"
68     assert_redirected_to "/user/username/traces"
69
70     get "/user/username/traces/tag/tagname/page/1"
71     assert_redirected_to "/user/username/traces/tag/tagname"
72
73     get "/traces/mine/page/1"
74     assert_redirected_to "/traces/mine"
75
76     get "/traces/mine/tag/tagname/page/1"
77     assert_redirected_to "/traces/mine/tag/tagname"
78   end
79
80   # Check that the index of traces is displayed
81   def test_index
82     user = create(:user)
83     # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
84     trace_a = create(:trace, :visibility => "identifiable", :timestamp => 4.seconds.ago) do |trace|
85       create(:tracetag, :trace => trace, :tag => "London")
86     end
87     trace_b = create(:trace, :visibility => "identifiable", :timestamp => 3.seconds.ago) do |trace|
88       create(:tracetag, :trace => trace, :tag => "Birmingham")
89     end
90     trace_c = create(:trace, :visibility => "trackable", :user => user, :timestamp => 2.seconds.ago) do |trace|
91       create(:tracetag, :trace => trace, :tag => "London")
92     end
93     trace_d = create(:trace, :visibility => "trackable", :user => user, :timestamp => 1.second.ago) do |trace|
94       create(:tracetag, :trace => trace, :tag => "Birmingham")
95     end
96
97     # First with the public index
98     get traces_path
99     check_trace_index [trace_b, trace_a]
100
101     # Restrict traces to those with a given tag
102     get traces_path(:tag => "London")
103     check_trace_index [trace_a]
104
105     session_for(user)
106
107     # Should see more when we are logged in
108     get traces_path
109     check_trace_index [trace_d, trace_c, trace_b, trace_a]
110
111     # Again, we should see more when we are logged in
112     get traces_path(:tag => "London")
113     check_trace_index [trace_c, trace_a]
114   end
115
116   # Check that I can get mine
117   def test_index_mine
118     user = create(:user)
119     create(:trace, :visibility => "identifiable") do |trace|
120       create(:tracetag, :trace => trace, :tag => "Birmingham")
121     end
122     trace_b = create(:trace, :visibility => "trackable", :user => user) do |trace|
123       create(:tracetag, :trace => trace, :tag => "London")
124     end
125
126     # First try to get it when not logged in
127     get traces_mine_path
128     assert_redirected_to login_path(:referer => "/traces/mine")
129
130     session_for(user)
131
132     # Now try when logged in
133     get traces_mine_path
134     assert_redirected_to :action => "index", :display_name => user.display_name
135
136     # Fetch the actual index
137     get traces_path(:display_name => user.display_name)
138     check_trace_index [trace_b]
139   end
140
141   # The link to the legacy visibility page only shows up while the user
142   # still has traces using a legacy visibility
143   def test_index_legacy_traces_link
144     user = create(:user)
145     create(:trace, :visibility => "trackable", :user => user)
146     session_for(user)
147
148     get traces_path
149     assert_response :success
150     assert_select "a[href=?]", edit_traces_legacy_visibility_path, :count => 0
151
152     create(:trace, :without_validations, :visibility => "public", :user => user)
153
154     get traces_path
155     assert_response :success
156     assert_select "a[href=?]", edit_traces_legacy_visibility_path, :count => 1
157   end
158
159   # Check the index of traces for a specific user
160   def test_index_user
161     user = create(:user)
162     checked_user_traces_path = url_for :only_path => true, :controller => "traces", :action => "index", :display_name => user.display_name
163     second_user = create(:user)
164     third_user = create(:user)
165     create(:trace)
166     trace_b = create(:trace, :visibility => "identifiable", :user => user)
167     trace_c = create(:trace, :visibility => "trackable", :user => user) do |trace|
168       create(:tracetag, :trace => trace, :tag => "London")
169     end
170
171     # Test a user with no traces
172     get traces_path(:display_name => second_user.display_name)
173     check_trace_index []
174
175     # Test the user with the traces - should see only public ones
176     get traces_path(:display_name => user.display_name)
177     check_trace_index [trace_b]
178     assert_dom ".nav-tabs" do
179       assert_dom "a[href='#{traces_path}']", :text => "All Traces", :count => 1
180       assert_dom "a[href='#{traces_mine_path}']", :text => "My Traces", :count => 0
181       assert_dom "a[href='#{checked_user_traces_path}']", :text => Regexp.new(Regexp.escape(user.display_name)), :count => 1
182     end
183
184     session_for(third_user)
185
186     # Should still see only public ones when authenticated as another user
187     get traces_path(:display_name => user.display_name)
188     check_trace_index [trace_b]
189     assert_dom ".nav-tabs" do
190       assert_dom "a[href='#{traces_path}']", :text => "All Traces", :count => 1
191       assert_dom "a[href='#{traces_mine_path}']", :text => "My Traces", :count => 1
192       assert_dom "a[href='#{checked_user_traces_path}']", :text => Regexp.new(Regexp.escape(user.display_name)), :count => 1
193     end
194
195     session_for(user)
196
197     # Should see all traces when authenticated as the target user
198     get traces_path(:display_name => user.display_name)
199     check_trace_index [trace_c, trace_b]
200     assert_dom ".nav-tabs" do
201       assert_dom "a[href='#{traces_path}']", :text => "All Traces", :count => 1
202       assert_dom "a[href='#{traces_mine_path}']", :text => "My Traces", :count => 1
203       assert_dom "a[href='#{checked_user_traces_path}']", :text => Regexp.new(Regexp.escape(user.display_name)), :count => 0
204     end
205
206     # Should only see traces with the correct tag when a tag is specified
207     get traces_path(:display_name => user.display_name, :tag => "London")
208     check_trace_index [trace_c]
209
210     # Should get an error if the user does not exist
211     get traces_path(:display_name => "UnknownUser")
212     assert_response :not_found
213     assert_template "users/no_such_user"
214   end
215
216   # Check a multi-page index
217   def test_index_paged
218     # Create several pages worth of traces
219     create_list(:trace, 50, :visibility => "identifiable")
220     next_path = traces_path
221
222     # Try and get the index
223     get next_path
224     assert_response :success
225     assert_select "table#trace_list tbody", :count => 1 do
226       assert_select "tr", :count => 20
227     end
228     check_no_page_link "Newer Traces"
229     next_path = check_page_link "Older Traces"
230
231     # Try and get the second page
232     get next_path
233     assert_response :success
234     assert_select "table#trace_list tbody", :count => 1 do
235       assert_select "tr", :count => 20
236     end
237     check_page_link "Newer Traces"
238     next_path = check_page_link "Older Traces"
239
240     # Try and get the third page
241     get next_path
242     assert_response :success
243     assert_select "table#trace_list tbody", :count => 1 do
244       assert_select "tr", :count => 10
245     end
246     next_path = check_page_link "Newer Traces"
247     check_no_page_link "Older Traces"
248
249     # Go back to the second page
250     get next_path
251     assert_response :success
252     assert_select "table#trace_list tbody", :count => 1 do
253       assert_select "tr", :count => 20
254     end
255     next_path = check_page_link "Newer Traces"
256     check_page_link "Older Traces"
257
258     # Go back to the first page
259     get next_path
260     assert_response :success
261     assert_select "table#trace_list tbody", :count => 1 do
262       assert_select "tr", :count => 20
263     end
264     check_no_page_link "Newer Traces"
265     check_page_link "Older Traces"
266   end
267
268   # Check a multi-page index of tagged traces
269   def test_index_tagged_paged
270     # Create several pages worth of traces
271     create_list(:trace, 100, :visibility => "identifiable") do |trace, index|
272       create(:tracetag, :trace => trace, :tag => "London") if index.even?
273     end
274     next_path = traces_path :tag => "London"
275
276     # Try and get the index
277     get next_path
278     assert_response :success
279     assert_select "table#trace_list tbody", :count => 1 do
280       assert_select "tr", :count => 20
281     end
282     check_no_page_link "Newer Traces"
283     next_path = check_page_link "Older Traces"
284
285     # Try and get the second page
286     get next_path
287     assert_response :success
288     assert_select "table#trace_list tbody", :count => 1 do
289       assert_select "tr", :count => 20
290     end
291     check_page_link "Newer Traces"
292     next_path = check_page_link "Older Traces"
293
294     # Try and get the third page
295     get next_path
296     assert_response :success
297     assert_select "table#trace_list tbody", :count => 1 do
298       assert_select "tr", :count => 10
299     end
300     next_path = check_page_link "Newer Traces"
301     check_no_page_link "Older Traces"
302
303     # Go back to the second page
304     get next_path
305     assert_response :success
306     assert_select "table#trace_list tbody", :count => 1 do
307       assert_select "tr", :count => 20
308     end
309     next_path = check_page_link "Newer Traces"
310     check_page_link "Older Traces"
311
312     # Go back to the first page
313     get next_path
314     assert_response :success
315     assert_select "table#trace_list tbody", :count => 1 do
316       assert_select "tr", :count => 20
317     end
318     check_no_page_link "Newer Traces"
319     check_page_link "Older Traces"
320   end
321
322   def test_index_invalid_paged
323     # Try some invalid paged accesses
324     %w[-1 fred].each do |id|
325       get traces_path(:before => id)
326       assert_response :bad_request
327
328       get traces_path(:after => id)
329       assert_response :bad_request
330     end
331   end
332
333   # Check that the traces index is not displayed when the traces feature is disabled
334   def test_index_disabled
335     with_settings(:traces_disabled => true) do
336       get traces_path
337       assert_response :not_found
338     end
339   end
340
341   # Test showing a trace
342   def test_show
343     public_trace_file = create(:trace, :visibility => "identifiable")
344
345     # First with no auth, which should work since the trace is public
346     get show_trace_path(public_trace_file.user, public_trace_file)
347     check_trace_show public_trace_file
348
349     # Now with some other user, which should work since the trace is public
350     session_for(create(:user))
351     get show_trace_path(public_trace_file.user, public_trace_file)
352     check_trace_show public_trace_file
353
354     # And finally we should be able to do it with the owner of the trace
355     session_for(public_trace_file.user)
356     get show_trace_path(public_trace_file.user, public_trace_file)
357     check_trace_show public_trace_file
358   end
359
360   # Check an anonymous trace can't be viewed by another user
361   def test_show_anon
362     anon_trace_file = create(:trace, :visibility => "trackable")
363
364     # First with no auth
365     get show_trace_path(anon_trace_file.user, anon_trace_file)
366     assert_redirected_to :action => :index
367
368     # Now with some other user, which should not work since the trace is anon
369     session_for(create(:user))
370     get show_trace_path(anon_trace_file.user, anon_trace_file)
371     assert_redirected_to :action => :index
372
373     # And finally we should be able to do it with the owner of the trace
374     session_for(anon_trace_file.user)
375     get show_trace_path(anon_trace_file.user, anon_trace_file)
376     check_trace_show anon_trace_file
377   end
378
379   # Test showing a trace that doesn't exist
380   def test_show_not_found
381     deleted_trace_file = create(:trace, :deleted)
382
383     # First with a trace that has never existed
384     get show_trace_path(create(:user), 0)
385     assert_redirected_to :action => :index
386
387     # Now with a trace that has been deleted
388     session_for(deleted_trace_file.user)
389     get show_trace_path(deleted_trace_file.user, deleted_trace_file)
390     assert_redirected_to :action => :index
391   end
392
393   # Test fetching the new trace page
394   def test_new_get
395     # First with no auth
396     get new_trace_path
397     assert_redirected_to login_path(:referer => new_trace_path)
398
399     # Now authenticated as a user with gps.trace.visibility set
400     user = create(:user)
401     create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
402     session_for(user)
403     get new_trace_path
404     assert_response :success
405     assert_template :new
406     assert_select "select#trace_visibility option[value=identifiable][selected]", 1
407
408     # Now authenticated as a user with the legacy gps.trace.public preference,
409     # which is no longer supported and falls back to trackable
410     second_user = create(:user)
411     create(:user_preference, :user => second_user, :k => "gps.trace.public", :v => "default")
412     session_for(second_user)
413     get new_trace_path
414     assert_response :success
415     assert_template :new
416     assert_select "select#trace_visibility option[value=trackable][selected]", 1
417
418     # Now authenticated as a user with no preferences, defaults to trackable
419     third_user = create(:user)
420     session_for(third_user)
421     get new_trace_path
422     assert_response :success
423     assert_template :new
424     assert_select "select#trace_visibility option[value=trackable][selected]", 1
425     # New uploads only offer the two supported visibilities
426     assert_select "select#trace_visibility option", 2
427   end
428
429   # Test creating a trace
430   def test_create_post
431     # Get file to use
432     fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
433     file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
434     user = create(:user)
435
436     # First with no auth
437     post traces_path(:trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" })
438     assert_response :forbidden
439
440     # Rewind the file
441     file.rewind
442
443     # Now authenticated
444     create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
445     assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
446     session_for(user)
447     post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }
448     assert_redirected_to :action => :index, :display_name => user.display_name
449     assert_match(/file has been uploaded/, flash[:notice])
450     trace = Trace.order(:id => :desc).first
451     assert_equal "a.gpx", trace.name
452     assert_equal "New Trace", trace.description
453     assert_equal %w[new trace], trace.tags.order(:tag).collect(&:tag)
454     assert_equal "trackable", trace.visibility
455     assert_not trace.inserted
456     assert_equal File.new(fixture).read, trace.file.blob.download
457     trace.destroy
458     assert_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
459   end
460
461   # A legacy visibility (public or private) is no longer accepted on upload
462   def test_create_post_with_legacy_visibility
463     fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
464     file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
465     user = create(:user)
466     session_for(user)
467
468     assert_no_difference "Trace.count" do
469       post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "public" } }
470     end
471     assert_template :new
472   end
473
474   # Test creating a trace with validation errors
475   def test_create_post_with_validation_errors
476     # Get file to use
477     fixture = Rails.root.join("test/gpx/fixtures/a.gpx")
478     file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
479     user = create(:user)
480
481     # Now authenticated
482     create(:user_preference, :user => user, :k => "gps.trace.visibility", :v => "identifiable")
483     assert_not_equal "trackable", user.preferences.find_by(:k => "gps.trace.visibility").v
484     session_for(user)
485     post traces_path, :params => { :trace => { :gpx_file => file, :description => "", :tagstring => "new,trace", :visibility => "trackable" } }
486     assert_response :unprocessable_content
487     assert_template :new
488     assert_select "#trace_description_feedback", :text => "can't be blank"
489
490     # Invalid tag
491     file = Rack::Test::UploadedFile.new(fixture, "application/gpx+xml")
492     assert_no_difference "Trace.count" do
493       post traces_path, :params => { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "invalid/tag, valid", :visibility => "trackable" } }
494     end
495     assert_response :unprocessable_content
496     assert_template :new
497     assert_select "#trace_tagstring.is-invalid"
498     assert_select "#trace_tagstring_feedback", :text => "contains special URL characters (/;.,?%#)"
499   end
500
501   # Test fetching the edit page for a trace using GET
502   def test_edit_get
503     public_trace_file = create(:trace, :visibility => "identifiable")
504     deleted_trace_file = create(:trace, :deleted)
505
506     # First with no auth
507     get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
508     assert_redirected_to login_path(:referer => edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file.id))
509
510     # Now with some other user, which should fail
511     session_for(create(:user))
512     get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
513     assert_response :forbidden
514
515     # Now with a trace which doesn't exist
516     session_for(create(:user))
517     get edit_trace_path(:display_name => create(:user).display_name, :id => 0)
518     assert_response :not_found
519
520     # Now with a trace which has been deleted
521     session_for(deleted_trace_file.user)
522     get edit_trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
523     assert_response :not_found
524
525     # Finally with a trace that we are allowed to edit
526     session_for(public_trace_file.user)
527     get edit_trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
528     assert_response :success
529   end
530
531   # An old visibility stays selected in the edit form, so changing other fields
532   # does not change it by mistake.
533   def test_edit_get_keeps_legacy_visibility
534     trace = create(:trace, :without_validations, :visibility => "private")
535
536     session_for(trace.user)
537     get edit_trace_path(:display_name => trace.user.display_name, :id => trace)
538     assert_response :success
539     assert_select "select#trace_visibility option", 3
540     assert_select "select#trace_visibility option[value=private][selected]", 1
541   end
542
543   # Test saving edits to a trace
544   def test_update
545     public_trace_file = create(:trace, :visibility => "identifiable")
546     deleted_trace_file = create(:trace, :deleted)
547
548     # New details
549     new_details = { :description => "Changed description", :tagstring => "new_tag", :visibility => "trackable" }
550
551     # First with no auth
552     put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
553     assert_response :forbidden
554
555     # Now with some other user, which should fail
556     session_for(create(:user))
557     put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
558     assert_response :forbidden
559
560     # Now with a trace which doesn't exist
561     session_for(create(:user))
562     put trace_path(:display_name => create(:user).display_name, :id => 0, :trace => new_details)
563     assert_response :not_found
564
565     # Now with a trace which has been deleted
566     session_for(deleted_trace_file.user)
567     put trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file, :trace => new_details)
568     assert_response :not_found
569
570     # Finally with a trace that we are allowed to edit
571     session_for(public_trace_file.user)
572     put trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file, :trace => new_details)
573     assert_redirected_to :action => :show, :display_name => public_trace_file.user.display_name
574     trace = Trace.find(public_trace_file.id)
575     assert_equal new_details[:description], trace.description
576     assert_equal new_details[:tagstring], trace.tagstring
577     assert_equal new_details[:visibility], trace.visibility
578   end
579
580   # Test invalid updates
581   def test_update_invalid
582     tracetag = create(:tracetag)
583     trace = tracetag.trace
584
585     # Invalid visibility
586     session_for(trace.user)
587     put trace_path(trace, :trace => { :description => "Changed description", :tagstring => "new_tag", :visibility => "wrong" })
588     assert_response :unprocessable_content
589     assert_select "title", :text => /^Editing Trace/
590
591     # Invalid tag
592     put trace_path(trace, :trace => { :description => "Changed description", :tagstring => "invalid/tag, valid", :visibility => "trackable" })
593     assert_response :unprocessable_content
594     assert_select "title", :text => /^Editing Trace/
595     assert_select "#trace_tagstring.is-invalid"
596     assert_select "#trace_tagstring_feedback", :text => "contains special URL characters (/;.,?%#)"
597
598     # Blank description
599     put trace_path(trace, :trace => { :description => " ", :tagstring => "new_tag", :visibility => "trackable" })
600     assert_response :unprocessable_content
601     assert_select "title", :text => /^Editing Trace/
602     assert_select "#trace_description.is-invalid"
603     assert_select "#trace_description_feedback", :text => "can't be blank"
604
605     # Ensure the existing tags have not been changed
606     assert_equal [tracetag.tag], trace.reload.tags.collect(&:tag)
607   end
608
609   # Test destroying a trace
610   def test_destroy
611     public_trace_file = create(:trace, :visibility => "identifiable")
612     deleted_trace_file = create(:trace, :deleted)
613
614     # First with no auth
615     delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
616     assert_response :forbidden
617
618     # Now with some other user, which should fail
619     session_for(create(:user))
620     delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
621     assert_response :forbidden
622
623     # Now with a trace which doesn't exist
624     session_for(create(:user))
625     delete trace_path(:display_name => create(:user).display_name, :id => 0)
626     assert_response :not_found
627
628     # Now with a trace has already been deleted
629     session_for(deleted_trace_file.user)
630     delete trace_path(:display_name => deleted_trace_file.user.display_name, :id => deleted_trace_file)
631     assert_response :not_found
632
633     # Now with a trace that we are allowed to delete
634     session_for(public_trace_file.user)
635     delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
636     assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
637     trace = Trace.find(public_trace_file.id)
638     assert_not trace.visible
639
640     # Finally with a trace that is destroyed by an admin
641     public_trace_file = create(:trace, :visibility => "identifiable")
642     admin = create(:administrator_user)
643     session_for(admin)
644     delete trace_path(:display_name => public_trace_file.user.display_name, :id => public_trace_file)
645     assert_redirected_to :action => :index, :display_name => public_trace_file.user.display_name
646     trace = Trace.find(public_trace_file.id)
647     assert_not trace.visible
648   end
649
650   private
651
652   def check_trace_index(traces)
653     assert_response :success
654     assert_template "index"
655
656     if traces.empty?
657       assert_select "h2", /Nothing here yet/
658     else
659       assert_select "table#trace_list tbody", :count => 1 do
660         assert_select "tr", :count => traces.length do |rows|
661           traces.zip(rows).each do |trace, row|
662             assert_select row, "a", Regexp.new(Regexp.escape(trace.name))
663             assert_select row, "li", Regexp.new(Regexp.escape("#{trace.size} points")) if trace.inserted?
664             assert_select row, "td", Regexp.new(Regexp.escape(trace.description))
665             assert_select row, "td", Regexp.new(Regexp.escape("by #{trace.user.display_name}"))
666             assert_select row, "a[href='#{user_path trace.user}']", :text => trace.user.display_name
667           end
668         end
669       end
670     end
671   end
672
673   def check_no_page_link(name)
674     assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/, :count => 0 }, "unexpected #{name} page link"
675   end
676
677   def check_page_link(name)
678     assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/ }, "missing #{name} page link" do |buttons|
679       return buttons.first.attributes["href"].value
680     end
681   end
682
683   def check_trace_show(trace)
684     assert_response :success
685     assert_template "show"
686
687     assert_select "table", :count => 1 do
688       assert_select "td", /^#{Regexp.quote(trace.name)} /
689       assert_select "td a[href='#{user_path trace.user}']", :text => trace.user.display_name
690       assert_select "td", trace.description
691     end
692   end
693 end