Problem
Consider the following code:
class Post < ActiveRecord::Base
validates :title, length: { minium: 10, maximum: 20 }
end
post = Post.new(title: "Invalid")
puts post.valid?
This code prints “true” instead of “false”. The problem is that we have a typo: “minimum” is correct but there’s “minium”.
In short, when there’s a typo in either side of “minimum” or “maximum”, the validator doesn’t raise an error. And it’s easier to typo on “minimum” and “maximum” in my experience.
Solution
I believe we can add min
and max
aliases to LengthValidator
options since it’s much less possible to typo on them. They are also the name of the methods in Range
class so it’s easier to memorize.
Do you think it’s worth adding?