3 class OauthClientsControllerTest < ActionDispatch::IntegrationTest
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)
42 get oauth_clients_path(user)
43 assert_redirected_to login_path(:referer => oauth_clients_path(user))
47 get oauth_clients_path(user)
48 assert_response :success
49 assert_template "index"
50 assert_select "li.client_application", 2
56 get new_oauth_client_path(user)
57 assert_redirected_to login_path(:referer => new_oauth_client_path(user))
61 get new_oauth_client_path(user)
62 assert_response :success
64 assert_select "form", 1 do
65 assert_select "input#client_application_name", 1
66 assert_select "input#client_application_url", 1
67 assert_select "input#client_application_callback_url", 1
68 assert_select "input#client_application_support_url", 1
69 ClientApplication.all_permissions.each do |perm|
70 assert_select "input#client_application_#{perm}", 1
78 with_settings(:oauth_10_registration => false) do
79 get new_oauth_client_path(user)
80 assert_redirected_to login_path(:referer => new_oauth_client_path(user))
84 get new_oauth_client_path(user)
85 assert_redirected_to oauth_clients_path(user)
92 assert_difference "ClientApplication.count", 0 do
93 post oauth_clients_path(user)
95 assert_response :forbidden
99 assert_difference "ClientApplication.count", 0 do
100 post oauth_clients_path(user, :client_application => { :name => "Test Application" })
102 assert_response :success
103 assert_template "new"
105 assert_difference "ClientApplication.count", 1 do
106 post oauth_clients_path(user, :client_application => { :name => "Test Application",
107 :url => "http://test.example.com/" })
109 assert_redirected_to oauth_client_path(:id => ClientApplication.find_by(:name => "Test Application").id)
114 client = create(:client_application, :user => user)
115 other_client = create(:client_application)
117 get oauth_client_path(user, client)
118 assert_redirected_to login_path(:referer => oauth_client_path(user, client.id))
122 get oauth_client_path(user, other_client)
123 assert_response :not_found
124 assert_template "not_found"
126 get oauth_client_path(user, client)
127 assert_response :success
128 assert_template "show"
133 client = create(:client_application, :user => user)
134 other_client = create(:client_application)
136 get edit_oauth_client_path(user, client)
137 assert_redirected_to login_path(:referer => edit_oauth_client_path(user, client.id))
141 get edit_oauth_client_path(user, other_client)
142 assert_response :not_found
143 assert_template "not_found"
145 get edit_oauth_client_path(user, client)
146 assert_response :success
147 assert_template "edit"
148 assert_select "form", 1 do
149 assert_select "input#client_application_name", 1
150 assert_select "input#client_application_url", 1
151 assert_select "input#client_application_callback_url", 1
152 assert_select "input#client_application_support_url", 1
153 ClientApplication.all_permissions.each do |perm|
154 assert_select "input#client_application_#{perm}", 1
161 client = create(:client_application, :user => user)
162 other_client = create(:client_application)
164 put oauth_client_path(user, client)
165 assert_response :forbidden
169 put oauth_client_path(user, other_client)
170 assert_response :not_found
171 assert_template "not_found"
173 put oauth_client_path(user, client, :client_application => { :name => "New Name", :url => nil })
174 assert_response :success
175 assert_template "edit"
177 put oauth_client_path(user, client, :client_application => { :name => "New Name", :url => "http://new.example.com/url" })
178 assert_redirected_to oauth_client_path(:id => client.id)
183 client = create(:client_application, :user => user)
184 other_client = create(:client_application)
186 assert_difference "ClientApplication.count", 0 do
187 delete oauth_client_path(user, client)
189 assert_response :forbidden
193 assert_difference "ClientApplication.count", 0 do
194 delete oauth_client_path(user, other_client)
196 assert_response :not_found
197 assert_template "not_found"
199 assert_difference "ClientApplication.count", -1 do
200 delete oauth_client_path(user, client)
202 assert_redirected_to oauth_clients_path(user)