Class: Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_model/have_secure_password_matcher.rb

Constant Summary collapse

CORRECT_PASSWORD =
'aBcDe12345'.freeze
INCORRECT_PASSWORD =
'password'.freeze
MESSAGES =
{
  authenticated_incorrect_password: 'expected %{subject} to not'\
    ' authenticate an incorrect %{attribute}',
  did_not_authenticate_correct_password: 'expected %{subject} to'\
    ' authenticate the correct %{attribute}',
  method_not_found: 'expected %{subject} to respond to %{methods}',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ HaveSecurePasswordMatcher

Returns a new instance of HaveSecurePasswordMatcher.



52
53
54
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 52

def initialize(attribute)
  @attribute = attribute.to_sym
end

Instance Attribute Details

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



39
40
41
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 39

def failure_message
  @failure_message
end

Instance Method Details

#descriptionObject



56
57
58
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 56

def description
  "have a secure password, defined on #{@attribute} attribute"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
# 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