1 require File.dirname(__FILE__) + '/../test_helper'
3 class TraceControllerTest < ActionController::TestCase
4 fixtures :users, :gpx_files
5 set_fixture_class :gpx_files => 'Trace'
8 # Check that the list of changesets is displayed
11 assert_response :success
12 assert_template 'list'
15 # Check that I can get mine
17 # First try to get it when not logged in
19 assert_redirected_to :controller => 'user', :action => 'login', :referer => '/traces/mine'
21 # Now try when logged in
22 get :mine, {}, {:user => users(:public_user).id}
23 assert_redirected_to :controller => 'trace', :action => 'list', :display_name => users(:public_user).display_name
26 # Check that the rss loads
31 get :georss, :display_name => users(:normal_user).display_name
35 def assert_rss_success
36 assert_response :success
38 assert_equal "application/rss+xml", @response.content_type
41 # Check getting a specific trace through the api
44 get :api_details, :id => gpx_files(:public_trace_file).id
45 assert_response :unauthorized
47 # Now with some other user, which should work since the trace is public
48 basic_authorization(users(:public_user).display_name, "test")
49 get :api_details, :id => gpx_files(:public_trace_file).id
50 assert_response :success
52 # And finally we should be able to do it with the owner of the trace
53 basic_authorization(users(:normal_user).display_name, "test")
54 get :api_details, :id => gpx_files(:public_trace_file).id
55 assert_response :success
58 # Check an anoymous trace can't be specifically fetched by another user
59 def test_api_details_anon
61 get :api_details, :id => gpx_files(:anon_trace_file).id
62 assert_response :unauthorized
64 # Now try with another user, which shouldn't work since the trace is anon
65 basic_authorization(users(:normal_user).display_name, "test")
66 get :api_details, :id => gpx_files(:anon_trace_file).id
67 assert_response :forbidden
69 # And finally we should be able to get the trace details with the trace owner
70 basic_authorization(users(:public_user).display_name, "test")
71 get :api_details, :id => gpx_files(:anon_trace_file).id
72 assert_response :success
75 # Check the api details for a trace that doesn't exist
76 def test_api_details_not_found
77 # Try first with no auth, as it should requure it
78 get :api_details, :id => 0
79 assert_response :unauthorized
81 # Login, and try again
82 basic_authorization(users(:public_user).display_name, "test")
83 get :api_details, :id => 0
84 assert_response :not_found