module Shoulda::Matchers::ActiveModel
def ensure_length_of(attr)
is_equal_to(9).
it { should ensure_length_of(:ssn).
with_short_message(/not long enough/) }
is_at_least(3).
it { should ensure_length_of(:name).
is_at_most(20) }
is_at_least(6).
it { should ensure_length_of(:password).
Examples:
is_equal_to.
translation for :wrong_length. Used in conjunction with
errors.on(:attribute). Regexp or string. Defaults to the
* with_message - value the test expects to find in
translation for :too_long.
errors.on(:attribute). Regexp or string. Defaults to the
* with_long_message - value the test expects to find in
translation for :too_short.
errors.on(:attribute). Regexp or string. Defaults to the
* with_short_message - value the test expects to find in
* is_equal_to - exact requred length of this attribute
* is_at_most - maximum length of this attribute
* is_at_least - minimum length of this attribute
Options:
string/text columns because it uses a string to check length.
Ensures that the length of the attribute is validated. Only works with
def ensure_length_of(attr) EnsureLengthOfMatcher.new(attr) end