<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -71,11 +71,11 @@ module ThoughtBot # :nodoc:
             assert existing = klass.find(:first), &quot;Can't find first #{klass}&quot;
             object = klass.new
             
-            object.send(:&quot;#{attribute}=&quot;, existing.send(attribute))
+            object.send(&quot;#{attribute}=&quot;, existing.send(attribute))
             if !scope.blank?
               scope.each do |s|
                 assert_respond_to object, :&quot;#{s}=&quot;, &quot;#{klass.name} doesn't seem to have a #{s} attribute.&quot;
-                object.send(:&quot;#{s}=&quot;, existing.send(s))
+                object.send(&quot;#{s}=&quot;, existing.send(s))
               end
             end
             
@@ -92,7 +92,7 @@ module ThoughtBot # :nodoc:
             if !scope.blank?
               scope.each do |s|
                 # Assume the scope is a foreign key if the field is nil
-                object.send(:&quot;#{s}=&quot;, existing.send(s).nil? ? 1 : existing.send(s).next)
+                object.send(&quot;#{s}=&quot;, existing.send(s).nil? ? 1 : existing.send(s).next)
               end
 
               object.errors.clear
@@ -167,9 +167,9 @@ module ThoughtBot # :nodoc:
         klass = model_class
         bad_values.each do |v|
           should &quot;not allow #{attribute} to be set to #{v.inspect}&quot; do
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+            object = klass.new
             object.send(&quot;#{attribute}=&quot;, v)
-            assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{v}\&quot;&quot;
+            assert !object.valid?, &quot;#{klass.name} allowed \&quot;#{v}\&quot; as a value for #{attribute}&quot;
             assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{v}\&quot;&quot;
             assert_contains(object.errors.on(attribute), message, &quot;when set to \&quot;#{v}\&quot;&quot;)
           end
@@ -187,9 +187,9 @@ module ThoughtBot # :nodoc:
         klass = model_class
         good_values.each do |v|
           should &quot;allow #{attribute} to be set to #{v.inspect}&quot; do
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+            object = klass.new
             object.send(&quot;#{attribute}=&quot;, v)
-            object.save
+            object.valid?
             assert_nil object.errors.on(attribute)
           end
         end
@@ -220,9 +220,9 @@ module ThoughtBot # :nodoc:
         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)
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+            object = klass.new
             object.send(&quot;#{attribute}=&quot;, min_value)
-            assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{min_value}\&quot;&quot;
+            assert !object.valid?, &quot;#{klass.name} allowed \&quot;#{min_value}\&quot; as a value for #{attribute}&quot;
             assert object.errors.on(attribute), 
                    &quot;There are no errors set on #{attribute} after being set to \&quot;#{min_value}\&quot;&quot;
             assert_contains(object.errors.on(attribute), short_message, &quot;when set to \&quot;#{min_value}\&quot;&quot;)
@@ -232,18 +232,18 @@ module ThoughtBot # :nodoc:
         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
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+            object = klass.new
             object.send(&quot;#{attribute}=&quot;, min_value)
-            object.save
+            object.valid?
             assert_does_not_contain(object.errors.on(attribute), short_message, &quot;when set to \&quot;#{min_value}\&quot;&quot;)
           end
         end
     
         should &quot;not allow #{attribute} to be more than #{max_length} chars long&quot; do
           max_value = &quot;x&quot; * (max_length + 1)
-          assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+          object = klass.new
           object.send(&quot;#{attribute}=&quot;, max_value)
-          assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{max_value}\&quot;&quot;
+          assert !object.valid?, &quot;#{klass.name} allowed \&quot;#{max_value}\&quot; as a value for #{attribute}&quot;
           assert object.errors.on(attribute), 
                  &quot;There are no errors set on #{attribute} after being set to \&quot;#{max_value}\&quot;&quot;
           assert_contains(object.errors.on(attribute), long_message, &quot;when set to \&quot;#{max_value}\&quot;&quot;)
@@ -252,45 +252,46 @@ module ThoughtBot # :nodoc:
         unless same_length
           should &quot;allow #{attribute} to be exactly #{max_length} chars long&quot; do
             max_value = &quot;x&quot; * max_length
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+            object = klass.new
             object.send(&quot;#{attribute}=&quot;, max_value)
-            object.save
+            object.valid?
             assert_does_not_contain(object.errors.on(attribute), long_message, &quot;when set to \&quot;#{max_value}\&quot;&quot;)
           end
         end
       end  
       
-     # Ensures that the length of the attribute is at least a certain length
-     # Requires an existing record
-     #
-     # Options:
-     # * &lt;tt&gt;:short_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;/short/&lt;/tt&gt;
-     #
-     # Example:
-     #   should_ensure_length_at_least :name, 3
-     #
-     def should_ensure_length_at_least(attribute, min_length, opts = {})
+      # Ensures that the length of the attribute is at least a certain length
+      # Requires an existing record
+      #
+      # Options:
+      # * &lt;tt&gt;:short_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;/short/&lt;/tt&gt;
+      #
+      # Example:
+      #   should_ensure_length_at_least :name, 3
+      #
+      def should_ensure_length_at_least(attribute, min_length, opts = {})
         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
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+            object = klass.new
             object.send(&quot;#{attribute}=&quot;, min_value)
-            assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{min_value}\&quot;&quot;
+            assert !object.valid?, &quot;#{klass} allowed \&quot;#{min_value}\&quot; as a value for #{attribute}&quot;
             assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{min_value}\&quot;&quot;
             assert_contains(object.errors.on(attribute), short_message, &quot;when set to \&quot;#{min_value}\&quot;&quot;)
           end
         end
         should &quot;allow #{attribute} to be at least #{min_length} chars long&quot; do
           valid_value = &quot;x&quot; * (min_length)
-          assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+          object = klass.new
           object.send(&quot;#{attribute}=&quot;, valid_value)
-          assert object.save, &quot;Could not save #{klass} with #{attribute} set to \&quot;#{valid_value}\&quot;&quot;
+          object.valid?
+          assert_does_not_contain(object.errors.on(attribute), short_message, &quot;when set to \&quot;#{valid_value}\&quot;&quot;)
         end
       end
       
@@ -305,38 +306,37 @@ module ThoughtBot # :nodoc:
       #   should_ensure_length_is :ssn, 9
       #
       def should_ensure_length_is(attribute, length, opts = {})
-         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)
-           assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
-           object.send(&quot;#{attribute}=&quot;, min_value)
-           assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{min_value}\&quot;&quot;
-           assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{min_value}\&quot;&quot;
-           assert_contains(object.errors.on(attribute), message, &quot;when set to \&quot;#{min_value}\&quot;&quot;)
-         end
-         
-         should &quot;not allow #{attribute} to be greater than #{length} chars long&quot; do
-           max_value = &quot;x&quot; * (length + 1)
-           assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
-           object.send(&quot;#{attribute}=&quot;, max_value)
-           assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{max_value}\&quot;&quot;
-           assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{max_value}\&quot;&quot;
-           assert_contains(object.errors.on(attribute), message, &quot;when set to \&quot;#{max_value}\&quot;&quot;)
-         end
-         
-          should &quot;allow #{attribute} to be #{length} chars long&quot; do
-             valid_value = &quot;x&quot; * (length)
-             assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
-             object.send(&quot;#{attribute}=&quot;, valid_value)
-             object.save
-             assert_does_not_contain(object.errors.on(attribute), message, &quot;when set to \&quot;#{valid_value}\&quot;&quot;)
-           end
-         
-       end
+        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
+          object.send(&quot;#{attribute}=&quot;, min_value)
+          assert !object.valid?, &quot;#{klass} allowed \&quot;#{min_value}\&quot; as a value for #{attribute}&quot;
+          assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{min_value}\&quot;&quot;
+          assert_contains(object.errors.on(attribute), message, &quot;when set to \&quot;#{min_value}\&quot;&quot;)
+        end
+        
+        should &quot;not allow #{attribute} to be greater than #{length} chars long&quot; do
+          max_value = &quot;x&quot; * (length + 1)
+          object = klass.new
+          object.send(&quot;#{attribute}=&quot;, max_value)
+          assert !object.valid?, &quot;#{klass} allowed \&quot;#{max_value}\&quot; as a value for #{attribute}&quot;
+          assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{max_value}\&quot;&quot;
+          assert_contains(object.errors.on(attribute), message, &quot;when set to \&quot;#{max_value}\&quot;&quot;)
+        end
+        
+        should &quot;allow #{attribute} to be #{length} chars long&quot; do
+          valid_value = &quot;x&quot; * (length)
+          object = klass.new
+          object.send(&quot;#{attribute}=&quot;, valid_value)
+          object.valid?
+          assert_does_not_contain(object.errors.on(attribute), message, &quot;when set to \&quot;#{valid_value}\&quot;&quot;)
+        end
+      end
 
       # Ensure that the attribute is in the range specified
       # Requires an existing record
@@ -361,35 +361,35 @@ module ThoughtBot # :nodoc:
 
         should &quot;not allow #{attribute} to be less than #{min}&quot; do
           v = min - 1
-          assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+          object = klass.new
           object.send(&quot;#{attribute}=&quot;, v)
-          assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{v}\&quot;&quot;
+          assert !object.valid?, &quot;#{klass} allowed \&quot;#{v}\&quot; as a value for #{attribute}&quot;
           assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{v}\&quot;&quot;
           assert_contains(object.errors.on(attribute), low_message, &quot;when set to \&quot;#{v}\&quot;&quot;)
         end
 
         should &quot;allow #{attribute} to be #{min}&quot; do
           v = min
-          assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+          object = klass.new
           object.send(&quot;#{attribute}=&quot;, v)
-          object.save
+          object.valid?
           assert_does_not_contain(object.errors.on(attribute), low_message, &quot;when set to \&quot;#{v}\&quot;&quot;)
         end
 
         should &quot;not allow #{attribute} to be more than #{max}&quot; do
           v = max + 1
-          assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+          object = klass.new
           object.send(&quot;#{attribute}=&quot;, v)
-          assert !object.save, &quot;Saved #{klass} with #{attribute} set to \&quot;#{v}\&quot;&quot;
+          assert !object.valid?, &quot;#{klass} allowed \&quot;#{v}\&quot; as a value for #{attribute}&quot;
           assert object.errors.on(attribute), &quot;There are no errors set on #{attribute} after being set to \&quot;#{v}\&quot;&quot;
           assert_contains(object.errors.on(attribute), high_message, &quot;when set to \&quot;#{v}\&quot;&quot;)
         end
 
         should &quot;allow #{attribute} to be #{max}&quot; do
           v = max
-          assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
+          object = klass.new
           object.send(&quot;#{attribute}=&quot;, v)
-          object.save
+          object.valid?
           assert_does_not_contain(object.errors.on(attribute), high_message, &quot;when set to \&quot;#{v}\&quot;&quot;)
         end
       end    
@@ -411,9 +411,9 @@ module ThoughtBot # :nodoc:
         attributes.each do |attribute|
           attribute = attribute.to_sym
           should &quot;only allow numeric values for #{attribute}&quot; do
-            assert object = klass.find(:first), &quot;Can't find first #{klass}&quot;
-            object.send(:&quot;#{attribute}=&quot;, &quot;abcd&quot;)
-            assert !object.valid?, &quot;Instance is still valid&quot;
+            object = klass.new
+            object.send(&quot;#{attribute}=&quot;, &quot;abcd&quot;)
+            assert !object.valid?, &quot;#{klass} allowed \&quot;abcd\&quot; as a value for #{attribute}&quot;
             assert_contains(object.errors.on(attribute), message)
           end
         end</diff>
      <filename>lib/shoulda/active_record_helpers.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5aed59248b6292be6dba3a928db5f73b24ae1213</id>
    </parent>
  </parents>
  <author>
    <name>Ryan McGeary</name>
    <email>ryanongit@mcgeary.org</email>
  </author>
  <url>http://github.com/rmm5t/shoulda/commit/e5cee5cf75280147566ab6be7da125d127adbf37</url>
  <id>e5cee5cf75280147566ab6be7da125d127adbf37</id>
  <committed-date>2008-06-27T20:14:02-07:00</committed-date>
  <authored-date>2008-06-27T20:14:02-07:00</authored-date>
  <message>Removed unnecessary database access for several active record macro helpers</message>
  <tree>f349b5a43832baea3fcfeafe81a5c562b8a0a421</tree>
  <committer>
    <name>Ryan McGeary</name>
    <email>ryanongit@mcgeary.org</email>
  </committer>
</commit>
