Class: DataMapper::Matchers::ValidatePresenceOf
Instance Method Summary
collapse
#description, #failure_message, #failure_message_when_negated, #initialize, set_default_msg_reg, set_validation_subject, #with_message
Instance Method Details
#failure_message_for_presence ⇒ Object
22
23
24
|
# File 'lib/dm/matchers/validate_presence_of.rb', line 22
def failure_message_for_presence
"expected to validate presence of #{@property}#{with_msg}"
end
|
#matches?(model) ⇒ Boolean
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/dm/matchers/validate_presence_of.rb', line 10
def matches?(model)
model_class = model.is_a?(Class) ? model : model.class
validators = model_class.validators.contexts[:default]
presence_of = validators.find do |validator|
validator.is_a? DataMapper::Validations::PresenceValidator and validator.field_name == @property
end
return false unless presence_of
return false if @msg and @msg != presence_of.options[:message]
true
end
|
#negative_failure_message ⇒ Object
26
27
28
|
# File 'lib/dm/matchers/validate_presence_of.rb', line 26
def negative_failure_message
"expected to not validate presence of #{@property}#{with_msg}"
end
|
#with_msg ⇒ Object
30
31
32
|
# File 'lib/dm/matchers/validate_presence_of.rb', line 30
def with_msg
" with message \"#{@msg}\"" if @msg
end
|