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}',
  should_not_have_secure_password: 'expected %{subject} to'\
    ' not %{description}!',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ HaveSecurePasswordMatcher

Returns a new instance of HaveSecurePasswordMatcher.



54
55
56
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 54

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



58
59
60
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 58

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

#failure_message_when_negatedObject



74
75
76
77
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 74

def failure_message_when_negated
  MESSAGES[:should_not_have_secure_password] %
    { subject: @subject.class, description: }
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 62

def matches?(subject)
  @subject = subject

  if failure = validate
    key, params = failure
    @failure_message =
      MESSAGES[key] % { subject: subject.class }.merge(params)
  end

  failure.nil?
end