Permalink
Browse files

Fixes validates_uniquness_of problem with case insensitive string con…

…taining newline characters

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent ba342c2 commit 91c14e92686fcfd9dad04d57563aa6ce385d2a81 wmoxam committed with NZKoz Sep 11, 2008
Showing with 8 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/validations.rb
  2. +7 −0 activerecord/test/cases/validations_test.rb
View
2 activerecord/lib/active_record/validations.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.chars.downcase]
+ condition_params = [value.chars.downcase.to_s]
end
if scope = configuration[:scope]
View
7 activerecord/test/cases/validations_test.rb
@@ -364,6 +364,13 @@ def test_validate_uniqueness
assert t2.save, "Should now save t2 as unique"
end
+ def test_validates_uniquness_with_newline_chars
+ Topic.validates_uniqueness_of(:title, :case_sensitive => false)
+
+ t = Topic.new("title" => "new\nline")
+ assert t.save, "Should save t as unique"
+ end
+
def test_validate_uniqueness_with_scope
Reply.validates_uniqueness_of(:content, :scope => "parent_id")

0 comments on commit 91c14e9

Please sign in to comment.