4 class IconsControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/user/username/traces/1/icon", :method => :get },
10 { :controller => "traces/icons", :action => "show", :display_name => "username", :trace_id => "1" }
14 # Test downloading the icon for a trace
16 public_trace_file = create(:trace, :visibility => "public", :fixture => "a")
18 # First with no auth, which should work since the trace is public
19 get trace_icon_path(public_trace_file.user, public_trace_file)
20 check_trace_icon public_trace_file
22 # Now with some other user, which should work since the trace is public
23 session_for(create(:user))
24 get trace_icon_path(public_trace_file.user, public_trace_file)
25 check_trace_icon public_trace_file
27 # And finally we should be able to do it with the owner of the trace
28 session_for(public_trace_file.user)
29 get trace_icon_path(public_trace_file.user, public_trace_file)
30 check_trace_icon public_trace_file
33 # Check the icon for an anonymous trace can't be downloaded by another user
35 anon_trace_file = create(:trace, :visibility => "private", :fixture => "b")
38 get trace_icon_path(anon_trace_file.user, anon_trace_file)
39 assert_response :forbidden
41 # Now with some other user, which shouldn't work since the trace is anon
42 session_for(create(:user))
43 get trace_icon_path(anon_trace_file.user, anon_trace_file)
44 assert_response :forbidden
46 # And finally we should be able to do it with the owner of the trace
47 session_for(anon_trace_file.user)
48 get trace_icon_path(anon_trace_file.user, anon_trace_file)
49 check_trace_icon anon_trace_file
52 # Test downloading the icon for a trace that doesn't exist
53 def test_show_not_found
54 deleted_trace_file = create(:trace, :deleted)
56 # First with a trace that has never existed
57 get trace_icon_path(create(:user), 0)
58 assert_response :not_found
60 # Now with a trace that has been deleted
61 session_for(deleted_trace_file.user)
62 get trace_icon_path(deleted_trace_file.user, deleted_trace_file)
63 assert_response :not_found
68 def check_trace_icon(trace)
71 assert_response :success
72 assert_equal "image/gif", response.media_type
73 assert_equal trace.icon_picture, response.body