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 the rss loads
20 get :georss, :display_name => users(:normal_user).display_name
24 def assert_rss_success
25 assert_response :success
27 assert_equal "application/rss+xml", @response.content_type
30 # Check getting a specific trace through the api
33 get :api_details, :id => gpx_files(:public_trace_file).id
34 assert_response :unauthorized
36 # Now with some other user, which should work since the trace is public
37 basic_authorization(users(:public_user).display_name, "test")
38 get :api_details, :id => gpx_files(:public_trace_file).id
39 assert_response :success
41 # And finally we should be able to do it with the owner of the trace
42 basic_authorization(users(:normal_user).display_name, "test")
43 get :api_details, :id => gpx_files(:public_trace_file).id
44 assert_response :success
47 # Check an anoymous trace can't be specifically fetched by another user
48 def test_api_details_anon
50 get :api_details, :id => gpx_files(:anon_trace_file).id
51 assert_response :unauthorized
53 # Now try with another user, which shouldn't work since the trace is anon
54 basic_authorization(users(:normal_user).display_name, "test")
55 get :api_details, :id => gpx_files(:anon_trace_file).id
56 assert_response :forbidden
58 # And finally we should be able to get the trace details with the trace owner
59 basic_authorization(users(:public_user).display_name, "test")
60 get :api_details, :id => gpx_files(:anon_trace_file).id
61 assert_response :success
64 # Check the api details for a trace that doesn't exist
65 def test_api_details_not_found
66 # Try first with no auth, as it should requure it
67 get :api_details, :id => 0
68 assert_response :unauthorized
70 # Login, and try again
71 basic_authorization(users(:public_user).display_name, "test")
72 get :api_details, :id => 0
73 assert_response :not_found