]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/permissions_controller_test.rb
Move the permissions call out of api_controller
[rails.git] / test / controllers / api / permissions_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class PermissionsControllerTest < ActionController::TestCase
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/api/0.6/permissions", :method => :get },
10         { :controller => "api/permissions", :action => "show" }
11       )
12     end
13
14     def test_permissions_anonymous
15       get :show
16       assert_response :success
17       assert_select "osm > permissions", :count => 1 do
18         assert_select "permission", :count => 0
19       end
20     end
21
22     def test_permissions_basic_auth
23       basic_authorization create(:user).email, "test"
24       get :show
25       assert_response :success
26       assert_select "osm > permissions", :count => 1 do
27         assert_select "permission", :count => ClientApplication.all_permissions.size
28         ClientApplication.all_permissions.each do |p|
29           assert_select "permission[name='#{p}']", :count => 1
30         end
31       end
32     end
33
34     def test_permissions_oauth
35       @request.env["oauth.token"] = AccessToken.new do |token|
36         # Just to test a few
37         token.allow_read_prefs = true
38         token.allow_write_api = true
39         token.allow_read_gpx = false
40       end
41       get :show
42       assert_response :success
43       assert_select "osm > permissions", :count => 1 do
44         assert_select "permission", :count => 2
45         assert_select "permission[name='allow_read_prefs']", :count => 1
46         assert_select "permission[name='allow_write_api']", :count => 1
47         assert_select "permission[name='allow_read_gpx']", :count => 0
48       end
49     end
50   end
51 end