3 class OauthClientsControllerTest < ActionController::TestCase
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)
41 get :index, :display_name => user.display_name
42 assert_response :redirect
43 assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
45 get :index, { :display_name => user.display_name }, { :user => user }
46 assert_response :success
47 assert_template "index"
48 assert_select "div.client_application", 2
54 get :new, :display_name => user.display_name
55 assert_response :redirect
56 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
58 get :new, { :display_name => user.display_name }, { :user => user }
59 assert_response :success
61 assert_select "form", 1 do
62 assert_select "input#client_application_name", 1
63 assert_select "input#client_application_url", 1
64 assert_select "input#client_application_callback_url", 1
65 assert_select "input#client_application_support_url", 1
66 ClientApplication.all_permissions.each do |perm|
67 assert_select "input#client_application_#{perm}", 1
75 assert_difference "ClientApplication.count", 0 do
76 post :create, :display_name => user.display_name
78 assert_response :forbidden
80 assert_difference "ClientApplication.count", 0 do
82 :display_name => user.display_name,
83 :client_application => {
84 :name => "Test Application"
88 assert_response :success
91 assert_difference "ClientApplication.count", 1 do
93 :display_name => user.display_name,
94 :client_application => {
95 :name => "Test Application",
96 :url => "http://test.example.com/"
100 assert_response :redirect
101 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
106 client = create(:client_application, :user => user)
107 other_client = create(:client_application)
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 => other_client.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"
124 client = create(:client_application, :user => user)
125 other_client = create(:client_application)
127 get :edit, :display_name => user.display_name, :id => client.id
128 assert_response :redirect
129 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
131 get :edit, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
132 assert_response :not_found
133 assert_template "not_found"
135 get :edit, { :display_name => user.display_name, :id => client.id }, { :user => user }
136 assert_response :success
137 assert_template "edit"
138 assert_select "form", 1 do
139 assert_select "input#client_application_name", 1
140 assert_select "input#client_application_url", 1
141 assert_select "input#client_application_callback_url", 1
142 assert_select "input#client_application_support_url", 1
143 ClientApplication.all_permissions.each do |perm|
144 assert_select "input#client_application_#{perm}", 1
151 client = create(:client_application, :user => user)
152 other_client = create(:client_application)
154 put :update, :display_name => user.display_name, :id => client.id
155 assert_response :forbidden
157 put :update, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
158 assert_response :not_found
159 assert_template "not_found"
162 :display_name => user.display_name,
164 :client_application => {
169 assert_response :success
170 assert_template "edit"
173 :display_name => user.display_name,
175 :client_application => {
177 :url => "http://new.example.com/url"
180 assert_response :redirect
181 assert_redirected_to oauth_client_path(:id => client.id)
186 client = create(:client_application, :user => user)
187 other_client = create(:client_application)
189 assert_difference "ClientApplication.count", 0 do
190 delete :destroy, :display_name => user.display_name, :id => client.id
192 assert_response :forbidden
194 assert_difference "ClientApplication.count", 0 do
195 delete :destroy, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
197 assert_response :not_found
198 assert_template "not_found"
200 assert_difference "ClientApplication.count", -1 do
201 delete :destroy, { :display_name => user.display_name, :id => client.id }, { :user => user }
203 assert_response :redirect
204 assert_redirected_to oauth_clients_path(:display_name => user.display_name)