1 require File.dirname(__FILE__) + '/../test_helper'
2 require File.dirname(__FILE__) + '/../oauth_controller_test_helper'
3 require 'oauth/client/action_controller_request'
5 class OauthClientsController; def rescue_action(e) raise e end; end
7 class OauthClientsControllerIndexTest < ActionController::TestCase
8 include OAuthControllerTestHelper
9 tests OauthClientsController
12 @controller = OauthClientsController.new
13 @request = ActionController::TestRequest.new
14 @response = ActionController::TestResponse.new
16 login_as_application_owner
23 def test_should_be_successful
25 assert @response.success?
28 def test_should_query_current_users_client_applications
29 @user.expects(:client_applications).returns(@client_applications)
33 def test_should_assign_client_applications
35 assert_equal @client_applications, assigns(:client_applications)
38 def test_should_render_index_template
40 assert_template 'index'
44 class OauthClientsControllerShowTest < ActionController::TestCase
45 include OAuthControllerTestHelper
46 tests OauthClientsController
49 @controller = OauthClientsController.new
50 @request = ActionController::TestRequest.new
51 @response = ActionController::TestResponse.new
53 login_as_application_owner
60 def test_should_be_successful
62 assert @response.success?
65 def test_should_query_current_users_client_applications
66 @user.expects(:client_applications).returns(@client_applications)
67 @client_applications.expects(:find).with('3').returns(@client_application)
71 def test_should_assign_client_applications
73 assert_equal @client_application, assigns(:client_application)
76 def test_should_render_show_template
78 assert_template 'show'
83 class OauthClientsControllerNewTest < ActionController::TestCase
84 include OAuthControllerTestHelper
85 tests OauthClientsController
88 @controller = OauthClientsController.new
89 @request = ActionController::TestRequest.new
90 @response = ActionController::TestResponse.new
92 login_as_application_owner
93 ClientApplication.stubs(:new).returns(@client_application)
100 def test_should_be_successful
102 assert @response.success?
105 def test_should_assign_client_applications
107 assert_equal @client_application, assigns(:client_application)
110 def test_should_render_show_template
112 assert_template 'new'
117 class OauthClientsControllerEditTest < ActionController::TestCase
118 include OAuthControllerTestHelper
119 tests OauthClientsController
122 @controller = OauthClientsController.new
123 @request = ActionController::TestRequest.new
124 @response = ActionController::TestResponse.new
126 login_as_application_owner
133 def test_should_be_successful
135 assert @response.success?
138 def test_should_query_current_users_client_applications
139 @user.expects(:client_applications).returns(@client_applications)
140 @client_applications.expects(:find).with('3').returns(@client_application)
144 def test_should_assign_client_applications
146 assert_equal @client_application, assigns(:client_application)
149 def test_should_render_edit_template
151 assert_template 'edit'
156 class OauthClientsControllerCreateTest < ActionController::TestCase
157 include OAuthControllerTestHelper
158 tests OauthClientsController
161 @controller = OauthClientsController.new
162 @request = ActionController::TestRequest.new
163 @response = ActionController::TestResponse.new
165 login_as_application_owner
166 @client_applications.stubs(:build).returns(@client_application)
167 @client_application.stubs(:save).returns(true)
171 @client_application.expects(:save).returns(true)
172 post :create,'client_application'=>{'name'=>'my site'}
176 @client_application.expects(:save).returns(false)
177 post :create,:client_application=>{:name=>'my site'}
180 def test_should_query_current_users_client_applications
181 @client_applications.expects(:build).returns(@client_application)
185 def test_should_redirect_to_new_client_application
187 assert_response :redirect
188 assert_redirected_to(:action => "show", :id => @client_application.id)
191 def test_should_assign_client_applications
193 assert_equal @client_application, assigns(:client_application)
196 def test_should_render_show_template
198 assert_template('new')
202 class OauthClientsControllerDestroyTest < ActionController::TestCase
203 include OAuthControllerTestHelper
204 tests OauthClientsController
207 @controller = OauthClientsController.new
208 @request = ActionController::TestRequest.new
209 @response = ActionController::TestResponse.new
211 login_as_application_owner
212 @client_application.stubs(:destroy)
216 delete :destroy,:id=>'3'
219 def test_should_query_current_users_client_applications
220 @user.expects(:client_applications).returns(@client_applications)
221 @client_applications.expects(:find).with('3').returns(@client_application)
225 def test_should_destroy_client_applications
226 @client_application.expects(:destroy)
230 def test_should_redirect_to_list
232 assert_response :redirect
233 assert_redirected_to :action => 'index'
238 class OauthClientsControllerUpdateTest < ActionController::TestCase
239 include OAuthControllerTestHelper
240 tests OauthClientsController
243 @controller = OauthClientsController.new
244 @request = ActionController::TestRequest.new
245 @response = ActionController::TestResponse.new
246 login_as_application_owner
250 @client_application.expects(:update_attributes).returns(true)
251 put :update, :id => '1', 'client_application' => {'name'=>'my site'}
254 def do_invalid_update
255 @client_application.expects(:update_attributes).returns(false)
256 put :update, :id=>'1', 'client_application' => {'name'=>'my site'}
259 def test_should_query_current_users_client_applications
260 @user.expects(:client_applications).returns(@client_applications)
261 @client_applications.expects(:find).with('1').returns(@client_application)
265 def test_should_redirect_to_new_client_application
267 assert_response :redirect
268 assert_redirected_to :action => "show", :id => @client_application.id
271 def test_should_assign_client_applications
273 assert_equal @client_application, assigns(:client_application)
276 def test_should_render_show_template
278 assert_template('edit')