mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
added update_without_password method
This commit is contained in:
parent
9cc69277bc
commit
8bdc4b544f
2 changed files with 25 additions and 1 deletions
|
@ -67,6 +67,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
|
||||
|
||||
|
|
|
@ -70,7 +70,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',
|
||||
|
@ -108,6 +108,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")
|
||||
|
|
Loading…
Reference in a new issue