提交 743f0e71 编写于 作者: E Eugene Pimenov 提交者: Michael Koziarski

Make case insensitive validates_uniqueness_of use unicode aware downcase method.

Signed-off-by: NMichael Koziarski <michael@koziarski.com>
上级 a9086b3d
......@@ -664,7 +664,7 @@ def validates_uniqueness_of(*attr_names)
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 @@ def test_validate_case_insensitive_uniqueness
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册