mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Fix validating length of password.
This commit is contained in:
parent
b82717a96c
commit
ffc383953e
2 changed files with 11 additions and 1 deletions
|
@ -14,7 +14,7 @@ module Devise
|
|||
|
||||
validates_presence_of :password, :if => :password_required?
|
||||
validates_confirmation_of :password, :if => :password_required?
|
||||
validates_length_of :password, :within => 6..20, :allow_blank => true
|
||||
validates_length_of :password, :within => 6..20, :allow_blank => true, :if => :password_required?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -90,5 +90,15 @@ class ValidatableTest < ActiveSupport::TestCase
|
|||
assert user.errors[:password]
|
||||
assert_equal 'is too long (maximum is 20 characters)', user.errors[:password]
|
||||
end
|
||||
|
||||
test 'should not require password length when it\'s not changed' do
|
||||
user = create_user.reload
|
||||
user.password = user.password_confirmation = nil
|
||||
assert user.valid?
|
||||
user.password_confirmation = 'confirmation'
|
||||
assert user.invalid?
|
||||
assert user.errors[:password]
|
||||
assert_not user.errors[:password].to_a.include?('is too short (minimum is 6 characters)')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue