]> git.openstreetmap.org Git - rails.git/blob - test/functional/trace_controller_test.rb
Updated Hungarian translation of Potlatch
[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_response :success
24     assert_template 'mine'
25     # Should really test to see which files are shown to the user
26   end
27   
28   # Check that the rss loads
29   def test_rss
30     get :georss
31     assert_rss_success
32     
33     get :georss, :display_name => users(:normal_user).display_name
34     assert_rss_success
35   end
36   
37   def assert_rss_success 
38     assert_response :success
39     assert_template nil
40     assert_equal "application/rss+xml", @response.content_type
41   end
42   
43   # Check getting a specific trace through the api
44   def test_api_details
45     # First with no auth
46     get :api_details, :id => gpx_files(:public_trace_file).id
47     assert_response :unauthorized
48     
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
53     
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
58   end
59   
60   # Check an anoymous trace can't be specifically fetched by another user
61   def test_api_details_anon
62     # Furst with no auth
63     get :api_details, :id => gpx_files(:anon_trace_file).id
64     assert_response :unauthorized
65     
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
70     
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
75   end
76   
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
82     
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
87   end
88 end