class Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher
@private
Constants
- CORRECT_PASSWORD
- EXPECTED_METHODS
- INCORRECT_PASSWORD
- MESSAGES
Attributes
failure_message[R]
failure_message_for_should[R]
subject[R]
Public Instance Methods
description()
click to toggle source
# File lib/shoulda/matchers/active_model/have_secure_password_matcher.rb, line 56 def description "have a secure password" end
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_model/have_secure_password_matcher.rb, line 60 def matches?(subject) @subject = subject if failure = validate key, params = failure @failure_message = MESSAGES[key] % { subject: subject.class }.merge(params) end failure.nil? end
Protected Instance Methods
validate()
click to toggle source
# File lib/shoulda/matchers/active_model/have_secure_password_matcher.rb, line 75 def validate missing_methods = EXPECTED_METHODS.select {|m| !subject.respond_to?(m) } if missing_methods.present? [:method_not_found, { methods: missing_methods.to_sentence }] else subject.password = CORRECT_PASSWORD subject.password_confirmation = CORRECT_PASSWORD if not subject.authenticate(CORRECT_PASSWORD) [:did_not_authenticate_correct_password, {}] elsif subject.authenticate(INCORRECT_PASSWORD) [:authenticated_incorrect_password, {}] end end end