Skip to content

Commit

Permalink
Make case insensitive validates_uniqueness_of use unicode aware downc…
Browse files Browse the repository at this point in the history
…ase method.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
libc authored and NZKoz committed Aug 29, 2008
1 parent a9086b3 commit 743f0e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/validations.rb
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/validations_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 743f0e7

Please sign in to comment.