Skip to content
Browse files

Make case insensitive validates_uniqueness_of use unicode aware downc…

…ase method.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent a9086b3 commit 743f0e7114b071bf7786a80227c12dcc7ccee6c1 @libc libc committed with NZKoz
Showing with 13 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/validations.rb
  2. +12 −0 activerecord/test/cases/validations_test.rb
View
2 activerecord/lib/active_record/validations.rb
@@ -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]
View
12 activerecord/test/cases/validations_test.rb
@@ -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

0 comments on commit 743f0e7

Please sign in to comment.
Something went wrong with that request. Please try again.