3 class OauthClientsControllerTest < ActionController::TestCase
7 # test all routes which lead to this controller
10 { :path => "/user/username/oauth_clients", :method => :get },
11 { :controller => "oauth_clients", :action => "index", :display_name => "username" }
14 { :path => "/user/username/oauth_clients/new", :method => :get },
15 { :controller => "oauth_clients", :action => "new", :display_name => "username" }
18 { :path => "/user/username/oauth_clients", :method => :post },
19 { :controller => "oauth_clients", :action => "create", :display_name => "username" }
22 { :path => "/user/username/oauth_clients/1", :method => :get },
23 { :controller => "oauth_clients", :action => "show", :display_name => "username", :id => "1" }
26 { :path => "/user/username/oauth_clients/1/edit", :method => :get },
27 { :controller => "oauth_clients", :action => "edit", :display_name => "username", :id => "1" }
30 { :path => "/user/username/oauth_clients/1", :method => :put },
31 { :controller => "oauth_clients", :action => "update", :display_name => "username", :id => "1" }
34 { :path => "/user/username/oauth_clients/1", :method => :delete },
35 { :controller => "oauth_clients", :action => "destroy", :display_name => "username", :id => "1" }
40 user = users(:public_user)
41 create_list(:client_application, 2, :user => user)
43 get :index, :display_name => user.display_name
44 assert_response :redirect
45 assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
47 get :index, { :display_name => user.display_name }, { :user => user }
48 assert_response :success
49 assert_template "index"
50 assert_select "div.client_application", 2
54 user = users(:public_user)
56 get :new, :display_name => user.display_name
57 assert_response :redirect
58 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
60 get :new, { :display_name => user.display_name }, { :user => user }
61 assert_response :success
63 assert_select "form", 1 do
64 assert_select "input#client_application_name", 1
65 assert_select "input#client_application_url", 1
66 assert_select "input#client_application_callback_url", 1
67 assert_select "input#client_application_support_url", 1
68 ClientApplication.all_permissions.each do |perm|
69 assert_select "input#client_application_#{perm}", 1
75 user = users(:public_user)
77 assert_difference "ClientApplication.count", 0 do
78 post :create, :display_name => user.display_name
80 assert_response :forbidden
82 assert_difference "ClientApplication.count", 0 do
84 :display_name => user.display_name,
85 :client_application => {
86 :name => "Test Application"
90 assert_response :success
93 assert_difference "ClientApplication.count", 1 do
95 :display_name => user.display_name,
96 :client_application => {
97 :name => "Test Application",
98 :url => "http://test.example.com/"
102 assert_response :redirect
103 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
107 user = users(:public_user)
108 client = create(:client_application, :user => user)
109 other_client = create(:client_application)
111 get :show, :display_name => user.display_name, :id => client.id
112 assert_response :redirect
113 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
115 get :show, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
116 assert_response :not_found
117 assert_template "not_found"
119 get :show, { :display_name => user.display_name, :id => client.id }, { :user => user }
120 assert_response :success
121 assert_template "show"
125 user = users(:public_user)
126 client = create(:client_application, :user => user)
127 other_client = create(:client_application)
129 get :edit, :display_name => user.display_name, :id => client.id
130 assert_response :redirect
131 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
133 get :edit, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
134 assert_response :not_found
135 assert_template "not_found"
137 get :edit, { :display_name => user.display_name, :id => client.id }, { :user => user }
138 assert_response :success
139 assert_template "edit"
140 assert_select "form", 1 do
141 assert_select "input#client_application_name", 1
142 assert_select "input#client_application_url", 1
143 assert_select "input#client_application_callback_url", 1
144 assert_select "input#client_application_support_url", 1
145 ClientApplication.all_permissions.each do |perm|
146 assert_select "input#client_application_#{perm}", 1
152 user = users(:public_user)
153 client = create(:client_application, :user => user)
154 other_client = create(:client_application)
156 put :update, :display_name => user.display_name, :id => client.id
157 assert_response :forbidden
159 put :update, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
160 assert_response :not_found
161 assert_template "not_found"
164 :display_name => user.display_name,
166 :client_application => {
171 assert_response :success
172 assert_template "edit"
175 :display_name => user.display_name,
177 :client_application => {
179 :url => "http://new.example.com/url"
182 assert_response :redirect
183 assert_redirected_to oauth_client_path(:id => client.id)
187 user = users(:public_user)
188 client = create(:client_application, :user => user)
189 other_client = create(:client_application)
191 assert_difference "ClientApplication.count", 0 do
192 delete :destroy, :display_name => user.display_name, :id => client.id
194 assert_response :forbidden
196 assert_difference "ClientApplication.count", 0 do
197 delete :destroy, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
199 assert_response :not_found
200 assert_template "not_found"
202 assert_difference "ClientApplication.count", -1 do
203 delete :destroy, { :display_name => user.display_name, :id => client.id }, { :user => user }
205 assert_response :redirect
206 assert_redirected_to oauth_clients_path(:display_name => user.display_name)