password_strength 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/password_strength/active_record.rb +2 -0
- data/lib/password_strength/active_record/ar2.rb +1 -1
- data/lib/password_strength/active_record/ar3.rb +1 -1
- data/lib/password_strength/locales/en.yml +5 -0
- data/lib/password_strength/locales/pt.yml +11 -0
- data/lib/password_strength/version.rb +1 -1
- data/test/active_record_test.rb +25 -4
- metadata +3 -1
@@ -16,7 +16,7 @@ module PasswordStrength
|
|
16
16
|
#
|
17
17
|
def validates_strength_of(*attr_names)
|
18
18
|
options = attr_names.extract_options!
|
19
|
-
options.reverse_merge!(:level => :good, :with => :username
|
19
|
+
options.reverse_merge!(:level => :good, :with => :username)
|
20
20
|
|
21
21
|
raise ArgumentError, "The :with option must be supplied" unless options.include?(:with)
|
22
22
|
raise ArgumentError, "The :level option must be one of [:weak, :good, :strong]" unless [:weak, :good, :strong].include?(options[:level])
|
@@ -2,7 +2,7 @@ module ActiveModel # :nodoc:
|
|
2
2
|
module Validations # :nodoc:
|
3
3
|
class StrengthValidator < EachValidator # :nodoc: all
|
4
4
|
def initialize(options)
|
5
|
-
super(options.reverse_merge(:level => :good, :with => :username
|
5
|
+
super(options.reverse_merge(:level => :good, :with => :username))
|
6
6
|
end
|
7
7
|
|
8
8
|
def validate_each(record, attribute, value)
|
data/test/active_record_test.rb
CHANGED
@@ -5,24 +5,45 @@ class TestActiveRecord < Test::Unit::TestCase
|
|
5
5
|
Object.class_eval { remove_const("User") } if defined?(User)
|
6
6
|
load "user.rb"
|
7
7
|
@user = User.new
|
8
|
+
I18n.locale = :en
|
8
9
|
end
|
9
10
|
|
10
11
|
def test_respond_to_validates_strength_of
|
11
12
|
assert User.respond_to?(:validates_strength_of)
|
12
13
|
end
|
13
14
|
|
15
|
+
def test_error_messages_in_pt
|
16
|
+
I18n.locale = :pt
|
17
|
+
User.validates_strength_of :password
|
18
|
+
@user.update_attributes :password => "123"
|
19
|
+
assert @user.errors.full_messages.include?("Password não é segura; utilize letras (maiúsculas e mínusculas), números e caracteres especiais")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_error_messages_in_en
|
23
|
+
I18n.locale = :en
|
24
|
+
User.validates_strength_of :password
|
25
|
+
@user.update_attributes :password => "123"
|
26
|
+
assert @user.errors.full_messages.include?("Password is not secure; use letters (uppercase and downcase), numbers and special characters")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_custom_error_message
|
30
|
+
User.validates_strength_of :password, :message => "is too weak"
|
31
|
+
@user.update_attributes :password => "123"
|
32
|
+
assert @user.errors.full_messages.include?("Password is too weak")
|
33
|
+
end
|
34
|
+
|
14
35
|
def test_defaults
|
15
36
|
User.validates_strength_of :password
|
16
37
|
|
17
38
|
@user.update_attributes :username => "johndoe", :password => "johndoe"
|
18
|
-
assert @user.errors.full_messages.
|
39
|
+
assert @user.errors.full_messages.any?
|
19
40
|
end
|
20
41
|
|
21
42
|
def test_strong_level
|
22
43
|
User.validates_strength_of :password, :level => :strong
|
23
44
|
|
24
45
|
@user.update_attributes :username => "johndoe", :password => "12345asdfg"
|
25
|
-
assert @user.errors.full_messages.
|
46
|
+
assert @user.errors.full_messages.any?
|
26
47
|
end
|
27
48
|
|
28
49
|
def test_weak_level
|
@@ -36,13 +57,13 @@ class TestActiveRecord < Test::Unit::TestCase
|
|
36
57
|
User.validates_strength_of :password, :with => :login
|
37
58
|
|
38
59
|
@user.update_attributes :login => "johndoe", :password => "johndoe"
|
39
|
-
assert @user.errors.full_messages.
|
60
|
+
assert @user.errors.full_messages.any?
|
40
61
|
end
|
41
62
|
|
42
63
|
def test_blank_username
|
43
64
|
User.validates_strength_of :password
|
44
65
|
|
45
66
|
@user.update_attributes :password => "johndoe"
|
46
|
-
assert @user.errors.full_messages.
|
67
|
+
assert @user.errors.full_messages.any?
|
47
68
|
end
|
48
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: password_strength
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- lib/password_strength/active_record/ar2.rb
|
42
42
|
- lib/password_strength/active_record/ar3.rb
|
43
43
|
- lib/password_strength/base.rb
|
44
|
+
- lib/password_strength/locales/en.yml
|
45
|
+
- lib/password_strength/locales/pt.yml
|
44
46
|
- lib/password_strength/version.rb
|
45
47
|
- test/active_record_test.rb
|
46
48
|
- test/jquery-1.4.2.js
|