diff options
author | wmoxam <wesley.moxam@savvica.com> | 2008-09-11 11:33:15 -0400 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-09-11 17:40:14 +0200 |
commit | 923f4ecad202e45ef117d592053c8b86549eb9d7 (patch) | |
tree | cd3cb4e898b3b8eab54144e3861e77b108da9fc5 | |
parent | c98cb8ffc2f42bff565994951af9412e52fcdc58 (diff) | |
download | rails-923f4ecad202e45ef117d592053c8b86549eb9d7.tar.gz rails-923f4ecad202e45ef117d592053c8b86549eb9d7.tar.bz2 rails-923f4ecad202e45ef117d592053c8b86549eb9d7.zip |
Fixes validates_uniquness_of problem with case insensitive string containing newline characters
Signed-off-by: Michael Koziarski <michael@koziarski.com>
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/validations_test.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 577e30ec86..ac7a87d59f 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -665,7 +665,7 @@ module ActiveRecord 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] diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 1f5f9fd489..c049659327 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -364,6 +364,13 @@ class ValidationsTest < ActiveRecord::TestCase 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") |