Add is_within method for shoulda's EnsureLengthOf matcher

This commit is contained in:
Robert Speicher 2012-08-29 02:21:50 -04:00
parent 9e7d77cece
commit 2bdea8651f

View file

@ -67,3 +67,17 @@ module UrlAccess
login_with(user) if user login_with(user) if user
end end
end end
# Extend shoulda-matchers
module Shoulda::Matchers::ActiveModel
class EnsureLengthOfMatcher
# Shortcut for is_at_least and is_at_most
def is_within(range)
if range.exclude_end?
is_at_least(range.first) && is_at_most(range.last - 1)
else
is_at_least(range.first) && is_at_most(range.last)
end
end
end
end