Skip to content
This repository
Browse code

Fixes validates_uniquness_of problem with case insensitive string con…

…taining newline characters

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
commit 91c14e92686fcfd9dad04d57563aa6ce385d2a81 1 parent ba342c2
wmoxam authored NZKoz committed
2  activerecord/lib/active_record/validations.rb
@@ -631,7 +631,7 @@ def validates_uniqueness_of(*attr_names)
631 631 # sqlite has case sensitive SELECT query, while MySQL/Postgresql don't.
632 632 # Hence, this is needed only for sqlite.
633 633 condition_sql = "LOWER(#{record.class.quoted_table_name}.#{attr_name}) #{attribute_condition(value)}"
634   - condition_params = [value.chars.downcase]
  634 + condition_params = [value.chars.downcase.to_s]
635 635 end
636 636
637 637 if scope = configuration[:scope]
7 activerecord/test/cases/validations_test.rb
@@ -364,6 +364,13 @@ def test_validate_uniqueness
364 364 assert t2.save, "Should now save t2 as unique"
365 365 end
366 366
  367 + def test_validates_uniquness_with_newline_chars
  368 + Topic.validates_uniqueness_of(:title, :case_sensitive => false)
  369 +
  370 + t = Topic.new("title" => "new\nline")
  371 + assert t.save, "Should save t as unique"
  372 + end
  373 +
367 374 def test_validate_uniqueness_with_scope
368 375 Reply.validates_uniqueness_of(:content, :scope => "parent_id")
369 376

0 comments on commit 91c14e9

Please sign in to comment.
Something went wrong with that request. Please try again.