diff options
author | Eugene Pimenov <libc@mac.com> | 2008-08-29 14:36:00 +0400 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-08-29 20:24:20 +0200 |
commit | 743f0e7114b071bf7786a80227c12dcc7ccee6c1 (patch) | |
tree | 54ac538042ba3e6caa556bec65f42a4c20385cd4 /activerecord | |
parent | a9086b3daa0a5174ba2118a2131eb5121f32d41b (diff) | |
download | rails-743f0e7114b071bf7786a80227c12dcc7ccee6c1.tar.gz rails-743f0e7114b071bf7786a80227c12dcc7ccee6c1.tar.bz2 rails-743f0e7114b071bf7786a80227c12dcc7ccee6c1.zip |
Make case insensitive validates_uniqueness_of use unicode aware downcase method.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/validations_test.rb | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 8fe4336bbc..9ee80e6655 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -664,7 +664,7 @@ module ActiveRecord 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] diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index a40bda2533..4999d93a86 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -451,6 +451,18 @@ class ValidationsTest < ActiveRecord::TestCase 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 |