Class: Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher
- Defined in:
- lib/shoulda/matchers/active_record/have_readonly_attribute_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
-
#initialize(attribute) ⇒ HaveReadonlyAttributeMatcher
constructor
A new instance of HaveReadonlyAttributeMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ HaveReadonlyAttributeMatcher
Returns a new instance of HaveReadonlyAttributeMatcher.
29 30 31 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 29 def initialize(attribute) @attribute = attribute.to_s end |
Instance Attribute Details
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
33 34 35 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 33 def @failure_message end |
#failure_message_when_negated ⇒ Object (readonly)
Returns the value of attribute failure_message_when_negated.
33 34 35 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 33 def @failure_message_when_negated end |
Instance Method Details
#description ⇒ Object
55 56 57 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 55 def description "make #{@attribute} read-only" end |
#matches?(subject) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 35 def matches?(subject) @subject = subject if readonly_attributes.include?(@attribute) @failure_message_when_negated = "Did not expect #{@attribute}"\ ' to be read-only' true else @failure_message = if readonly_attributes.empty? "#{class_name} attribute #{@attribute} " << 'is not read-only' else "#{class_name} is making " << "#{readonly_attributes.to_a.to_sentence} " << "read-only, but not #{@attribute}." end false end end |