class Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher

@private

Attributes

failure_message[R]
failure_message_when_negated[R]

Public Class Methods

new(attribute) click to toggle 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

description() click to toggle source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 55
def description
  "make #{@attribute} read-only"
end
matches?(subject) click to toggle 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

class_name() click to toggle source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 65
def class_name
  @subject.class.name
end
readonly_attributes() click to toggle source
# File lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb, line 61
def readonly_attributes
  @_readonly_attributes ||= (@subject.class.readonly_attributes || [])
end