]> git.openstreetmap.org Git - rails.git/blob - test/controllers/oauth2_authorized_applications_controller_test.rb
Don't show types twice in issue type select
[rails.git] / test / controllers / oauth2_authorized_applications_controller_test.rb
1 require "test_helper"
2
3 class Oauth2AuthorizedApplicationsControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/oauth2/authorized_applications", :method => :get },
9       { :controller => "oauth2_authorized_applications", :action => "index" }
10     )
11     assert_routing(
12       { :path => "/oauth2/authorized_applications/1", :method => :delete },
13       { :controller => "oauth2_authorized_applications", :action => "destroy", :id => "1" }
14     )
15   end
16
17   def test_index
18     user = create(:user)
19     application1 = create(:oauth_application)
20     create(:oauth_access_grant, :resource_owner_id => user.id, :application => application1)
21     create(:oauth_access_token, :resource_owner_id => user.id, :application => application1)
22     application2 = create(:oauth_application)
23     create(:oauth_access_grant, :resource_owner_id => user.id, :application => application2)
24     create(:oauth_access_token, :resource_owner_id => user.id, :application => application2)
25     create(:oauth_application)
26
27     get oauth_authorized_applications_path
28     assert_redirected_to login_path(:referer => oauth_authorized_applications_path)
29
30     session_for(user)
31
32     get oauth_authorized_applications_path
33     assert_response :success
34     assert_template "oauth2_authorized_applications/index"
35     assert_select "tbody tr", 2
36   end
37
38   def test_index_scopes
39     user = create(:user)
40     application1 = create(:oauth_application, :scopes => %w[read_prefs write_prefs write_diary read_gpx write_gpx])
41     create(:oauth_access_grant, :resource_owner_id => user.id, :application => application1, :scopes => %w[read_prefs write_prefs])
42     create(:oauth_access_token, :resource_owner_id => user.id, :application => application1, :scopes => %w[read_prefs write_prefs])
43     create(:oauth_access_grant, :resource_owner_id => user.id, :application => application1, :scopes => %w[read_prefs write_diary])
44     create(:oauth_access_token, :resource_owner_id => user.id, :application => application1, :scopes => %w[read_prefs write_diary])
45
46     get oauth_authorized_applications_path
47     assert_redirected_to login_path(:referer => oauth_authorized_applications_path)
48
49     session_for(user)
50
51     get oauth_authorized_applications_path
52     assert_response :success
53     assert_template "oauth2_authorized_applications/index"
54     assert_select "tbody tr", 1
55     assert_select "tbody tr td ul" do
56       assert_select "li", :count => 3
57       assert_select "li", :text => "Read user preferences"
58       assert_select "li", :text => "Modify user preferences"
59       assert_select "li", :text => "Create diary entries, comments and make friends"
60     end
61   end
62
63   def test_destroy
64     user = create(:user)
65     application1 = create(:oauth_application)
66     create(:oauth_access_grant, :resource_owner_id => user.id, :application => application1)
67     create(:oauth_access_token, :resource_owner_id => user.id, :application => application1)
68     application2 = create(:oauth_application)
69     create(:oauth_access_grant, :resource_owner_id => user.id, :application => application2)
70     create(:oauth_access_token, :resource_owner_id => user.id, :application => application2)
71     create(:oauth_application)
72
73     delete oauth_authorized_application_path(:id => application1.id)
74     assert_response :forbidden
75
76     session_for(user)
77
78     delete oauth_authorized_application_path(:id => application1.id)
79     assert_redirected_to oauth_authorized_applications_path
80
81     get oauth_authorized_applications_path
82     assert_response :success
83     assert_template "oauth2_authorized_applications/index"
84     assert_select "tbody tr", 1
85   end
86 end