]> git.openstreetmap.org Git - rails.git/blob - test/functional/trace_controller_test.rb
Tests for PreconditionFailed error messages.
[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 the rss loads
16   def test_rss
17     get :georss
18     assert_rss_success
19     
20     get :georss, :display_name => users(:normal_user).display_name
21     assert_rss_success
22   end
23   
24   def assert_rss_success 
25     assert_response :success
26     assert_template nil
27     assert_equal "application/rss+xml", @response.content_type
28   end
29   
30   # Check getting a specific trace through the api
31   def test_api_details
32     # First with no auth
33     get :api_details, :id => gpx_files(:public_trace_file).id
34     assert_response :unauthorized
35     
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
40     
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
45   end
46   
47   # Check an anoymous trace can't be specifically fetched by another user
48   def test_api_details_anon
49     # Furst with no auth
50     get :api_details, :id => gpx_files(:anon_trace_file).id
51     assert_response :unauthorized
52     
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
57     
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
62   end
63   
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
69     
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
74   end
75 end