class Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher
@private
def collection?
def collection? if reflection [:has_many, :has_and_belongs_to_many].include?(reflection.macro) else false end end
def column_type
def column_type @subject.class.respond_to?(:columns_hash) && @subject.class.columns_hash[@attribute.to_s].respond_to?(:type) && @subject.class.columns_hash[@attribute.to_s].type end
def does_not_match?(subject)
def does_not_match?(subject) super(subject) allows_value_of(value, @expected_message) end
def enum_column?
def enum_column? @subject.class.respond_to?(:defined_enums) && @subject.class.defined_enums.key?(@attribute.to_s) end
def enum_values
def enum_values @subject.class.defined_enums[@attribute.to_s].values end
def initialize(attribute)
def initialize(attribute) super @expected_message = :present end
def matches?(subject)
def matches?(subject) super(subject) disallows_value_of(value, @expected_message) end
def reflection
def reflection @subject.class.respond_to?(:reflect_on_association) && @subject.class.reflect_on_association(@attribute) end
def simple_description
def simple_description "validate that :#{@attribute} is empty/falsy" end
def value
def value if reflection obj = reflection.klass.new if collection? [obj] else obj end elsif array_column? ['an arbitrary value'] elsif enum_column? enum_values.first else case column_type when :integer, :float then 1 when :decimal then BigDecimal(1, 0) when :datetime, :time, :timestamp then Time.current when :date then Date.new when :binary then '0' when :uuid then SecureRandom.uuid else 'an arbitrary value' end end end