Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9168

Show
Ignore:
Timestamp:
03/31/08 12:57:47 (5 months ago)
Author:
pratik
Message:

Ensure that validates_uniqueness_of works with with_scope. Closes #9235. [nik.wakelin, cavalle]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r9157 r9168  
    11*SVN* 
     2 
     3* Ensure that validates_uniqueness_of works with with_scope. Closes #9235. [nik.wakelin, cavalle] 
    24 
    35* Partial updates include only unsaved attributes. Off by default; set YourClass.partial_updates = true to enable.  [Jeremy Kemper] 
  • trunk/activerecord/lib/active_record/validations.rb

    r9160 r9168  
    655655          end 
    656656 
    657           results = connection.select_all( 
    658             construct_finder_sql( 
    659               :select     => "#{attr_name}", 
    660               :from       => "#{finder_class.quoted_table_name}", 
    661               :conditions => [condition_sql, *condition_params] 
     657          results = finder_class.with_exclusive_scope do 
     658            connection.select_all( 
     659              construct_finder_sql( 
     660                :select     => "#{attr_name}", 
     661                :from       => "#{finder_class.quoted_table_name}", 
     662                :conditions => [condition_sql, *condition_params] 
     663              ) 
    662664            ) 
    663           ) 
     665          end 
    664666 
    665667          unless results.length.zero? 
  • trunk/activerecord/test/cases/validations_test.rb

    r9160 r9168  
    468468  end 
    469469 
     470  def test_validates_uniqueness_inside_with_scope 
     471    Topic.validates_uniqueness_of(:title) 
     472 
     473    Topic.with_scope(:find => { :conditions => { :author_name => "David" } }) do 
     474      t1 = Topic.new("title" => "I'm unique!", "author_name" => "Mary") 
     475      assert t1.save 
     476      t2 = Topic.new("title" => "I'm unique!", "author_name" => "David") 
     477      assert !t2.valid? 
     478    end 
     479  end 
    470480 
    471481  def test_validate_straight_inheritance_uniqueness