3 class OauthClientsControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/user/username/oauth_clients", :method => :get },
9 { :controller => "oauth_clients", :action => "index", :display_name => "username" }
12 { :path => "/user/username/oauth_clients/new", :method => :get },
13 { :controller => "oauth_clients", :action => "new", :display_name => "username" }
16 { :path => "/user/username/oauth_clients", :method => :post },
17 { :controller => "oauth_clients", :action => "create", :display_name => "username" }
20 { :path => "/user/username/oauth_clients/1", :method => :get },
21 { :controller => "oauth_clients", :action => "show", :display_name => "username", :id => "1" }
24 { :path => "/user/username/oauth_clients/1/edit", :method => :get },
25 { :controller => "oauth_clients", :action => "edit", :display_name => "username", :id => "1" }
28 { :path => "/user/username/oauth_clients/1", :method => :put },
29 { :controller => "oauth_clients", :action => "update", :display_name => "username", :id => "1" }
32 { :path => "/user/username/oauth_clients/1", :method => :delete },
33 { :controller => "oauth_clients", :action => "destroy", :display_name => "username", :id => "1" }
39 create_list(:client_application, 2, :user => user)
40 create_list(:access_token, 2, :user => user)
42 get oauth_clients_path(:display_name => user.display_name)
43 assert_response :redirect
44 assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
48 get oauth_clients_path(:display_name => user.display_name)
49 assert_response :success
50 assert_template "index"
51 assert_select "li.client_application", 2
57 get new_oauth_client_path(:display_name => user.display_name)
58 assert_response :redirect
59 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
63 get new_oauth_client_path(:display_name => user.display_name)
64 assert_response :success
66 assert_select "form", 1 do
67 assert_select "input#client_application_name", 1
68 assert_select "input#client_application_url", 1
69 assert_select "input#client_application_callback_url", 1
70 assert_select "input#client_application_support_url", 1
71 ClientApplication.all_permissions.each do |perm|
72 assert_select "input#client_application_#{perm}", 1
80 with_settings(:oauth_10_registration => false) do
81 get new_oauth_client_path(:display_name => user.display_name)
82 assert_response :redirect
83 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
87 get new_oauth_client_path(:display_name => user.display_name)
88 assert_response :redirect
89 assert_redirected_to oauth_clients_path(:display_name => user.display_name)
96 assert_difference "ClientApplication.count", 0 do
97 post oauth_clients_path(:display_name => user.display_name)
99 assert_response :forbidden
103 assert_difference "ClientApplication.count", 0 do
104 post oauth_clients_path(:display_name => user.display_name,
105 :client_application => { :name => "Test Application" })
107 assert_response :success
108 assert_template "new"
110 assert_difference "ClientApplication.count", 1 do
111 post oauth_clients_path(:display_name => user.display_name,
112 :client_application => { :name => "Test Application",
113 :url => "http://test.example.com/" })
115 assert_response :redirect
116 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
121 client = create(:client_application, :user => user)
122 other_client = create(:client_application)
124 get oauth_client_path(:display_name => user.display_name, :id => client)
125 assert_response :redirect
126 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
130 get oauth_client_path(:display_name => user.display_name, :id => other_client)
131 assert_response :not_found
132 assert_template "not_found"
134 get oauth_client_path(:display_name => user.display_name, :id => client)
135 assert_response :success
136 assert_template "show"
141 client = create(:client_application, :user => user)
142 other_client = create(:client_application)
144 get edit_oauth_client_path(:display_name => user.display_name, :id => client)
145 assert_response :redirect
146 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
150 get edit_oauth_client_path(:display_name => user.display_name, :id => other_client)
151 assert_response :not_found
152 assert_template "not_found"
154 get edit_oauth_client_path(:display_name => user.display_name, :id => client)
155 assert_response :success
156 assert_template "edit"
157 assert_select "form", 1 do
158 assert_select "input#client_application_name", 1
159 assert_select "input#client_application_url", 1
160 assert_select "input#client_application_callback_url", 1
161 assert_select "input#client_application_support_url", 1
162 ClientApplication.all_permissions.each do |perm|
163 assert_select "input#client_application_#{perm}", 1
170 client = create(:client_application, :user => user)
171 other_client = create(:client_application)
173 put oauth_client_path(:display_name => user.display_name, :id => client)
174 assert_response :forbidden
178 put oauth_client_path(:display_name => user.display_name, :id => other_client)
179 assert_response :not_found
180 assert_template "not_found"
182 put oauth_client_path(:display_name => user.display_name, :id => client,
183 :client_application => { :name => "New Name", :url => nil })
184 assert_response :success
185 assert_template "edit"
187 put oauth_client_path(:display_name => user.display_name, :id => client,
188 :client_application => { :name => "New Name", :url => "http://new.example.com/url" })
189 assert_response :redirect
190 assert_redirected_to oauth_client_path(:id => client.id)
195 client = create(:client_application, :user => user)
196 other_client = create(:client_application)
198 assert_difference "ClientApplication.count", 0 do
199 delete oauth_client_path(:display_name => user.display_name, :id => client)
201 assert_response :forbidden
205 assert_difference "ClientApplication.count", 0 do
206 delete oauth_client_path(:display_name => user.display_name, :id => other_client)
208 assert_response :not_found
209 assert_template "not_found"
211 assert_difference "ClientApplication.count", -1 do
212 delete oauth_client_path(:display_name => user.display_name, :id => client)
214 assert_response :redirect
215 assert_redirected_to oauth_clients_path(:display_name => user.display_name)