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 c98cb8f commit 923f4ecad202e45ef117d592053c8b86549eb9d7 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
@@ -665,7 +665,7 @@ def validates_uniqueness_of(*attr_names)
condition_params = [value]
else
condition_sql = "LOWER(#{sql_attribute}) #{comparison_operator}"
- 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 923f4ec

Please sign in to comment.