Permalink
Browse files

Make case insensitive validates_uniqueness_of use unicode aware downc…

…ase 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>
  • Loading branch information...
1 parent 08b0c8d commit 184ae2ccb49f0e408fe7d9ba7fe2d1bc5470bc8a @tarmo tarmo committed Aug 29, 2008
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
@@ -631,7 +631,7 @@ def validates_uniqueness_of(*attr_names)
# sqlite has case sensitive SELECT query, while MySQL/Postgresql don't.
# Hence, this is needed only for sqlite.
condition_sql = "LOWER(#{record.class.quoted_table_name}.#{attr_name}) #{attribute_condition(value)}"
- condition_params = [value.downcase]
+ condition_params = [value.chars.downcase]
end
if scope = configuration[:scope]
@@ -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

4 comments on commit 184ae2c

Contributor

yaroslav replied Aug 29, 2008

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

Member

NZKoz replied Aug 30, 2008

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

Contributor

geoffgarside replied Aug 30, 2008

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

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

Contributor

yaroslav replied Aug 30, 2008

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

Please sign in to comment.