mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make case insensitive validates_uniqueness_of use unicode aware downcase method.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
parent
a9086b3daa
commit
743f0e7114
2 changed files with 13 additions and 1 deletions
|
@ -664,7 +664,7 @@ module ActiveRecord
|
|||
condition_params = [value]
|
||||
else
|
||||
condition_sql = "LOWER(#{sql_attribute}) #{comparison_operator}"
|
||||
condition_params = [value.downcase]
|
||||
condition_params = [value.chars.downcase]
|
||||
end
|
||||
|
||||
if scope = configuration[:scope]
|
||||
|
|
|
@ -451,6 +451,18 @@ class ValidationsTest < ActiveRecord::TestCase
|
|||
t2.title = nil
|
||||
assert t2.valid?, "should validate with nil"
|
||||
assert t2.save, "should save with nil"
|
||||
|
||||
with_kcode('UTF8') do
|
||||
t_utf8 = Topic.new("title" => "Я тоже уникальный!")
|
||||
assert t_utf8.save, "Should save t_utf8 as unique"
|
||||
|
||||
# If database hasn't UTF-8 character set, this test fails
|
||||
if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
|
||||
t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
|
||||
assert !t2_utf8.valid?, "Shouldn't be valid"
|
||||
assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_validate_case_sensitive_uniqueness
|
||||
|
|
Loading…
Reference in a new issue