2014-01-23 18:07:36 +00:00
|
|
|
module Shoulda
|
2014-01-13 01:43:36 +00:00
|
|
|
module Matchers
|
2014-01-23 18:07:36 +00:00
|
|
|
module ActiveModel
|
2014-01-13 01:43:36 +00:00
|
|
|
module NumericalityMatchers
|
2014-01-23 18:07:36 +00:00
|
|
|
# @private
|
|
|
|
class EvenNumberMatcher < NumericTypeMatcher
|
2014-01-13 01:43:36 +00:00
|
|
|
NON_EVEN_NUMBER_VALUE = 1
|
|
|
|
|
2015-12-13 23:45:24 +00:00
|
|
|
def simple_description
|
|
|
|
description = ''
|
|
|
|
|
|
|
|
if expects_strict?
|
|
|
|
description << 'strictly '
|
|
|
|
end
|
|
|
|
|
|
|
|
description +
|
|
|
|
"disallow :#{attribute} from being an odd number"
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_type_adjective
|
|
|
|
'even'
|
2014-01-13 01:43:36 +00:00
|
|
|
end
|
2014-02-27 03:26:37 +00:00
|
|
|
|
|
|
|
def diff_to_compare
|
|
|
|
2
|
|
|
|
end
|
2015-10-07 05:12:30 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def wrap_disallow_value_matcher(matcher)
|
|
|
|
matcher.with_message(:even)
|
|
|
|
end
|
|
|
|
|
|
|
|
def disallowed_value
|
|
|
|
if @numeric_type_matcher.given_numeric_column?
|
|
|
|
NON_EVEN_NUMBER_VALUE
|
|
|
|
else
|
|
|
|
NON_EVEN_NUMBER_VALUE.to_s
|
|
|
|
end
|
|
|
|
end
|
2014-01-13 01:43:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|