0
@@ -71,11 +71,11 @@ module ThoughtBot # :nodoc:
0
assert existing = klass.find(:first), "Can't find first #{klass}"
0
- object.send(
:"#{attribute}=", existing.send(attribute))
0
+ object.send(
"#{attribute}=", existing.send(attribute))
0
assert_respond_to object, :"#{s}=", "#{klass.name} doesn't seem to have a #{s} attribute."
0
- object.send(
:"#{s}=", existing.send(s))
0
+ object.send(
"#{s}=", existing.send(s))
0
@@ -92,7 +92,7 @@ module ThoughtBot # :nodoc:
0
# Assume the scope is a foreign key if the field is nil
0
- object.send(
:"#{s}=", existing.send(s).nil? ? 1 : existing.send(s).next)
0
+ object.send(
"#{s}=", existing.send(s).nil? ? 1 : existing.send(s).next)
0
@@ -167,9 +167,9 @@ module ThoughtBot # :nodoc:
0
should "not allow #{attribute} to be set to #{v.inspect}" do
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", v)
0
- assert !object.
save, "Saved #{klass} with #{attribute} set to \"#{v}\""
0
+ assert !object.
valid?, "#{klass.name} allowed \"#{v}\" as a value for #{attribute}"
0
assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{v}\""
0
assert_contains(object.errors.on(attribute), message, "when set to \"#{v}\"")
0
@@ -187,9 +187,9 @@ module ThoughtBot # :nodoc:
0
good_values.each do |v|
0
should "allow #{attribute} to be set to #{v.inspect}" do
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", v)
0
assert_nil object.errors.on(attribute)
0
@@ -220,9 +220,9 @@ module ThoughtBot # :nodoc:
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.
valid?, "#{klass.name} allowed \"#{min_value}\" as a value for #{attribute}"
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
@@ -232,18 +232,18 @@ module ThoughtBot # :nodoc:
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
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.
valid?, "#{klass.name} allowed \"#{max_value}\" as a value for #{attribute}"
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
@@ -252,45 +252,46 @@ module ThoughtBot # :nodoc:
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
- # Ensures that the length of the attribute is at least a certain length
0
- # Requires an existing record
0
- # * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
- # Regexp or string. Default = <tt>/short/</tt>
0
- # should_ensure_length_at_least :name, 3
0
- def should_ensure_length_at_least(attribute, min_length, opts = {})
0
+ # Ensures that the length of the attribute is at least a certain length
0
+ # Requires an existing record
0
+ # * <tt>:short_message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
0
+ # Regexp or string. Default = <tt>/short/</tt>
0
+ # should_ensure_length_at_least :name, 3
0
+ def should_ensure_length_at_least(attribute, min_length, opts = {})
0
short_message = get_options!([opts], :short_message)
0
short_message ||= /short/
0
min_value = "x" * (min_length - 1)
0
should "not allow #{attribute} to be less than #{min_length} chars long" do
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.
valid?, "#{klass} allowed \"#{min_value}\" as a value for #{attribute}"
0
assert object.errors.on(attribute), "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 at least #{min_length} chars long" do
0
valid_value = "x" * (min_length)
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", valid_value)
0
- assert object.save, "Could not save #{klass} with #{attribute} set to \"#{valid_value}\""
0
+ assert_does_not_contain(object.errors.on(attribute), short_message, "when set to \"#{valid_value}\"")
0
@@ -305,38 +306,37 @@ module ThoughtBot # :nodoc:
0
# should_ensure_length_is :ssn, 9
0
def should_ensure_length_is(attribute, length, opts = {})
0
- message = get_options!([opts], :message)
0
- message ||= /wrong length/
0
- should "not allow #{attribute} to be less than #{length} chars long" do
0
- min_value = "x" * (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_contains(object.errors.on(attribute), message, "when set to \"#{min_value}\"")
0
- should "not allow #{attribute} to be greater than #{length} chars long" do
0
- max_value = "x" * (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_contains(object.errors.on(attribute), message, "when set to \"#{max_value}\"")
0
- should "allow #{attribute} to be #{length} chars long" do
0
- valid_value = "x" * (length)
0
- assert object = klass.find(:first), "Can't find first #{klass}"
0
- object.send("#{attribute}=", valid_value)
0
- assert_does_not_contain(object.errors.on(attribute), message, "when set to \"#{valid_value}\"")
0
+ message = get_options!([opts], :message)
0
+ message ||= /wrong length/
0
+ should "not allow #{attribute} to be less than #{length} chars long" do
0
+ min_value = "x" * (length - 1)
0
+ object.send("#{attribute}=", min_value)
0
+ assert !object.valid?, "#{klass} allowed \"#{min_value}\" as a value for #{attribute}"
0
+ assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{min_value}\""
0
+ assert_contains(object.errors.on(attribute), message, "when set to \"#{min_value}\"")
0
+ should "not allow #{attribute} to be greater than #{length} chars long" do
0
+ max_value = "x" * (length + 1)
0
+ object.send("#{attribute}=", max_value)
0
+ assert !object.valid?, "#{klass} allowed \"#{max_value}\" as a value for #{attribute}"
0
+ assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{max_value}\""
0
+ assert_contains(object.errors.on(attribute), message, "when set to \"#{max_value}\"")
0
+ should "allow #{attribute} to be #{length} chars long" do
0
+ valid_value = "x" * (length)
0
+ object.send("#{attribute}=", valid_value)
0
+ assert_does_not_contain(object.errors.on(attribute), message, "when set to \"#{valid_value}\"")
0
# Ensure that the attribute is in the range specified
0
# Requires an existing record
0
@@ -361,35 +361,35 @@ module ThoughtBot # :nodoc:
0
should "not allow #{attribute} to be less than #{min}" do
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", v)
0
- assert !object.
save, "Saved #{klass} with #{attribute} set to \"#{v}\""
0
+ assert !object.
valid?, "#{klass} allowed \"#{v}\" as a value for #{attribute}"
0
assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{v}\""
0
assert_contains(object.errors.on(attribute), low_message, "when set to \"#{v}\"")
0
should "allow #{attribute} to be #{min}" do
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", v)
0
assert_does_not_contain(object.errors.on(attribute), low_message, "when set to \"#{v}\"")
0
should "not allow #{attribute} to be more than #{max}" do
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", v)
0
- assert !object.
save, "Saved #{klass} with #{attribute} set to \"#{v}\""
0
+ assert !object.
valid?, "#{klass} allowed \"#{v}\" as a value for #{attribute}"
0
assert object.errors.on(attribute), "There are no errors set on #{attribute} after being set to \"#{v}\""
0
assert_contains(object.errors.on(attribute), high_message, "when set to \"#{v}\"")
0
should "allow #{attribute} to be #{max}" do
0
-
assert object = klass.find(:first), "Can't find first #{klass}"0
object.send("#{attribute}=", v)
0
assert_does_not_contain(object.errors.on(attribute), high_message, "when set to \"#{v}\"")
0
@@ -411,9 +411,9 @@ module ThoughtBot # :nodoc:
0
attributes.each do |attribute|
0
attribute = attribute.to_sym
0
should "only allow numeric values for #{attribute}" do
0
- assert object = klass.find(:first), "Can't find first #{klass}"
0
- object.send(:"#{attribute}=", "abcd")
0
- assert !object.valid?, "Instance is still valid"
0
+ object.send("#{attribute}=", "abcd")
0
+ assert !object.valid?, "#{klass} allowed \"abcd\" as a value for #{attribute}"
0
assert_contains(object.errors.on(attribute), message)
Comments
No one has commented yet.