1 require File.dirname(__FILE__) + '/../test_helper'
3 class OauthClientsControllerTest < ActionController::TestCase
4 fixtures :users, :client_applications
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)
42 get :index, { :display_name => user.display_name }
43 assert_response :redirect
44 assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
46 get :index, { :display_name => user.display_name }, { :user => user }
47 assert_response :success
48 assert_template "index"
49 assert_select "div.client_application", 2
53 user = users(:public_user)
55 get :new, { :display_name => user.display_name }
56 assert_response :redirect
57 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
59 get :new, { :display_name => user.display_name }, { :user => user }
60 assert_response :success
62 assert_select "form", 1 do
63 assert_select "input#client_application_name", 1
64 assert_select "input#client_application_url", 1
65 assert_select "input#client_application_callback_url", 1
66 assert_select "input#client_application_support_url", 1
67 ClientApplication.all_permissions.each do |perm|
68 assert_select "input#client_application_#{perm}", 1
74 user = users(:public_user)
76 assert_difference "ClientApplication.count", 0 do
77 post :create, { :display_name => user.display_name }
79 assert_response :forbidden
81 assert_difference "ClientApplication.count", 0 do
83 :display_name => user.display_name,
84 :client_application => {
85 :name => "Test Application"
91 assert_response :success
94 assert_difference "ClientApplication.count", 1 do
96 :display_name => user.display_name,
97 :client_application => {
98 :name => "Test Application",
99 :url => "http://test.example.com/"
105 assert_response :redirect
106 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by_name("Test Application").id)
110 user = users(:public_user)
111 client = client_applications(:oauth_web_app)
113 get :show, { :display_name => user.display_name, :id => client.id }
114 assert_response :redirect
115 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
117 get :show, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
118 assert_response :not_found
119 assert_template "not_found"
121 get :show, { :display_name => user.display_name, :id => client.id }, { :user => user }
122 assert_response :success
123 assert_template "show"
127 user = users(:public_user)
128 client = client_applications(:oauth_web_app)
130 get :edit, { :display_name => user.display_name, :id => client.id }
131 assert_response :redirect
132 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
134 get :edit, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
135 assert_response :not_found
136 assert_template "not_found"
138 get :edit, { :display_name => user.display_name, :id => client.id }, { :user => user }
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
153 user = users(:public_user)
154 client = client_applications(:oauth_web_app)
156 put :update, { :display_name => user.display_name, :id => client.id }
157 assert_response :forbidden
159 put :update, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
160 assert_response :not_found
161 assert_template "not_found"
164 :display_name => user.display_name,
166 :client_application => {
173 assert_response :success
174 assert_template "edit"
177 :display_name => user.display_name,
179 :client_application => {
181 :url => "http://new.example.com/url"
186 assert_response :redirect
187 assert_redirected_to oauth_client_path(:id => client.id)
191 user = users(:public_user)
192 client = client_applications(:oauth_web_app)
194 assert_difference "ClientApplication.count", 0 do
195 delete :destroy, { :display_name => user.display_name, :id => client.id }
197 assert_response :forbidden
199 assert_difference "ClientApplication.count", 0 do
200 delete :destroy, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
202 assert_response :not_found
203 assert_template "not_found"
205 assert_difference "ClientApplication.count", -1 do
206 delete :destroy, { :display_name => user.display_name, :id => client.id }, { :user => user }
208 assert_response :redirect
209 assert_redirected_to oauth_clients_path(:display_name => user.display_name)