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. 
[#932 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>

Conflicts:

  activerecord/lib/active_record/validations.rb

Signed-off-by: Tarmo Tänav <tarmo@itech.ee>
Tarmo Tänav (author)
Fri Aug 29 11:52:10 -0700 2008
commit  184ae2ccb49f0e408fe7d9ba7fe2d1bc5470bc8a
tree    5c9f0d43a852ef58997d703e273a5329f9efc2ec
parent  08b0c8da7f0790eb1ade2b789c2bbe1580bf6859
...
631
632
633
634
 
635
636
637
...
631
632
633
 
634
635
636
637
0
@@ -631,7 +631,7 @@ module ActiveRecord
0
             # sqlite has case sensitive SELECT query, while MySQL/Postgresql don't.
0
             # Hence, this is needed only for sqlite.
0
             condition_sql = "LOWER(#{record.class.quoted_table_name}.#{attr_name}) #{attribute_condition(value)}"
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

yaroslav Fri Aug 29 12:03:02 -0700 2008

Thanks! Sad it was not there. So you happen to speak russian? :)

NZKoz Sat Aug 30 02:46:40 -0700 2008

Not at all, here’s hoping it doesn’t say rails sucks or something…

geoffgarside Sat Aug 30 03:36:53 -0700 2008

Well according to Dashboard Translate widget it says “4 the also UNIQUE”

“Rails sucks” would be “Рельсы всасывают” apparently :P

yaroslav Sat Aug 30 03:41:00 -0700 2008

@NZKoz it says “I am UNIQUE as well!”