class Shoulda::Matchers::ActiveModel::ValidateAbsenceOfMatcher
@private
Public Class Methods
new(attribute)
click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 81 def initialize(attribute) super @expected_message = :present end
Public Instance Methods
matches?(subject)
click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 86 def matches?(subject) super(subject) disallows_value_of(value, @expected_message) end
simple_description()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 91 def simple_description "validate that :#{@attribute} is empty/falsy" end
Private Instance Methods
collection?()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 123 def collection? if reflection [:has_many, :has_and_belongs_to_many].include?(reflection.macro) else false end end
column_type()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 117 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
reflection()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb, line 131 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 97 def value if reflection obj = reflection.klass.new if collection? [ obj ] else obj end else case column_type when :integer, :float then 1 when :decimal then BigDecimal(1, 0) when :datetime, :time, :timestamp then Time.now when :date then Date.new when :binary then '0' else 'an arbitrary value' end end end