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)
40 create_list(:access_token, 2, :user => user)
43 :params => { :display_name => user.display_name }
44 assert_response :redirect
45 assert_redirected_to login_path(:referer => oauth_clients_path(:display_name => user.display_name))
48 :params => { :display_name => user.display_name },
49 :session => { :user => user }
50 assert_response :success
51 assert_template "index"
52 assert_select "div.client_application", 2
59 :params => { :display_name => user.display_name }
60 assert_response :redirect
61 assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))
64 :params => { :display_name => user.display_name },
65 :session => { :user => user }
66 assert_response :success
68 assert_select "form", 1 do
69 assert_select "input#client_application_name", 1
70 assert_select "input#client_application_url", 1
71 assert_select "input#client_application_callback_url", 1
72 assert_select "input#client_application_support_url", 1
73 ClientApplication.all_permissions.each do |perm|
74 assert_select "input#client_application_#{perm}", 1
82 assert_difference "ClientApplication.count", 0 do
83 post :create, :params => { :display_name => user.display_name }
85 assert_response :forbidden
87 assert_difference "ClientApplication.count", 0 do
89 :params => { :display_name => user.display_name,
90 :client_application => { :name => "Test Application" } },
91 :session => { :user => user }
93 assert_response :success
96 assert_difference "ClientApplication.count", 1 do
98 :params => { :display_name => user.display_name,
99 :client_application => { :name => "Test Application",
100 :url => "http://test.example.com/" } },
101 :session => { :user => user }
103 assert_response :redirect
104 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
109 client = create(:client_application, :user => user)
110 other_client = create(:client_application)
113 :params => { :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))
118 :params => { :display_name => user.display_name, :id => other_client.id },
119 :session => { :user => user }
120 assert_response :not_found
121 assert_template "not_found"
124 :params => { :display_name => user.display_name, :id => client.id },
125 :session => { :user => user }
126 assert_response :success
127 assert_template "show"
132 client = create(:client_application, :user => user)
133 other_client = create(:client_application)
136 :params => { :display_name => user.display_name, :id => client.id }
137 assert_response :redirect
138 assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
141 :params => { :display_name => user.display_name, :id => other_client.id },
142 :session => { :user => user }
143 assert_response :not_found
144 assert_template "not_found"
147 :params => { :display_name => user.display_name, :id => client.id },
148 :session => { :user => user }
149 assert_response :success
150 assert_template "edit"
151 assert_select "form", 1 do
152 assert_select "input#client_application_name", 1
153 assert_select "input#client_application_url", 1
154 assert_select "input#client_application_callback_url", 1
155 assert_select "input#client_application_support_url", 1
156 ClientApplication.all_permissions.each do |perm|
157 assert_select "input#client_application_#{perm}", 1
164 client = create(:client_application, :user => user)
165 other_client = create(:client_application)
168 :params => { :display_name => user.display_name, :id => client.id }
169 assert_response :forbidden
172 :params => { :display_name => user.display_name, :id => other_client.id },
173 :session => { :user => user }
174 assert_response :not_found
175 assert_template "not_found"
178 :params => { :display_name => user.display_name,
180 :client_application => { :name => "New Name", :url => nil } },
181 :session => { :user => user }
182 assert_response :success
183 assert_template "edit"
186 :params => { :display_name => user.display_name,
188 :client_application => { :name => "New Name", :url => "http://new.example.com/url" } },
189 :session => { :user => user }
190 assert_response :redirect
191 assert_redirected_to oauth_client_path(:id => client.id)
196 client = create(:client_application, :user => user)
197 other_client = create(:client_application)
199 assert_difference "ClientApplication.count", 0 do
201 :params => { :display_name => user.display_name, :id => client.id }
203 assert_response :forbidden
205 assert_difference "ClientApplication.count", 0 do
207 :params => { :display_name => user.display_name, :id => other_client.id },
208 :session => { :user => user }
210 assert_response :not_found
211 assert_template "not_found"
213 assert_difference "ClientApplication.count", -1 do
215 :params => { :display_name => user.display_name, :id => client.id },
216 :session => { :user => user }
218 assert_response :redirect
219 assert_redirected_to oauth_clients_path(:display_name => user.display_name)