Mercurial > hg > soundsoftware-site
comparison test/functional/users_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
19 require 'users_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class UsersController; def rescue_action(e) raise e end; end | |
23 | 19 |
24 class UsersControllerTest < ActionController::TestCase | 20 class UsersControllerTest < ActionController::TestCase |
25 include Redmine::I18n | 21 include Redmine::I18n |
26 | 22 |
27 fixtures :users, :projects, :members, :member_roles, :roles, | 23 fixtures :users, :projects, :members, :member_roles, :roles, |
28 :custom_fields, :custom_values, :groups_users, | 24 :custom_fields, :custom_values, :groups_users, |
29 :auth_sources | 25 :auth_sources |
30 | 26 |
31 def setup | 27 def setup |
32 @controller = UsersController.new | |
33 @request = ActionController::TestRequest.new | |
34 @response = ActionController::TestResponse.new | |
35 User.current = nil | 28 User.current = nil |
36 @request.session[:user_id] = 1 # admin | 29 @request.session[:user_id] = 1 # admin |
37 end | |
38 | |
39 def test_index | |
40 get :index | |
41 assert_response :success | |
42 assert_template 'index' | |
43 end | 30 end |
44 | 31 |
45 def test_index | 32 def test_index |
46 get :index | 33 get :index |
47 assert_response :success | 34 assert_response :success |
223 assert_equal 'Paris', user.pref.time_zone | 210 assert_equal 'Paris', user.pref.time_zone |
224 assert_equal 'desc', user.pref[:comments_sorting] | 211 assert_equal 'desc', user.pref[:comments_sorting] |
225 assert_equal '0', user.pref[:warn_on_leaving_unsaved] | 212 assert_equal '0', user.pref[:warn_on_leaving_unsaved] |
226 end | 213 end |
227 | 214 |
215 def test_create_with_generate_password_should_email_the_password | |
216 assert_difference 'User.count' do | |
217 post :create, :user => { | |
218 :login => 'randompass', | |
219 :firstname => 'Random', | |
220 :lastname => 'Pass', | |
221 :mail => 'randompass@example.net', | |
222 :language => 'en', | |
223 :generate_password => '1', | |
224 :password => '', | |
225 :password_confirmation => '' | |
226 }, :send_information => 1 | |
227 end | |
228 user = User.order('id DESC').first | |
229 assert_equal 'randompass', user.login | |
230 | |
231 mail = ActionMailer::Base.deliveries.last | |
232 assert_not_nil mail | |
233 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/) | |
234 assert m | |
235 password = m[1] | |
236 assert user.check_password?(password) | |
237 end | |
238 | |
228 def test_create_with_failure | 239 def test_create_with_failure |
229 assert_no_difference 'User.count' do | 240 assert_no_difference 'User.count' do |
230 post :create, :user => {} | 241 post :create, :user => {} |
231 end | 242 end |
232 assert_response :success | 243 assert_response :success |
295 assert_not_nil mail | 306 assert_not_nil mail |
296 assert_equal [u.mail], mail.bcc | 307 assert_equal [u.mail], mail.bcc |
297 assert_mail_body_match 'newpass123', mail | 308 assert_mail_body_match 'newpass123', mail |
298 end | 309 end |
299 | 310 |
311 def test_update_with_generate_password_should_email_the_password | |
312 ActionMailer::Base.deliveries.clear | |
313 Setting.bcc_recipients = '1' | |
314 | |
315 put :update, :id => 2, :user => { | |
316 :generate_password => '1', | |
317 :password => '', | |
318 :password_confirmation => '' | |
319 }, :send_information => '1' | |
320 | |
321 mail = ActionMailer::Base.deliveries.last | |
322 assert_not_nil mail | |
323 m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/) | |
324 assert m | |
325 password = m[1] | |
326 assert User.find(2).check_password?(password) | |
327 end | |
328 | |
329 def test_update_without_generate_password_should_not_change_password | |
330 put :update, :id => 2, :user => { | |
331 :firstname => 'changed', | |
332 :generate_password => '0', | |
333 :password => '', | |
334 :password_confirmation => '' | |
335 }, :send_information => '1' | |
336 | |
337 user = User.find(2) | |
338 assert_equal 'changed', user.firstname | |
339 assert user.check_password?('jsmith') | |
340 end | |
341 | |
300 def test_update_user_switchin_from_auth_source_to_password_authentication | 342 def test_update_user_switchin_from_auth_source_to_password_authentication |
301 # Configure as auth source | 343 # Configure as auth source |
302 u = User.find(2) | 344 u = User.find(2) |
303 u.auth_source = AuthSource.find(1) | 345 u.auth_source = AuthSource.find(1) |
304 u.save! | 346 u.save! |
314 assert_response :success | 356 assert_response :success |
315 assert_template 'edit' | 357 assert_template 'edit' |
316 u = User.find(2) | 358 u = User.find(2) |
317 assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort | 359 assert_equal [1, 2, 5], u.projects.collect{|p| p.id}.sort |
318 assert_equal [1, 2, 5], u.notified_projects_ids.sort | 360 assert_equal [1, 2, 5], u.notified_projects_ids.sort |
319 assert_tag :tag => 'input', | 361 assert_select 'input[name=?][value=?]', 'user[notified_project_ids][]', '1' |
320 :attributes => { | |
321 :id => 'notified_project_ids_', | |
322 :value => 1, | |
323 } | |
324 assert_equal 'all', u.mail_notification | 362 assert_equal 'all', u.mail_notification |
325 put :update, :id => 2, | 363 put :update, :id => 2, |
326 :user => { | 364 :user => { |
327 :mail_notification => 'selected', | 365 :mail_notification => 'selected', |
328 }, | 366 :notified_project_ids => [1, 2] |
329 :notified_project_ids => [1, 2] | 367 } |
330 u = User.find(2) | 368 u = User.find(2) |
331 assert_equal 'selected', u.mail_notification | 369 assert_equal 'selected', u.mail_notification |
332 assert_equal [1, 2], u.notified_projects_ids.sort | 370 assert_equal [1, 2], u.notified_projects_ids.sort |
371 end | |
372 | |
373 def test_update_status_should_not_update_attributes | |
374 user = User.find(2) | |
375 user.pref[:no_self_notified] = '1' | |
376 user.pref.save | |
377 | |
378 put :update, :id => 2, :user => {:status => 3} | |
379 assert_response 302 | |
380 user = User.find(2) | |
381 assert_equal 3, user.status | |
382 assert_equal '1', user.pref[:no_self_notified] | |
333 end | 383 end |
334 | 384 |
335 def test_destroy | 385 def test_destroy |
336 assert_difference 'User.count', -1 do | 386 assert_difference 'User.count', -1 do |
337 delete :destroy, :id => 2 | 387 delete :destroy, :id => 2 |