<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/fixtures/addresses.yml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -51,25 +51,32 @@ 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;/taken/&lt;/tt&gt;
+      # * &lt;tt&gt;:scoped_to&lt;/tt&gt; - field(s) to scope the uniqueness to.
       #
-      # Example:
+      # Examples:
       #   should_require_unique_attributes :keyword, :username
+      #   should_require_unique_attributes :name, :message =&gt; &quot;O NOES! SOMEONE STOELED YER NAME!&quot;
+      #   should_require_unique_attributes :email, :scoped_to =&gt; :name
+      #   should_require_unique_attributes :address, :scoped_to =&gt; [:first_name, :last_name]
       #
       def should_require_unique_attributes(*attributes)
         message, scope = get_options!(attributes, :message, :scoped_to)
+        scope = [*scope].compact
         message ||= /taken/
         
         klass = model_class
         attributes.each do |attribute|
           attribute = attribute.to_sym
-          should &quot;require unique value for #{attribute}#{&quot; scoped to #{scope}&quot; if scope}&quot; do
+          should &quot;require unique value for #{attribute}#{&quot; scoped to #{scope.join(', ')}&quot; if scope}&quot; do
             assert existing = klass.find(:first), &quot;Can't find first #{klass}&quot;
             object = klass.new
             
             object.send(:&quot;#{attribute}=&quot;, existing.send(attribute))
-            if scope
-              assert_respond_to object, :&quot;#{scope}=&quot;, &quot;#{klass.name} doesn't seem to have a #{scope} attribute.&quot;
-              object.send(:&quot;#{scope}=&quot;, existing.send(scope))
+            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))
+              end
             end
             
             assert !object.valid?, &quot;#{klass.name} does not require a unique value for #{attribute}.&quot;
@@ -82,13 +89,18 @@ module ThoughtBot # :nodoc:
             # to a value that's already taken.  An alternative implementation
             # could actually find all values for scope and create a unique
             # one.  
-            if scope
+            if !scope.blank?
+              scope.each do |s|
               # 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)
+                object.send(:&quot;#{s}=&quot;, existing.send(s).nil? ? 1 : existing.send(s).next)
+              end
+
               object.errors.clear
               object.valid?
-              assert_does_not_contain(object.errors.on(attribute), message, 
-                                      &quot;after :#{scope} set to #{object.send(scope.to_sym)}&quot;)
+              scope.each do |s|
+                assert_does_not_contain(object.errors.on(attribute), message, 
+                                        &quot;after :#{s} set to #{object.send(s.to_sym)}&quot;)
+              end
             end
           end
         end</diff>
      <filename>lib/shoulda/active_record_helpers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
 class Address &lt; ActiveRecord::Base
   belongs_to :addressable, :polymorphic =&gt; true
+  validates_uniqueness_of :title, :scope =&gt; [:addressable_type, :addressable_id]
 end</diff>
      <filename>test/rails_root/app/models/address.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,4 +10,5 @@ class User &lt; ActiveRecord::Base
   validates_length_of :email, :in =&gt; 1..100
   validates_inclusion_of :age, :in =&gt; 1..100
   validates_acceptance_of :eula
+  validates_uniqueness_of :email, :scope =&gt; :name
 end</diff>
      <filename>test/rails_root/app/models/user.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,7 @@
 class CreateAddresses &lt; ActiveRecord::Migration
   def self.up
     create_table :addresses do |t|
+      t.column :title, :string
       t.column :addressable_id, :integer
       t.column :addressable_type, :string
     end</diff>
      <filename>test/rails_root/db/migrate/006_create_addresses.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,4 +3,5 @@ require File.dirname(__FILE__) + '/../test_helper'
 class AddressTest &lt; Test::Unit::TestCase
   load_all_fixtures
   should_belong_to :addressable
+  should_require_unique_attributes :title, :scoped_to =&gt; [:addressable_id, :addressable_type]
 end</diff>
      <filename>test/unit/address_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,4 +23,5 @@ class UserTest &lt; Test::Unit::TestCase
   should_have_db_column :email, :type =&gt; &quot;string&quot;, :default =&gt; nil,   :precision =&gt; nil, :limit    =&gt; 255, 
                                 :null =&gt; true,     :primary =&gt; false, :scale     =&gt; nil, :sql_type =&gt; 'varchar(255)'
   should_require_acceptance_of :eula
+  should_require_unique_attributes :email, :scoped_to =&gt; :name
 end</diff>
      <filename>test/unit/user_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>9c78fe05a1897acc9455115725c09f408f5f67ba</id>
    </parent>
  </parents>
  <author>
    <name>Nathan Sutton</name>
    <email>nate@sevenwire.com</email>
  </author>
  <url>http://github.com/snowblink/shoulda/commit/911b2f7cb43e8afb1395e55be9334bcd533fe330</url>
  <id>911b2f7cb43e8afb1395e55be9334bcd533fe330</id>
  <committed-date>2008-05-29T16:48:39-07:00</committed-date>
  <authored-date>2008-05-29T16:48:39-07:00</authored-date>
  <message>Scoping of uniqueness validations on multiple attributes

Previously the :scoped_to option on the 'should_require_unique_attributes'
only allowed a single attribute to scope uniqueness.  This adds the ability to
scope to multiple attributes.  This also improves the documentation for the
method.</message>
  <tree>94e6a396be93466a321e221971873f75c6e3c8e9</tree>
  <committer>
    <name>Nathan Sutton</name>
    <email>nate@sevenwire.com</email>
  </committer>
</commit>
