thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb

35 lines
705 B
Ruby
Raw Normal View History

module Shoulda
module Matchers
module ActiveModel
module NumericalityMatchers
# @private
2014-06-20 04:44:06 +00:00
class OnlyIntegerMatcher < NumericTypeMatcher
NON_INTEGER_VALUE = 0.1
def allowed_type
'integers'
end
def diff_to_compare
1
end
protected
def wrap_disallow_value_matcher(matcher)
matcher.with_message(:not_an_integer)
end
def disallowed_value
if @numeric_type_matcher.given_numeric_column?
NON_INTEGER_VALUE
else
NON_INTEGER_VALUE.to_s
end
end
end
end
end
end
end