<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -32,13 +32,8 @@ module ThoughtBot # :nodoc:
       def should_require_attributes(*attributes)
         message = get_options!(attributes, :message)
         message ||= /blank/
-        klass = model_class
-
         attributes.each do |attribute|
-          should &quot;require #{attribute} to be set&quot; do
-            object = klass.new
-            assert_bad_value(object, attribute, nil, message)
-          end
+          should_not_allow_values_for attribute, nil, :message =&gt; message, :should =&gt; &quot;require #{attribute} to be set&quot;
         end
       end
 
@@ -144,16 +139,19 @@ module ThoughtBot # :nodoc:
       # Options:
       # * &lt;tt&gt;:message&lt;/tt&gt; - value the test expects to find in &lt;tt&gt;errors.on(:attribute)&lt;/tt&gt;.
       #   Regexp or string.  Default = &lt;tt&gt;/invalid/&lt;/tt&gt;
+      # * &lt;tt&gt;:should&lt;/tt&gt; - an override of the default should test name.
+      #   Usually only used by other macros.
       #
       # Example:
       #   should_not_allow_values_for :isbn, &quot;bad 1&quot;, &quot;bad 2&quot;
       #
       def should_not_allow_values_for(attribute, *bad_values)
-        message = get_options!(bad_values, :message)
+        message, name = get_options!(bad_values, :message, :should)
         message ||= /invalid/
         klass = model_class
         bad_values.each do |v|
-          should &quot;not allow #{attribute} to be set to #{v.inspect}&quot; do
+          name ||= &quot;not allow #{attribute} to be set to #{v.inspect}&quot;
+          should name do
             object = klass.new
             assert_bad_value(object, attribute, v, message)
           end
@@ -163,16 +161,24 @@ module ThoughtBot # :nodoc:
       # Ensures that the attribute can be set to the given values.
       # Requires an existing record
       #
+      # Options:
+      # * &lt;tt&gt;:message&lt;/tt&gt; - value the test shouldn't find in &lt;tt&gt;errors.on(:attribute)&lt;/tt&gt;.
+      #   Regexp or string.  Default = &lt;tt&gt;//&lt;/tt&gt;
+      # * &lt;tt&gt;:should&lt;/tt&gt; - an override of the default should test name.
+      #   Usually only used by other macros.
+      #
       # Example:
       #   should_allow_values_for :isbn, &quot;isbn 1 2345 6789 0&quot;, &quot;ISBN 1-2345-6789-0&quot;
       #
       def should_allow_values_for(attribute, *good_values)
-        get_options!(good_values)
+        message, name = get_options!(good_values, :message, :should)
+        message ||= //
         klass = model_class
         good_values.each do |v|
-          should &quot;allow #{attribute} to be set to #{v.inspect}&quot; do
+          name ||= &quot;allow #{attribute} to be set to #{v.inspect}&quot;
+          should name do
             object = klass.new
-            assert_good_value(object, attribute, v)
+            assert_good_value(object, attribute, v, message)
           end
         end
       end
@@ -194,39 +200,26 @@ module ThoughtBot # :nodoc:
         short_message ||= /short/
         long_message  ||= /long/
 
-        klass = model_class
         min_length = range.first
         max_length = range.last
         same_length = (min_length == max_length)
 
         if min_length &gt; 0
-          should &quot;not allow #{attribute} to be less than #{min_length} chars long&quot; do
-            min_value = &quot;x&quot; * (min_length - 1)
-            object = klass.new
-            assert_bad_value(object, attribute, min_value, short_message)
-          end
+          min_value = &quot;x&quot; * (min_length - 1)
+          should_not_allow_values_for attribute, min_value, :message =&gt; short_message, :should =&gt; &quot;not allow #{attribute} to be less than #{min_length} chars long&quot;
         end
 
         if min_length &gt; 0
