Permalink
Browse files

Fixes #2 nil error in password strength validation and bump to 0.0.3

  • Loading branch information...
1 parent 42a176c commit 4bddf15aba10d0d59783ef0b94da6d630975c398 Brian McManus committed Jun 27, 2013
@@ -4,9 +4,9 @@ module ActiveModel
module Validations
class PasswordStrengthValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
- ps = ::StrongPassword::StrengthChecker.new(value)
+ ps = ::StrongPassword::StrengthChecker.new(value.to_s)
unless ps.is_strong?(strength_options(options, object))
- object.errors.add(attribute, :'password.password_strength', options.merge(:value => value))
+ object.errors.add(attribute, :'password.password_strength', options.merge(:value => value.to_s))
end
end
@@ -28,7 +28,7 @@ def extra_words_for_object(extra_words, object)
extra_words || []
end
end
-
+
module HelperMethods
# class User < ActiveRecord::Base
# validates_password_strength :password
@@ -1,3 +1,3 @@
module StrongPassword
- VERSION = "0.0.2"
+ VERSION = "0.0.3"
end
@@ -9,7 +9,7 @@ class TestBaseStrength < User
validates :password, password_strength: true
end
-class TestStrengthWeakEntropy< User
+class TestStrengthWeakEntropy < User
validates :password, password_strength: {min_entropy: 1, use_dictionary: true}
end
@@ -33,11 +33,12 @@ module Validations
let(:strong_entropy) { TestStrengthStrongEntropy.new }
let(:extra_words) { TestStrengthExtraWords.new }
let(:alternative_usage) { TestBaseStrengthAlternative.new }
-
+
describe 'validations' do
describe 'base strength' do
describe 'invalid' do
[
+ nil,
'password',
'1234',
'f0bar',
@@ -50,7 +51,7 @@ module Validations
end
end
end
-
+
describe 'valid' do
[
'p@ssw0fdsafsdafrd',
@@ -66,7 +67,7 @@ module Validations
end
end
end
-
+
describe 'alternative usage' do
describe 'invalid' do
[
@@ -82,7 +83,7 @@ module Validations
end
end
end
-
+
describe 'valid' do
[
'p@ssw0fdsafsdafrd',
@@ -98,7 +99,7 @@ module Validations
end
end
end
-
+
describe 'entropy override' do
describe 'lowered entropy' do
describe 'valid' do
@@ -116,7 +117,7 @@ module Validations
end
end
end
-
+
describe 'increased entropy' do
describe 'valid' do
[
@@ -134,7 +135,7 @@ module Validations
end
end
end
-
+
describe 'extra words' do
it 'allows extra words to be specified as an option to the validation' do
password = 'mcmanus'

0 comments on commit 4bddf15

Please sign in to comment.