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 71
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 65
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 60
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 96
def attribute_class
  @subject.class.respond_to?(:columns_hash) &&
    @subject.class.columns_hash[@attribute.to_s].respond_to?(:klass) &&
    @subject.class.columns_hash[@attribute.to_s].klass
end
collection?() click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 102
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 110
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 77
def value
  if reflection
    obj = reflection.klass.new
    if collection?
      [ obj ]
    else
      obj
    end
  elsif [Fixnum, Float].include?(attribute_class)
    1
  elsif attribute_class == BigDecimal
    BigDecimal.new(1, 0)
  elsif !attribute_class || attribute_class == String
    'an arbitrary value'
  else
    attribute_class.new
  end
end