password_required? should not affect length validation, closes #1037.
This commit is contained in:
parent
b1a27ad633
commit
a59410a254
|
@ -1,6 +1,9 @@
|
||||||
* enhancements
|
* enhancements
|
||||||
* Improve e-mail regexp (by github.com/rodrigoflores)
|
* Improve e-mail regexp (by github.com/rodrigoflores)
|
||||||
|
|
||||||
|
* bug fix
|
||||||
|
* password_required? should not affect length validation
|
||||||
|
|
||||||
== 1.3.3
|
== 1.3.3
|
||||||
|
|
||||||
* bug fix
|
* bug fix
|
||||||
|
|
|
@ -26,11 +26,9 @@ module Devise
|
||||||
validates_uniqueness_of :email, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true
|
validates_uniqueness_of :email, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true
|
||||||
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
||||||
|
|
||||||
with_options :if => :password_required? do |v|
|
validates_presence_of :password, :if => :password_required?
|
||||||
v.validates_presence_of :password
|
validates_confirmation_of :password, :if => :password_required?
|
||||||
v.validates_confirmation_of :password
|
validates_length_of :password, :within => password_length, :allow_blank => true
|
||||||
v.validates_length_of :password, :within => password_length, :allow_blank => true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,13 @@ class ValidatableTest < ActiveSupport::TestCase
|
||||||
assert_not (user.errors[:password].join =~ /is too long/)
|
assert_not (user.errors[:password].join =~ /is too long/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should complain about length even if possword is not required' do
|
||||||
|
user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
|
||||||
|
user.stubs(:password_required?).returns(false)
|
||||||
|
assert user.invalid?
|
||||||
|
assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
|
||||||
|
end
|
||||||
|
|
||||||
test 'shuold not be included in objects with invalid API' do
|
test 'shuold not be included in objects with invalid API' do
|
||||||
assert_raise RuntimeError do
|
assert_raise RuntimeError do
|
||||||
Class.new.send :include, Devise::Models::Validatable
|
Class.new.send :include, Devise::Models::Validatable
|
||||||
|
|
Loading…
Reference in New Issue