Class: Shoulda::Matchers::ActiveRecord::EncryptMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::EncryptMatcher
- Defined in:
- lib/shoulda/matchers/active_record/encrypt_matcher.rb
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#failure_message_when_negated ⇒ Object
readonly
Returns the value of attribute failure_message_when_negated.
Instance Method Summary collapse
- #description ⇒ Object
- #deterministic(deterministic) ⇒ Object
- #downcase(downcase) ⇒ Object
- #ignore_case(ignore_case) ⇒ Object
-
#initialize(attribute) ⇒ EncryptMatcher
constructor
A new instance of EncryptMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ EncryptMatcher
Returns a new instance of EncryptMatcher.
79 80 81 82 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 79 def initialize(attribute) @attribute = attribute.to_sym @options = {} end |
Instance Attribute Details
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
84 85 86 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 84 def @failure_message end |
#failure_message_when_negated ⇒ Object (readonly)
Returns the value of attribute failure_message_when_negated.
84 85 86 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 84 def @failure_message_when_negated end |
Instance Method Details
#description ⇒ Object
125 126 127 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 125 def description "encrypt :#{@attribute}" end |
#deterministic(deterministic) ⇒ Object
86 87 88 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 86 def deterministic(deterministic) with_option(:deterministic, deterministic) end |
#downcase(downcase) ⇒ Object
90 91 92 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 90 def downcase(downcase) with_option(:downcase, downcase) end |
#ignore_case(ignore_case) ⇒ Object
94 95 96 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 94 def ignore_case(ignore_case) with_option(:ignore_case, ignore_case) end |
#matches?(subject) ⇒ Boolean
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/shoulda/matchers/active_record/encrypt_matcher.rb', line 98 def matches?(subject) @subject = subject result = encrypted_attributes_included? && ( :deterministic, :downcase, :ignore_case, ) if result @failure_message_when_negated = "Did not expect to #{description} of #{class_name}" if @options.present? @failure_message_when_negated += " using " @failure_message_when_negated += @options.map { |opt, expected| ":#{opt} option as ‹#{expected}›" }.join(' and ') end @failure_message_when_negated += ", but it did" end result end |