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)
42 :params => { :display_name => user.display_name }
43 assert_response :redirect
44 assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
47 :params => { :display_name => user.display_name },
48 :session => { :user => user }
49 assert_response :success
50 assert_template "index"
51 assert_select "div.client_application", 2
58 :params => { :display_name => user.display_name }
59 assert_response :redirect
60 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
63 :params => { :display_name => user.display_name },
64 :session => { :user => user }
65 assert_response :success
67 assert_select "form", 1 do
68 assert_select "input#client_application_name", 1
69 assert_select "input#client_application_url", 1
70 assert_select "input#client_application_callback_url", 1
71 assert_select "input#client_application_support_url", 1
72 ClientApplication.all_permissions.each do |perm|
73 assert_select "input#client_application_#{perm}", 1
81 assert_difference "ClientApplication.count", 0 do
82 post :create, :params => { :display_name => user.display_name }
84 assert_response :forbidden
86 assert_difference "ClientApplication.count", 0 do
88 :params => { :display_name => user.display_name,
89 :client_application => { :name => "Test Application" } },
90 :session => { :user => user }
92 assert_response :success
95 assert_difference "ClientApplication.count", 1 do
97 :params => { :display_name => user.display_name,
98 :client_application => { :name => "Test Application",
99 :url => "http://test.example.com/" } },
100 :session => { :user => user }
102 assert_response :redirect
103 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
108 client = create(:client_application, :user => user)
109 other_client = create(:client_application)
112 :params => { :display_name => user.display_name, :id => client.id }
113 assert_response :redirect
114 assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
117 :params => { :display_name => user.display_name, :id => other_client.id },
118 :session => { :user => user }
119 assert_response :not_found
120 assert_template "not_found"
123 :params => { :display_name => user.display_name, :id => client.id },
124 :session => { :user => user }
125 assert_response :success
126 assert_template "show"
131 client = create(:client_application, :user => user)
132 other_client = create(:client_application)
135 :params => { :display_name => user.display_name, :id => client.id }
136 assert_response :redirect
137 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
140 :params => { :display_name => user.display_name, :id => other_client.id },
141 :session => { :user => user }
142 assert_response :not_found
143 assert_template "not_found"
146 :params => { :display_name => user.display_name, :id => client.id },
147 :session => { :user => user }
148 assert_response :success
149 assert_template "edit"
150 assert_select "form", 1 do
151 assert_select "input#client_application_name", 1
152 assert_select "input#client_application_url", 1
153 assert_select "input#client_application_callback_url", 1
154 assert_select "input#client_application_support_url", 1
155 ClientApplication.all_permissions.each do |perm|
156 assert_select "input#client_application_#{perm}", 1
163 client = create(:client_application, :user => user)
164 other_client = create(:client_application)
167 :params => { :display_name => user.display_name, :id => client.id }
168 assert_response :forbidden
171 :params => { :display_name => user.display_name, :id => other_client.id },
172 :session => { :user => user }
173 assert_response :not_found
174 assert_template "not_found"
177 :params => { :display_name => user.display_name,
179 :client_application => { :name => "New Name", :url => nil } },
180 :session => { :user => user }
181 assert_response :success
182 assert_template "edit"
185 :params => { :display_name => user.display_name,
187 :client_application => { :name => "New Name", :url => "http://new.example.com/url" } },
188 :session => { :user => user }
189 assert_response :redirect
190 assert_redirected_to oauth_client_path(:id => client.id)
195 client = create(:client_application, :user => user)
196 other_client = create(:client_application)
198 assert_difference "ClientApplication.count", 0 do
200 :params => { :display_name => user.display_name, :id => client.id }
202 assert_response :forbidden
204 assert_difference "ClientApplication.count", 0 do
206 :params => { :display_name => user.display_name, :id => other_client.id },
207 :session => { :user => user }
209 assert_response :not_found
210 assert_template "not_found"
212 assert_difference "ClientApplication.count", -1 do
214 :params => { :display_name => user.display_name, :id => client.id },
215 :session => { :user => user }
217 assert_response :redirect
218 assert_redirected_to oauth_clients_path(:display_name => user.display_name)