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
- #failure_reason ⇒ Object
-
#initialize(attribute) ⇒ HaveReadonlyAttributeMatcher
constructor
A new instance of HaveReadonlyAttributeMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ HaveReadonlyAttributeMatcher
Returns a new instance of HaveReadonlyAttributeMatcher.
49 50 51 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 49 def initialize(attribute) @attribute = attribute.to_s end |
Instance Attribute Details
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
53 54 55 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 53 def @failure_message end |
#failure_message_when_negated ⇒ Object (readonly)
Returns the value of attribute failure_message_when_negated.
53 54 55 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 53 def @failure_message_when_negated end |
Instance Method Details
#description ⇒ Object
79 80 81 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 79 def description "make #{@attribute} read-only" end |
#failure_reason ⇒ Object
55 56 57 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 55 def failure_reason @failure_message end |
#matches?(subject) ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb', line 59 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 |