aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/lib/active_model/secure_password.rb6
-rw-r--r--activemodel/test/cases/secure_password_test.rb4
2 files changed, 6 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb
index 54191f41df..3e7d3174ac 100644
--- a/activemodel/lib/active_model/secure_password.rb
+++ b/activemodel/lib/active_model/secure_password.rb
@@ -62,9 +62,9 @@ module ActiveModel
private
def password_must_be_strong
- if @password.present?
- errors.add(:password, "must be longer than 6 characters") unless @password.size > 6
- errors.add(:password, "is a too weak and common") if WEAK_PASSWORDS.include?(@password)
+ if password.present?
+ errors.add(:password, "must be longer than 6 characters") unless password.size > 6
+ errors.add(:password, "is too weak and common") if WEAK_PASSWORDS.include?(password)
end
end
end
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb
index 62fffce233..c46a092d2d 100644
--- a/activemodel/test/cases/secure_password_test.rb
+++ b/activemodel/test/cases/secure_password_test.rb
@@ -34,11 +34,13 @@ class SecurePasswordTest < ActiveModel::TestCase
end
test "too weak passwords" do
- @user.password = "123456"
+ @user.password = "012345"
assert !@user.valid?
+ assert_equal ["must be longer than 6 characters"], @user.errors[:password]
@user.password = "password"
assert !@user.valid?
+ assert_equal ["is too weak and common"], @user.errors[:password]
@user.password = "d9034rfjlakj34RR$!!"
assert @user.valid?