]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/clients_controller_test.rb
Revert "Switch to using oauth-plugin as a gem"
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / clients_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 require File.dirname(__FILE__) + '/../oauth_controller_test_helper'
3 require 'oauth/client/action_controller_request'
4
5 class OauthClientsController; def rescue_action(e) raise e end; end
6
7 class OauthClientsControllerIndexTest < ActionController::TestCase
8   include OAuthControllerTestHelper
9   tests OauthClientsController
10   
11   def setup    
12     @controller = OauthClientsController.new
13     @request    = ActionController::TestRequest.new
14     @response   = ActionController::TestResponse.new    
15     
16     login_as_application_owner
17   end
18   
19   def do_get
20     get :index
21   end
22   
23   def test_should_be_successful
24     do_get
25     assert @response.success?
26   end
27   
28   def test_should_query_current_users_client_applications
29     @user.expects(:client_applications).returns(@client_applications)
30     do_get
31   end
32   
33   def test_should_assign_client_applications
34     do_get
35     assert_equal @client_applications, assigns(:client_applications)
36   end
37   
38   def test_should_render_index_template
39     do_get
40     assert_template 'index'
41   end
42 end
43
44 class OauthClientsControllerShowTest < ActionController::TestCase
45   include OAuthControllerTestHelper
46   tests OauthClientsController
47   
48   def setup
49     @controller = OauthClientsController.new
50     @request    = ActionController::TestRequest.new
51     @response   = ActionController::TestResponse.new    
52     
53     login_as_application_owner
54   end
55   
56   def do_get
57     get :show, :id=>'3'
58   end
59   
60   def test_should_be_successful
61     do_get
62     assert @response.success?
63   end
64   
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)
68     do_get
69   end
70   
71   def test_should_assign_client_applications
72     do_get
73     assert_equal @client_application, assigns(:client_application)
74   end
75   
76   def test_should_render_show_template
77     do_get
78     assert_template 'show'
79   end
80   
81 end
82
83 class OauthClientsControllerNewTest < ActionController::TestCase
84   include OAuthControllerTestHelper
85   tests OauthClientsController
86
87   def setup
88     @controller = OauthClientsController.new
89     @request    = ActionController::TestRequest.new
90     @response   = ActionController::TestResponse.new    
91     
92     login_as_application_owner
93     ClientApplication.stubs(:new).returns(@client_application)
94   end
95   
96   def do_get
97     get :new
98   end
99   
100   def test_should_be_successful
101     do_get
102     assert @response.success?
103   end
104   
105   def test_should_assign_client_applications
106     do_get
107     assert_equal @client_application, assigns(:client_application)
108   end
109   
110   def test_should_render_show_template
111     do_get
112     assert_template 'new'
113   end
114   
115 end
116  
117 class OauthClientsControllerEditTest < ActionController::TestCase
118   include OAuthControllerTestHelper
119   tests OauthClientsController
120   
121   def setup
122     @controller = OauthClientsController.new
123     @request    = ActionController::TestRequest.new
124     @response   = ActionController::TestResponse.new    
125
126     login_as_application_owner
127   end
128   
129   def do_get
130     get :edit, :id=>'3'
131   end
132   
133   def test_should_be_successful
134     do_get
135     assert @response.success?
136   end
137   
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)
141     do_get
142   end
143   
144   def test_should_assign_client_applications
145     do_get
146     assert_equal @client_application, assigns(:client_application)
147   end
148   
149   def test_should_render_edit_template
150     do_get
151     assert_template 'edit'
152   end
153   
154 end
155
156 class OauthClientsControllerCreateTest < ActionController::TestCase
157   include OAuthControllerTestHelper
158   tests OauthClientsController
159   
160   def setup
161     @controller = OauthClientsController.new
162     @request    = ActionController::TestRequest.new
163     @response   = ActionController::TestResponse.new    
164     
165     login_as_application_owner
166     @client_applications.stubs(:build).returns(@client_application)
167     @client_application.stubs(:save).returns(true)
168   end
169   
170   def do_valid_post
171     @client_application.expects(:save).returns(true)
172     post :create,'client_application'=>{'name'=>'my site'}
173   end
174
175   def do_invalid_post
176     @client_application.expects(:save).returns(false)
177     post :create,:client_application=>{:name=>'my site'}
178   end
179   
180   def test_should_query_current_users_client_applications
181     @client_applications.expects(:build).returns(@client_application)
182     do_valid_post
183   end
184   
185   def test_should_redirect_to_new_client_application
186     do_valid_post
187     assert_response :redirect
188     assert_redirected_to(:action => "show", :id => @client_application.id)
189   end
190   
191   def test_should_assign_client_applications
192     do_invalid_post
193     assert_equal @client_application, assigns(:client_application)
194   end
195   
196   def test_should_render_show_template
197     do_invalid_post
198     assert_template('new')
199   end
200 end
201  
202 class OauthClientsControllerDestroyTest < ActionController::TestCase
203   include OAuthControllerTestHelper
204   tests OauthClientsController
205   
206   def setup
207     @controller = OauthClientsController.new
208     @request    = ActionController::TestRequest.new
209     @response   = ActionController::TestResponse.new
210     
211     login_as_application_owner
212     @client_application.stubs(:destroy)
213   end
214   
215   def do_delete
216     delete :destroy,:id=>'3'
217   end
218     
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)
222     do_delete
223   end
224
225   def test_should_destroy_client_applications
226     @client_application.expects(:destroy)
227     do_delete
228   end
229     
230   def test_should_redirect_to_list
231     do_delete
232     assert_response :redirect
233     assert_redirected_to :action => 'index'
234   end
235   
236 end
237
238 class OauthClientsControllerUpdateTest < ActionController::TestCase
239   include OAuthControllerTestHelper
240   tests OauthClientsController
241
242   def setup
243     @controller = OauthClientsController.new
244     @request    = ActionController::TestRequest.new
245     @response   = ActionController::TestResponse.new
246     login_as_application_owner
247   end
248   
249   def do_valid_update
250     @client_application.expects(:update_attributes).returns(true)
251     put :update, :id => '1', 'client_application' => {'name'=>'my site'}
252   end
253
254   def do_invalid_update
255     @client_application.expects(:update_attributes).returns(false)
256     put :update, :id=>'1', 'client_application' => {'name'=>'my site'}
257   end
258   
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)
262     do_valid_update
263   end
264   
265   def test_should_redirect_to_new_client_application
266     do_valid_update
267     assert_response :redirect
268     assert_redirected_to :action => "show", :id => @client_application.id
269   end
270   
271   def test_should_assign_client_applications
272     do_invalid_update
273     assert_equal @client_application, assigns(:client_application)
274   end
275   
276   def test_should_render_show_template
277     do_invalid_update
278     assert_template('edit')
279   end
280 end