Skip to content

Commit

Permalink
Make case insensitive validates_uniqueness_of use unicode aware downc…
Browse files Browse the repository at this point in the history
…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
tarmo committed Aug 29, 2008
1 parent 08b0c8d commit 184ae2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/validations.rb
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/validations_test.rb
Expand Up @@ -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
Expand Down

4 comments on commit 184ae2c

@yaroslav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@NZKoz
Copy link
Member

@NZKoz NZKoz commented on 184ae2c Aug 30, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@geoffgarside
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

@yaroslav
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.