0
@@ -177,26 +177,49 @@ module ThoughtBot # :nodoc:
0
min_length = range.first
0
max_length = range.last
0
+ same_length = (min_length == max_length)
0
- min_value = "x" * (min_length - 1)
0
should "not allow #{attribute} to be less than #{min_length} chars long" do
0
+ min_value = "x" * (min_length - 1)
0
assert object = klass.find(:first), "Can't find first #{klass}"
0
object.send("#{attribute}=", min_value)
0
assert !object.save, "Saved #{klass} with #{attribute} set to \"#{min_value}\""
0
- assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{min_value}\""
0
+ assert object.errors.on(attribute),
0
+ "There are no errors set on #{attribute} after being set to \"#{min_value}\""
0
assert_contains(object.errors.on(attribute), short_message, "when set to \"#{min_value}\"")
0
+ should "allow #{attribute} to be exactly #{min_length} chars long" do
0
+ min_value = "x" * min_length
0
+ assert object = klass.find(:first), "Can't find first #{klass}"
0
+ object.send("#{attribute}=", min_value)
0
+ assert_does_not_contain(object.errors.on(attribute), short_message, "when set to \"#{min_value}\"")
0
- max_value = "x" * (max_length + 1)
0
should "not allow #{attribute} to be more than #{max_length} chars long" do
0
+ max_value = "x" * (max_length + 1)
0
assert object = klass.find(:first), "Can't find first #{klass}"
0
object.send("#{attribute}=", max_value)
0
assert !object.save, "Saved #{klass} with #{attribute} set to \"#{max_value}\""
0
- assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{max_value}\""
0
+ assert object.errors.on(attribute),
0
+ "There are no errors set on #{attribute} after being set to \"#{max_value}\""
0
assert_contains(object.errors.on(attribute), long_message, "when set to \"#{max_value}\"")
0
+ should "allow #{attribute} to be exactly #{max_length} chars long" do
0
+ max_value = "x" * max_length
0
+ assert object = klass.find(:first), "Can't find first #{klass}"
0
+ object.send("#{attribute}=", max_value)
0
+ assert_does_not_contain(object.errors.on(attribute), long_message, "when set to \"#{max_value}\"")
0
# Ensure that the attribute is in the range specified
Comments
No one has commented yet.