提交 92cd8811 编写于 作者: P Pratik Naik

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
上级 cc2d6a0b
*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 @@ def validates_uniqueness_of(*attr_names)
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 @@ def test_validate_uniqueness_with_non_standard_table_names
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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册