public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Make case insensitive validates_uniqueness_of use unicode aware downcase method.


Signed-off-by: Michael Koziarski <michael@koziarski.com>
libc (author)
Fri Aug 29 03:36:00 -0700 2008
NZKoz (committer)
Fri Aug 29 11:24:20 -0700 2008
commit  743f0e7114b071bf7786a80227c12dcc7ccee6c1
tree    54ac538042ba3e6caa556bec65f42a4c20385cd4
parent  a9086b3daa0a5174ba2118a2131eb5121f32d41b
...
664
665
666
667
 
668
669
670
...
664
665
666
 
667
668
669
670
0
@@ -664,7 +664,7 @@ module ActiveRecord
0
             condition_params = [value]
0
           else
0
             condition_sql = "LOWER(#{sql_attribute}) #{comparison_operator}"
0
-            condition_params = [value.downcase]
0
+            condition_params = [value.chars.downcase]
0
           end
0
 
0
           if scope = configuration[:scope]
...
451
452
453
 
 
 
 
 
 
 
 
 
 
 
 
454
455
456
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
0
@@ -451,6 +451,18 @@ class ValidationsTest < ActiveRecord::TestCase
0
     t2.title = nil
0
     assert t2.valid?, "should validate with nil"
0
     assert t2.save, "should save with nil"
0
+
0
+    with_kcode('UTF8') do
0
+      t_utf8 = Topic.new("title" => "Я тоже уникальный!")
0
+      assert t_utf8.save, "Should save t_utf8 as unique"
0
+
0
+      # If database hasn't UTF-8 character set, this test fails
0
+      if Topic.find(t_utf8, :select => 'LOWER(title) AS title').title == "я тоже уникальный!"
0
+        t2_utf8 = Topic.new("title" => "я тоже УНИКАЛЬНЫЙ!")
0
+        assert !t2_utf8.valid?, "Shouldn't be valid"
0
+        assert !t2_utf8.save, "Shouldn't save t2_utf8 as unique"
0
+      end
0
+    end
0
   end
0
 
0
   def test_validate_case_sensitive_uniqueness

Comments