Class: Shoulda::ActiveRecord::Matchers::ValidateNumericalityOfMatcher

Inherits:
ValidationMatcher
  • Object
show all
Defined in:
lib/shoulda/active_record/matchers/validate_numericality_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



32
33
34
# File 'lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb', line 32

def description
  "only allow numeric values for #{@attribute}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb', line 26

def matches?(subject)
  super(subject)
  @expected_message ||= :not_a_number
  disallows_value_of('abcd', @expected_message)
end

#with_message(message) ⇒ Object



21
22
23
24
# File 'lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb', line 21

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