1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge pull request #1138 from fschwahn/update_without_password

added update_without_password method, closes #801
This commit is contained in:
José Valim 2011-06-15 10:45:18 -07:00
commit c0017ce76d
2 changed files with 25 additions and 1 deletions

View file

@ -68,6 +68,17 @@ module Devise
result
end
# Update record attributes without asking for the current password. Never allow to
# change the current password
def update_without_password(params={})
params.delete(:password)
params.delete(:password_confirmation)
result = update_attributes(params)
clean_up_passwords
result
end
def after_database_authentication
end

View file

@ -103,7 +103,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
:password => 'pass321', :password_confirmation => 'pass321')
assert user.reload.valid_password?('pass321')
end
test 'should add an error to current password when it is invalid' do
user = create_user
assert_not user.update_with_password(:current_password => 'other',
@ -141,6 +141,19 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert user.password_confirmation.blank?
end
test 'should update the user without password' do
user = create_user
user.update_without_password(:email => 'new@example.com')
assert_equal 'new@example.com', user.email
end
test 'should not update password without password' do
user = create_user
user.update_without_password(:password => 'pass321', :password_confirmation => 'pass321')
assert !user.reload.valid_password?('pass321')
assert user.valid_password?('123456')
end
test 'downcase_keys with validation' do
user = User.create(:email => "HEllO@example.com", :password => "123456")
user = User.create(:email => "HEllO@example.com", :password => "123456")