class Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher
@private
Attributes
Public Class Methods
Source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 29 def initialize(attribute) @attribute = attribute.to_s end
Public Instance Methods
Source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 55 def description "make #{@attribute} read-only" end
Source
# 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
Private Instance Methods
Source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 65 def class_name @subject.class.name end
Source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 61 def readonly_attributes @_readonly_attributes ||= (@subject.class.readonly_attributes || []) end