diff options
Diffstat (limited to 'test/functional/users_controller_test.rb')
-rw-r--r-- | test/functional/users_controller_test.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 37e58d500..65aa2d7c0 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -218,6 +218,30 @@ class UsersControllerTest < ActionController::TestCase assert_equal '0', user.pref[:warn_on_leaving_unsaved] end + def test_create_with_generate_password_should_email_the_password + assert_difference 'User.count' do + post :create, :user => { + :login => 'randompass', + :firstname => 'Random', + :lastname => 'Pass', + :mail => 'randompass@example.net', + :language => 'en', + :generate_password => '1', + :password => '', + :password_confirmation => '' + }, :send_information => 1 + end + user = User.order('id DESC').first + assert_equal 'randompass', user.login + + mail = ActionMailer::Base.deliveries.last + assert_not_nil mail + m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/) + assert m + password = m[1] + assert user.check_password?(password) + end + def test_create_with_failure assert_no_difference 'User.count' do post :create, :user => {} @@ -290,6 +314,37 @@ class UsersControllerTest < ActionController::TestCase assert_mail_body_match 'newpass123', mail end + def test_update_with_generate_password_should_email_the_password + ActionMailer::Base.deliveries.clear + Setting.bcc_recipients = '1' + + put :update, :id => 2, :user => { + :generate_password => '1', + :password => '', + :password_confirmation => '' + }, :send_information => '1' + + mail = ActionMailer::Base.deliveries.last + assert_not_nil mail + m = mail_body(mail).match(/Password: ([a-zA-Z0-9]+)/) + assert m + password = m[1] + assert User.find(2).check_password?(password) + end + + def test_update_without_generate_password_should_not_change_password + put :update, :id => 2, :user => { + :firstname => 'changed', + :generate_password => '0', + :password => '', + :password_confirmation => '' + }, :send_information => '1' + + user = User.find(2) + assert_equal 'changed', user.firstname + assert user.check_password?('jsmith') + end + def test_update_user_switchin_from_auth_source_to_password_authentication # Configure as auth source u = User.find(2) |