Skip to content

Commit

Permalink
Fixed issue with PasswordStrength.enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Aug 12, 2010
1 parent e7e4818 commit 6570309
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/password_strength/active_record/ar2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def validates_strength_of(*attr_names)
raise ArgumentError, "The :level option must be one of [:weak, :good, :strong]" unless [:weak, :good, :strong].include?(options[:level])

validates_each(attr_names, options) do |record, attr_name, value|
next unless PasswordStrength.enabled

strength = options[:using].new(record.send(options[:with]), value, :exclude => options[:exclude])
strength.test
record.errors.add(attr_name, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
record.errors.add(attr_name, :too_weak, options) unless strength.valid?(options[:level])
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/password_strength/active_record/ar3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def initialize(options)
end

def validate_each(record, attribute, value)
return unless PasswordStrength.enabled
strength = options[:using].new(record.send(options[:with]), value, :exclude => options[:exclude])
strength.test
record.errors.add(attribute, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
Expand Down
1 change: 1 addition & 0 deletions test/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_exclude_option
end

def test_ignore_validations_when_password_strength_is_disabled
User.validates_strength_of :password
PasswordStrength.enabled = false
@user.update_attributes :password => ""
assert @user.valid?
Expand Down

0 comments on commit 6570309

Please sign in to comment.