]> git.openstreetmap.org Git - rails.git/blob - test/functional/trace_controller_test.rb
Ajaxify the mark read/unread function for messages so it doesn't
[rails.git] / test / functional / trace_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class TraceControllerTest < ActionController::TestCase
4   fixtures :users, :gpx_files
5   set_fixture_class :gpx_files => 'Trace'
6
7
8   # Check that the list of changesets is displayed
9   def test_list
10     get :list
11     assert_response :success
12     assert_template 'list'
13   end
14
15   # Check that I can get mine
16   def test_list_mine
17     # First try to get it when not logged in
18     get :mine
19     assert_redirected_to :controller => 'user', :action => 'login', :referer => '/traces/mine'
20
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
24   end
25
26   # Check that the rss loads
27   def test_rss
28     get :georss
29     assert_rss_success
30
31     get :georss, :display_name => users(:normal_user).display_name
32     assert_rss_success
33   end
34
35   def assert_rss_success
36     assert_response :success
37     assert_template nil
38     assert_equal "application/rss+xml", @response.content_type
39   end
40
41   # Check getting a specific trace through the api
42   def test_api_details
43     # First with no auth
44     get :api_details, :id => gpx_files(:public_trace_file).id
45     assert_response :unauthorized
46
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
51
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
56   end
57
58   # Check an anoymous trace can't be specifically fetched by another user
59   def test_api_details_anon
60     # Furst with no auth
61     get :api_details, :id => gpx_files(:anon_trace_file).id
62     assert_response :unauthorized
63
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
68
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
73   end
74
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
80
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
85   end
86 end