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"
89 assert_response :success
92 assert_difference "ClientApplication.count", 1 do
94 :display_name => user.display_name,
95 :client_application => {
96 :name => "Test Application",
97 :url => "http://test.example.com/"
101 assert_response :redirect
102 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by_name("Test Application").id)
106 user = users(:public_user)
107 client = client_applications(:oauth_web_app)
109 get :show, :display_name => user.display_name, :id => client.id
110 assert_response :redirect
111 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
113 get :show, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
114 assert_response :not_found
115 assert_template "not_found"
117 get :show, { :display_name => user.display_name, :id => client.id }, { :user => user }
118 assert_response :success
119 assert_template "show"
123 user = users(:public_user)
124 client = client_applications(:oauth_web_app)
126 get :edit, :display_name => user.display_name, :id => client.id
127 assert_response :redirect
128 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
130 get :edit, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
131 assert_response :not_found
132 assert_template "not_found"
134 get :edit, { :display_name => user.display_name, :id => client.id }, { :user => user }
135 assert_response :success
136 assert_template "edit"
137 assert_select "form", 1 do
138 assert_select "input#client_application_name", 1
139 assert_select "input#client_application_url", 1
140 assert_select "input#client_application_callback_url", 1
141 assert_select "input#client_application_support_url", 1
142 ClientApplication.all_permissions.each do |perm|
143 assert_select "input#client_application_#{perm}", 1
149 user = users(:public_user)
150 client = client_applications(:oauth_web_app)
152 put :update, :display_name => user.display_name, :id => client.id
153 assert_response :forbidden
155 put :update, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
156 assert_response :not_found
157 assert_template "not_found"
160 :display_name => user.display_name,
162 :client_application => {
167 assert_response :success
168 assert_template "edit"
171 :display_name => user.display_name,
173 :client_application => {
175 :url => "http://new.example.com/url"
178 assert_response :redirect
179 assert_redirected_to oauth_client_path(:id => client.id)
183 user = users(:public_user)
184 client = client_applications(:oauth_web_app)
186 assert_difference "ClientApplication.count", 0 do
187 delete :destroy, :display_name => user.display_name, :id => client.id
189 assert_response :forbidden
191 assert_difference "ClientApplication.count", 0 do
192 delete :destroy, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
194 assert_response :not_found
195 assert_template "not_found"
197 assert_difference "ClientApplication.count", -1 do
198 delete :destroy, { :display_name => user.display_name, :id => client.id }, { :user => user }
200 assert_response :redirect
201 assert_redirected_to oauth_clients_path(:display_name => user.display_name)