class Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher

@private

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 68
def description
  "require #{@attribute} to not be set"
end
matches?(subject) click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 62
def matches?(subject)
  super(subject)
  @expected_message ||= :present
  disallows_value_of(value, @expected_message)
end
with_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 57
def with_message(message)
  @expected_message = message
  self
end

Private Instance Methods

attribute_class() click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 91
def attribute_class
  @subject.class.respond_to?(:columns_hash) &&
    @subject.class.columns_hash[@attribute].respond_to?(:klass) &&
    @subject.class.columns_hash[@attribute].klass
end
collection?() click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 97
def collection?
  if reflection
    [:has_many, :has_and_belongs_to_many].include?(reflection.macro)
  else
    false
  end
end
reflection() click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 105
def reflection
  @subject.class.respond_to?(:reflect_on_association) &&
    @subject.class.reflect_on_association(@attribute)
end
value() click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 74
def value
  if reflection
    obj = reflection.klass.new
    if collection?
      [ obj ]
    else
      obj
    end
  elsif attribute_class == Fixnum
    1
  elsif !attribute_class || attribute_class == String
    'an arbitrary value'
  else
    attribute_class.new
  end
end