class Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher

@private

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb, line 60
def description
  "require #{@attribute} to be set"
end
matches?(subject) click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb, line 54
def matches?(subject)
  super(subject)
  @expected_message ||= :blank
  disallows_value_of(blank_value, @expected_message)
end
with_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb, line 49
def with_message(message)
  @expected_message = message if message
  self
end

Private Instance Methods

blank_value() click to toggle source
# File lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb, line 66
def blank_value
  if collection?
    []
  else
    nil
  end
end
collection?() click to toggle source
# File lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb, line 74
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_presence_of_matcher.rb, line 82
def reflection
  @subject.class.respond_to?(:reflect_on_association) &&
    @subject.class.reflect_on_association(@attribute)
end