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}', }.freeze
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(attribute) ⇒ HaveSecurePasswordMatcher
constructor
A new instance of HaveSecurePasswordMatcher.
- #matches?(subject) ⇒ Boolean
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_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 @failure_message end |
Instance Method Details
#description ⇒ Object
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
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 |