mirror of
https://github.com/github/rails.git
synced 2026-01-30 16:58:15 -05:00
Ensure that validates_uniqueness_of works with with_scope. Closes #9235. [nik.wakelin, cavalle]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9168 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Ensure that validates_uniqueness_of works with with_scope. Closes #9235. [nik.wakelin, cavalle]
|
||||
|
||||
* Partial updates include only unsaved attributes. Off by default; set YourClass.partial_updates = true to enable. [Jeremy Kemper]
|
||||
|
||||
* Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled [Geoff Buesing]
|
||||
|
||||
@@ -654,13 +654,15 @@ module ActiveRecord
|
||||
condition_params << record.send(:id)
|
||||
end
|
||||
|
||||
results = connection.select_all(
|
||||
construct_finder_sql(
|
||||
:select => "#{attr_name}",
|
||||
:from => "#{finder_class.quoted_table_name}",
|
||||
:conditions => [condition_sql, *condition_params]
|
||||
results = finder_class.with_exclusive_scope do
|
||||
connection.select_all(
|
||||
construct_finder_sql(
|
||||
:select => "#{attr_name}",
|
||||
:from => "#{finder_class.quoted_table_name}",
|
||||
:conditions => [condition_sql, *condition_params]
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
unless results.length.zero?
|
||||
found = true
|
||||
|
||||
@@ -467,6 +467,16 @@ class ValidationsTest < ActiveRecord::TestCase
|
||||
assert i1.errors.on(:value), "Should not be empty"
|
||||
end
|
||||
|
||||
def test_validates_uniqueness_inside_with_scope
|
||||
Topic.validates_uniqueness_of(:title)
|
||||
|
||||
Topic.with_scope(:find => { :conditions => { :author_name => "David" } }) do
|
||||
t1 = Topic.new("title" => "I'm unique!", "author_name" => "Mary")
|
||||
assert t1.save
|
||||
t2 = Topic.new("title" => "I'm unique!", "author_name" => "David")
|
||||
assert !t2.valid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_validate_straight_inheritance_uniqueness
|
||||
w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
|
||||
|
||||
Reference in New Issue
Block a user