<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -53,12 +53,17 @@ module ThoughtBot # :nodoc:
       #   Regexp or string.  Default = &lt;tt&gt;/taken/&lt;/tt&gt;
       # * &lt;tt&gt;:scoped_to&lt;/tt&gt; - shoulda analogue to :scope in 
       #   ActiveRecord::Base#validates_uniqueness_of.  Can be an array of values or just one.
+      # * &lt;tt&gt;:change_scoped_to_values&lt;/tt&gt; - a proc that should will call with the scoped_to 
+      #&#160;  attribute name and the existing value.  The result is what shoulda will set the new 
+      #   objects value to in order to test that changing the scoped_to attributes does allow
+      #   duplicate values of the attribute in question.  If your scoped_to attributes don't
+      #   implement .next, you need to supply this.
       #
       # Example:
       #   should_require_unique_attributes :keyword, :username
       #
       def should_require_unique_attributes(*attributes)
-        message, scope = get_options!(attributes, :message, :scoped_to)
+        message, scope, change_existing_proc = get_options!(attributes, :message, :scoped_to, :change_scoped_to_values)
         message ||= /taken/
         
         klass = model_class
@@ -107,7 +112,11 @@ module ThoughtBot # :nodoc:
               if scope.is_a? Array
                 scope.each do |scoped_attribute|
                   # Assume the scope is a foreign key if the field is nil
-                  object.send(:&quot;#{scoped_attribute}=&quot;, existing.send(scoped_attribute).nil? ? 1 : existing.send(scoped_attribute).next)
+                  if change_existing_proc.nil?
+                    object.send(:&quot;#{scoped_attribute}=&quot;, existing.send(scoped_attribute).nil? ? 1 : existing.send(scoped_attribute).next)
+                  else
+                    object.send(:&quot;#{scoped_attribute}=&quot;, change_existing_proc.call(scoped_attribute, existing.send(scoped_attribute)))
+                  end
                   object.errors.clear
                   object.valid?
                   assert_does_not_contain(object.errors.on(attribute), message, 
@@ -115,7 +124,11 @@ module ThoughtBot # :nodoc:
                 end
               else
                 # Assume the scope is a foreign key if the field is nil
-                object.send(:&quot;#{scope}=&quot;, existing.send(scope).nil? ? 1 : existing.send(scope).next)
+                if change_existing_proc.nil?
+                  object.send(:&quot;#{scope}=&quot;, existing.send(scope).nil? ? 1 : existing.send(scope).next)
+                else
+                  object.send(:&quot;#{scope}=&quot;, change_existing_proc.call(scope, existing.send(scope)))
+                end
                 object.errors.clear
                 object.valid?
                 assert_does_not_contain(object.errors.on(attribute), message, </diff>
      <filename>lib/shoulda/active_record_helpers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,4 +2,4 @@ first:
   id: 1
   user_group_id: 1
   location: London
-  happens_on: 2008-01-01
+  happens_on: 2008-01-01 18:00:00</diff>
      <filename>test/fixtures/meetings.yml</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ class CreateUserGroupsAndMembershipsAndMeetings &lt; ActiveRecord::Migration
     create_table :meetings do |t|
       t.integer :user_group_id
       t.string :location
-      t.date :happens_on
+      t.time :happens_on
     end
   end
 </diff>
      <filename>test/rails_root/db/migrate/009_create_user_groups_and_memberships_and_meetings.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,5 +9,13 @@ class MeetingTest &lt; Test::Unit::TestCase
 
   should_require_attributes :user_group_id, :location, :happens_on
   
-  should_require_unique_attributes :user_group_id, :scoped_to =&gt; [:location, :happens_on]
+  should_require_unique_attributes :user_group_id, 
+                                   :scoped_to =&gt; [:location, :happens_on],
+                                   :change_scoped_to_values =&gt; lambda {|attr, value|
+                                                                        if attr == :happens_on
+                                                                          value + 1.hours
+                                                                        else
+                                                                          value.next
+                                                                        end
+                                                                      }
 end</diff>
      <filename>test/unit/meeting_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2c13f67c35778978481f8250ed39e327df7e6311</id>
    </parent>
  </parents>
  <author>
    <name>Murray Steele</name>
    <email>muz@h-lame.com</email>
  </author>
  <url>http://github.com/h-lame/shoulda/commit/25d5079094d7296d88c222eb2699d267f213ce19</url>
  <id>25d5079094d7296d88c222eb2699d267f213ce19</id>
  <committed-date>2008-05-21T01:14:39-07:00</committed-date>
  <authored-date>2008-05-20T04:32:46-07:00</authored-date>
  <message>Add support for testing scoped attribtues in should_require_unique_attributes that don't respond to .next.

If the values of the existing object don't respond to .next (e.g. Time, or perhaps serialized attributes) but you want to use them as the scope for validating the uniqueness of another attribute shoulda will break by attempting to call .next on them.  This patch allows you to supply a :change_scoped_to_values option to should_require_unique_attributes to help with this.  The :change_scoped_to_values option is expected to be a proc that will be called with the scoped_to attribute name and it's current value, the result of this proc will be set as the attribute on the existing object.</message>
  <tree>88f5cf2569136de3d2d813e4102722b62f5d35b9</tree>
  <committer>
    <name>Murray Steele</name>
    <email>muz@h-lame.com</email>
  </committer>
</commit>
