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_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
47 get oauth_clients_path(:display_name => user.display_name)
48 assert_response :success
49 assert_template "index"
50 assert_select "li.client_application", 2
56 get new_oauth_client_path(:display_name => user.display_name)
57 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
61 get new_oauth_client_path(:display_name => user.display_name)
62 assert_response :success
64 assert_select "form", 1 do
65 assert_select "input#client_application_name", 1
66 assert_select "input#client_application_url", 1
67 assert_select "input#client_application_callback_url", 1
68 assert_select "input#client_application_support_url", 1
69 ClientApplication.all_permissions.each do |perm|
70 assert_select "input#client_application_#{perm}", 1
78 with_settings(:oauth_10_registration => false) do
79 get new_oauth_client_path(:display_name => user.display_name)
80 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
84 get new_oauth_client_path(:display_name => user.display_name)
85 assert_redirected_to oauth_clients_path(:display_name => user.display_name)
92 assert_difference "ClientApplication.count", 0 do
93 post oauth_clients_path(:display_name => user.display_name)
95 assert_response :forbidden
99 assert_difference "ClientApplication.count", 0 do
100 post oauth_clients_path(:display_name => user.display_name,
101 :client_application => { :name => "Test Application" })
103 assert_response :success
104 assert_template "new"
106 assert_difference "ClientApplication.count", 1 do
107 post oauth_clients_path(:display_name => user.display_name,
108 :client_application => { :name => "Test Application",
109 :url => "http://test.example.com/" })
111 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
116 client = create(:client_application, :user => user)
117 other_client = create(:client_application)
119 get oauth_client_path(:display_name => user.display_name, :id => client)
120 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
124 get oauth_client_path(:display_name => user.display_name, :id => other_client)
125 assert_response :not_found
126 assert_template "not_found"
128 get oauth_client_path(:display_name => user.display_name, :id => client)
129 assert_response :success
130 assert_template "show"
135 client = create(:client_application, :user => user)
136 other_client = create(:client_application)
138 get edit_oauth_client_path(:display_name => user.display_name, :id => client)
139 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
143 get edit_oauth_client_path(:display_name => user.display_name, :id => other_client)
144 assert_response :not_found
145 assert_template "not_found"
147 get edit_oauth_client_path(:display_name => user.display_name, :id => client)
148 assert_response :success
149 assert_template "edit"
150 assert_select "form", 1 do
151 assert_select "input#client_application_name", 1
152 assert_select "input#client_application_url", 1
153 assert_select "input#client_application_callback_url", 1
154 assert_select "input#client_application_support_url", 1
155 ClientApplication.all_permissions.each do |perm|
156 assert_select "input#client_application_#{perm}", 1
163 client = create(:client_application, :user => user)
164 other_client = create(:client_application)
166 put oauth_client_path(:display_name => user.display_name, :id => client)
167 assert_response :forbidden
171 put oauth_client_path(:display_name => user.display_name, :id => other_client)
172 assert_response :not_found
173 assert_template "not_found"
175 put oauth_client_path(:display_name => user.display_name, :id => client,
176 :client_application => { :name => "New Name", :url => nil })
177 assert_response :success
178 assert_template "edit"
180 put oauth_client_path(:display_name => user.display_name, :id => client,
181 :client_application => { :name => "New Name", :url => "http://new.example.com/url" })
182 assert_redirected_to oauth_client_path(:id => client.id)
187 client = create(:client_application, :user => user)
188 other_client = create(:client_application)
190 assert_difference "ClientApplication.count", 0 do
191 delete oauth_client_path(:display_name => user.display_name, :id => client)
193 assert_response :forbidden
197 assert_difference "ClientApplication.count", 0 do
198 delete oauth_client_path(:display_name => user.display_name, :id => other_client)
200 assert_response :not_found
201 assert_template "not_found"
203 assert_difference "ClientApplication.count", -1 do
204 delete oauth_client_path(:display_name => user.display_name, :id => client)
206 assert_redirected_to oauth_clients_path(:display_name => user.display_name)