-          should &quot;allow #{attribute} to be exactly #{min_length} chars long&quot; do
-            min_value = &quot;x&quot; * min_length
-            object = klass.new
-            assert_good_value(object, attribute, min_value, short_message)
-          end
+          min_value = &quot;x&quot; * min_length
+          should_allow_values_for attribute, min_value, :message =&gt; short_message, :should =&gt; &quot;allow #{attribute} to be exactly #{min_length} chars long&quot;
         end
 
-        should &quot;not allow #{attribute} to be more than #{max_length} chars long&quot; do
-          max_value = &quot;x&quot; * (max_length + 1)
-          object = klass.new
-          assert_bad_value(object, attribute, max_value, long_message)
-        end
+        max_value = &quot;x&quot; * (max_length + 1)
+        should_not_allow_values_for attribute, max_value, :message =&gt; long_message, :should =&gt; &quot;not allow #{attribute} to be more than #{max_length} chars long&quot;
 
         unless same_length
-          should &quot;allow #{attribute} to be exactly #{max_length} chars long&quot; do
-            max_value = &quot;x&quot; * max_length
-            object = klass.new
-            assert_good_value(object, attribute, max_value, long_message)
-          end
+          max_value = &quot;x&quot; * max_length
+          should_allow_values_for attribute, max_value, :message =&gt; long_message, :should =&gt; &quot;allow #{attribute} to be exactly #{max_length} chars long&quot;
         end
       end
 
@@ -244,20 +237,13 @@ module ThoughtBot # :nodoc:
         short_message = get_options!([opts], :short_message)
         short_message ||= /short/
 
-        klass = model_class
-
         if min_length &gt; 0
           min_value = &quot;x&quot; * (min_length - 1)
-          should &quot;not allow #{attribute} to be less than #{min_length} chars long&quot; do
-            object = klass.new
-            assert_bad_value(object, attribute, min_value, short_message)
-          end
-        end
-        should &quot;allow #{attribute} to be at least #{min_length} chars long&quot; do
-          valid_value = &quot;x&quot; * (min_length)
-          object = klass.new
-          assert_good_value(object, attribute, valid_value, short_message)
+          should_not_allow_values_for attribute, min_value, :message =&gt; short_message, :should =&gt; &quot;not allow #{attribute} to be less than #{min_length} chars long&quot;
         end
+
+        valid_value = &quot;x&quot; * (min_length)
+        should_allow_values_for attribute, valid_value, :message =&gt; short_message, :should =&gt; &quot;allow #{attribute} to be at least #{min_length} chars long&quot;
       end
 
       # Ensures that the length of the attribute is exactly a certain length
@@ -274,25 +260,14 @@ module ThoughtBot # :nodoc:
         message = get_options!([opts], :message)
         message ||= /wrong length/
 
-        klass = model_class
-
-        should &quot;not allow #{attribute} to be less than #{length} chars long&quot; do
-          min_value = &quot;x&quot; * (length - 1)
-          object = klass.new
-          assert_bad_value(object, attribute, min_value, message)
-        end
+        min_value = &quot;x&quot; * (length - 1)
+        should_not_allow_values_for attribute, min_value, :message =&gt; message, :should =&gt; &quot;not allow #{attribute} to be less than #{length} chars long&quot;
 
-        should &quot;not allow #{attribute} to be greater than #{length} chars long&quot; do
-          max_value = &quot;x&quot; * (length + 1)
-          object = klass.new
-          assert_bad_value(object, attribute, max_value, message)
-        end
+        max_value = &quot;x&quot; * (length + 1)
+        should_not_allow_values_for attribute, max_value, :message =&gt; message, :should =&gt; &quot;not allow #{attribute} to be greater than #{length} chars long&quot;
 
-        should &quot;allow #{attribute} to be #{length} chars long&quot; do
-          valid_value = &quot;x&quot; * (length)
-          object = klass.new
-          assert_good_value(object, attribute, valid_value, message)
-        end
+        valid_value = &quot;x&quot; * (length)
+        should_allow_values_for attribute, valid_value, :message =&gt; message, :should =&gt; &quot;allow #{attribute} to be #{length} chars long&quot;
       end
 
       # Ensure that the attribute is in the range specified
