Class: Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveModel::HaveSecurePasswordMatcher
- 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
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attribute) ⇒ HaveSecurePasswordMatcher
constructor
A new instance of HaveSecurePasswordMatcher.
- #matches?(subject) ⇒ Boolean
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_message ⇒ Object (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 end |
Instance Method Details
#description ⇒ Object
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_negated ⇒ Object
74 75 76 77 |
# File 'lib/shoulda/matchers/active_model/have_secure_password_matcher.rb', line 74 def MESSAGES[:should_not_have_secure_password] % { subject: @subject.class, description: } end |
#matches?(subject) ⇒ 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 = MESSAGES[key] % { subject: subject.class }.merge(params) end failure.nil? end |