2014-01-23 18:07:36 +00:00
|
|
|
module Shoulda
|
2013-11-01 21:57:42 +00:00
|
|
|
module Matchers
|
2014-01-23 18:07:36 +00:00
|
|
|
module ActiveModel
|
2013-11-01 21:57:42 +00:00
|
|
|
module NumericalityMatchers
|
2014-01-23 18:07:36 +00:00
|
|
|
# @private
|
2014-06-20 04:44:06 +00:00
|
|
|
class OnlyIntegerMatcher < NumericTypeMatcher
|
2013-11-01 21:57:42 +00:00
|
|
|
NON_INTEGER_VALUE = 0.1
|
|
|
|
|
2015-12-13 23:45:24 +00:00
|
|
|
def simple_description
|
|
|
|
description = ''
|
|
|
|
|
|
|
|
if expects_strict?
|
|
|
|
description << ' strictly'
|
|
|
|
end
|
|
|
|
|
|
|
|
description + "disallow :#{attribute} from being a decimal number"
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_type_name
|
|
|
|
'integer'
|
2013-11-01 21:57:42 +00:00
|
|
|
end
|
2014-02-27 03:26:37 +00:00
|
|
|
|
|
|
|
def diff_to_compare
|
|
|
|
1
|
|
|
|
end
|
2015-10-07 05:12:30 +00:00
|
|
|
|
|
|
|
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
|
2013-11-01 21:57:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|