@@ -312,33 +287,13 @@ module ThoughtBot # :nodoc:
         low_message  ||= /included/
         high_message ||= /included/
 
-        klass = model_class
         min   = range.first
         max   = range.last
 
-        should &quot;not allow #{attribute} to be less than #{min}&quot; do
-          v = min - 1
-          object = klass.new
-          assert_bad_value(object, attribute, v, low_message)
-        end
-
-        should &quot;allow #{attribute} to be #{min}&quot; do
-          v = min
-          object = klass.new
-          assert_good_value(object, attribute, v, low_message)
-        end
-
-        should &quot;not allow #{attribute} to be more than #{max}&quot; do
-          v = max + 1
-          object = klass.new
-          assert_bad_value(object, attribute, v, high_message)
-        end
-
-        should &quot;allow #{attribute} to be #{max}&quot; do
-          v = max
-          object = klass.new
-          assert_good_value(object, attribute, v, high_message)
-        end
+        should_not_allow_values_for attribute, (min - 1), :message =&gt; low_message, :should =&gt; &quot;not allow #{attribute} to be less than #{min}&quot;
+        should_allow_values_for attribute, min, :message =&gt; low_message, :should =&gt; &quot;allow #{attribute} to be #{min}&quot;
+        should_not_allow_values_for attribute, (max + 1), :message =&gt; high_message, :should =&gt; &quot;not allow #{attribute} to be more than #{max}&quot;
+        should_allow_values_for attribute, max, :message =&gt; high_message, :should =&gt; &quot;allow #{attribute} to be #{max}&quot;
       end
 
       # Ensure that the attribute is numeric
@@ -354,13 +309,8 @@ module ThoughtBot # :nodoc:
       def should_only_allow_numeric_values_for(*attributes)
         message = get_options!(attributes, :message)
         message ||= /number/
-        klass = model_class
         attributes.each do |attribute|
-          attribute = attribute.to_sym
-          should &quot;only allow numeric values for #{attribute}&quot; do
-            object = klass.new
-            assert_bad_value(object, attribute, &quot;abcd&quot;, message)
-          end
+          should_not_allow_values_for attribute, &quot;abcd&quot;, :message =&gt; message, :should =&gt; &quot;only allow numeric values for #{attribute}&quot;
         end
       end
 
@@ -593,13 +543,9 @@ module ThoughtBot # :nodoc:
       def should_require_acceptance_of(*attributes)
         message = get_options!(attributes, :message)
         message ||= /must be accepted/
-        klass = model_class
 
         attributes.each do |attribute|
-          should &quot;require #{attribute} to be accepted&quot; do
-            object = klass.new
-            assert_bad_value(object, attribute, false, message)
-          end
+          should_not_allow_values_for attribute, false, :message =&gt; message, :should =&gt; &quot;require #{attribute} to be accepted&quot;
         end
       end
 </diff>
      <filename>lib/shoulda/active_record_helpers.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4c5768d1630bbfc522c6019eede33fb1b2e6c57f</id>
    </parent>
  </parents>
  <author>
    <name>Ryan McGeary</name>
    <email>ryanongit@mcgeary.org</email>
  </author>
  <url>http://github.com/rmm5t/shoulda/commit/063426f75110a9081eccda5607e18274c666b162</url>
  <id>063426f75110a9081eccda5607e18274c666b162</id>
  <committed-date>2008-07-28T21:32:25-07:00</committed-date>
  <authored-date>2008-07-28T21:32:25-07:00</authored-date>
  <message>Further DRY'd Active Record several macros to re-use should_allow_values_for and should_not_allow_values_for</message>
  <tree>ec542cd53b8ba2d1ae840563e2100f7fee30a5e6</tree>
  <committer>
    <name>Ryan McGeary</name>
    <email>ryanongit@mcgeary.org</email>
  </committer>
</commit>
