Class: Shoulda::ActiveRecord::Matchers::ValidatePresenceOfMatcher

Inherits:
ValidationMatcher
  • Object
show all
Defined in:
lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ValidationMatcher

#failure_message

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#initialize, #negative_failure_message

Constructor Details

This class inherits a constructor from Shoulda::ActiveRecord::Matchers::ValidationMatcher

Instance Method Details

#descriptionObject


35
36
37
# File 'lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb', line 35

def description
  "require #{@attribute} to be set"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)

29
30
31
32
33
# File 'lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb', line 29

def matches?(subject)
  super(subject)
  @expected_message ||= :blank
  disallows_value_of(blank_value, @expected_message)
end

#with_message(message) ⇒ Object


24
25
26
27
# File 'lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb', line 24

def with_message(message)
  @expected_message = message if message
  self
end