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_response :success
 
  24     assert_template 'mine'
 
  25     # Should really test to see which files are shown to the user
 
  28   # Check that the rss loads
 
  33     get :georss, :display_name => users(:normal_user).display_name
 
  37   def assert_rss_success 
 
  38     assert_response :success
 
  40     assert_equal "application/rss+xml", @response.content_type
 
  43   # Check getting a specific trace through the api
 
  46     get :api_details, :id => gpx_files(:public_trace_file).id
 
  47     assert_response :unauthorized
 
  49     # Now with some other user, which should work since the trace is public
 
  50     basic_authorization(users(:public_user).display_name, "test")
 
  51     get :api_details, :id => gpx_files(:public_trace_file).id
 
  52     assert_response :success
 
  54     # And finally we should be able to do it with the owner of the trace
 
  55     basic_authorization(users(:normal_user).display_name, "test")
 
  56     get :api_details, :id => gpx_files(:public_trace_file).id
 
  57     assert_response :success
 
  60   # Check an anoymous trace can't be specifically fetched by another user
 
  61   def test_api_details_anon
 
  63     get :api_details, :id => gpx_files(:anon_trace_file).id
 
  64     assert_response :unauthorized
 
  66     # Now try with another user, which shouldn't work since the trace is anon
 
  67     basic_authorization(users(:normal_user).display_name, "test")
 
  68     get :api_details, :id => gpx_files(:anon_trace_file).id
 
  69     assert_response :forbidden
 
  71     # And finally we should be able to get the trace details with the trace owner
 
  72     basic_authorization(users(:public_user).display_name, "test")
 
  73     get :api_details, :id => gpx_files(:anon_trace_file).id
 
  74     assert_response :success
 
  77   # Check the api details for a trace that doesn't exist
 
  78   def test_api_details_not_found
 
  79     # Try first with no auth, as it should requure it
 
  80     get :api_details, :id => 0
 
  81     assert_response :unauthorized
 
  83     # Login, and try again
 
  84     basic_authorization(users(:public_user).display_name, "test")
 
  85     get :api_details, :id => 0
 
  86     assert_response :not_found