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 "div.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 assert_difference "ClientApplication.count", 0 do
81 post oauth_clients_path(:display_name => user.display_name)
83 assert_response :forbidden
87 assert_difference "ClientApplication.count", 0 do
88 post oauth_clients_path(:display_name => user.display_name,
89 :client_application => { :name => "Test Application" })
91 assert_response :success
94 assert_difference "ClientApplication.count", 1 do
95 post oauth_clients_path(:display_name => user.display_name,
96 :client_application => { :name => "Test Application",
97 :url => "http://test.example.com/" })
99 assert_response :redirect
100 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
105 client = create(:client_application, :user => user)
106 other_client = create(:client_application)
108 get oauth_client_path(:display_name => user.display_name, :id => client)
109 assert_response :redirect
110 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
114 get oauth_client_path(:display_name => user.display_name, :id => other_client)
115 assert_response :not_found
116 assert_template "not_found"
118 get oauth_client_path(:display_name => user.display_name, :id => client)
119 assert_response :success
120 assert_template "show"
125 client = create(:client_application, :user => user)
126 other_client = create(:client_application)
128 get edit_oauth_client_path(:display_name => user.display_name, :id => client)
129 assert_response :redirect
130 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
134 get edit_oauth_client_path(:display_name => user.display_name, :id => other_client)
135 assert_response :not_found
136 assert_template "not_found"
138 get edit_oauth_client_path(:display_name => user.display_name, :id => client)
139 assert_response :success
140 assert_template "edit"
141 assert_select "form", 1 do
142 assert_select "input#client_application_name", 1
143 assert_select "input#client_application_url", 1
144 assert_select "input#client_application_callback_url", 1
145 assert_select "input#client_application_support_url", 1
146 ClientApplication.all_permissions.each do |perm|
147 assert_select "input#client_application_#{perm}", 1
154 client = create(:client_application, :user => user)
155 other_client = create(:client_application)
157 put oauth_client_path(:display_name => user.display_name, :id => client)
158 assert_response :forbidden
162 put oauth_client_path(:display_name => user.display_name, :id => other_client)
163 assert_response :not_found
164 assert_template "not_found"
166 put oauth_client_path(:display_name => user.display_name, :id => client,
167 :client_application => { :name => "New Name", :url => nil })
168 assert_response :success
169 assert_template "edit"
171 put oauth_client_path(:display_name => user.display_name, :id => client,
172 :client_application => { :name => "New Name", :url => "http://new.example.com/url" })
173 assert_response :redirect
174 assert_redirected_to oauth_client_path(:id => client.id)
179 client = create(:client_application, :user => user)
180 other_client = create(:client_application)
182 assert_difference "ClientApplication.count", 0 do
183 delete oauth_client_path(:display_name => user.display_name, :id => client)
185 assert_response :forbidden
189 assert_difference "ClientApplication.count", 0 do
190 delete oauth_client_path(:display_name => user.display_name, :id => other_client)
192 assert_response :not_found
193 assert_template "not_found"
195 assert_difference "ClientApplication.count", -1 do
196 delete oauth_client_path(:display_name => user.display_name, :id => client)
198 assert_response :redirect
199 assert_redirected_to oauth_clients_path(:display_name => user.display_name)