4 class PermissionsControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/api/0.6/permissions", :method => :get },
10 { :controller => "api/permissions", :action => "show" }
13 { :path => "/api/0.6/permissions.json", :method => :get },
14 { :controller => "api/permissions", :action => "show", :format => "json" }
18 def test_permissions_anonymous
20 assert_response :success
21 assert_select "osm > permissions", :count => 1 do
22 assert_select "permission", :count => 0
26 get permissions_path(:format => "json")
27 assert_response :success
28 assert_equal "application/json", @response.media_type
30 js = ActiveSupport::JSON.decode(@response.body)
32 assert_equal 0, js["permissions"].count
35 def test_permissions_oauth2
37 token = create(:oauth_access_token,
38 :resource_owner_id => user.id,
39 :scopes => %w[read_prefs write_api])
40 get permissions_path, :headers => bearer_authorization_header(token.token)
41 assert_response :success
42 assert_select "osm > permissions", :count => 1 do
43 assert_select "permission", :count => 2
44 assert_select "permission[name='allow_read_prefs']", :count => 1
45 assert_select "permission[name='allow_write_api']", :count => 1
46 assert_select "permission[name='allow_read_gpx']", :count => 0