Class: Shoulda::ActiveRecord::Matchers::HaveReadonlyAttributeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ HaveReadonlyAttributeMatcher

Returns a new instance of HaveReadonlyAttributeMatcher.



16
17
18
# File 'lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb', line 16

def initialize(attribute)
  @attribute = attribute.to_s
end

Instance Attribute Details

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



39
40
41
# File 'lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb', line 39

def failure_message
  @failure_message
end

#negative_failure_messageObject (readonly)

Returns the value of attribute negative_failure_message.



39
40
41
# File 'lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb', line 39

def negative_failure_message
  @negative_failure_message
end

Instance Method Details

#descriptionObject



41
42
43
# File 'lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb', line 41

def description
  "make #{@attribute} read-only"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb', line 20

def matches?(subject)
  @subject = subject
  if readonly_attributes.include?(@attribute)
    @negative_failure_message =
      "Did not expect #{@attribute} to be read-only"
    true
  else
    if readonly_attributes.empty?
      @failure_message = "#{class_name} attribute #{@attribute} " <<
        "is not read-only"
    else
      @failure_message = "#{class_name} is making " <<
        "#{readonly_attributes.to_sentence} " <<
        "read-only, but not #{@attribute}."
    end
    false
  end
end