Skip to content
This repository
Browse code

Ensure checked value is a string when validating case-sensitive uniqu…

…eness [#361 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit f2059393481ceb632abc7a9d92670e409020d5bd 1 parent cab168a
Tom Ward authored July 19, 2008 lifo committed July 19, 2008
2  activerecord/lib/active_record/validations.rb
@@ -664,7 +664,7 @@ def validates_uniqueness_of(*attr_names)
664 664
             # As MySQL/Postgres don't have case sensitive SELECT queries, we try to find duplicate
665 665
             # column in ruby when case sensitive option
666 666
             if configuration[:case_sensitive] && finder_class.columns_hash[attr_name.to_s].text?
667  
-              found = results.any? { |a| a[attr_name.to_s] == value }
  667
+              found = results.any? { |a| a[attr_name.to_s] == value.to_s }
668 668
             end
669 669
             
670 670
             if found
9  activerecord/test/cases/validations_test.rb
@@ -477,6 +477,15 @@ def test_validate_case_sensitive_uniqueness
477 477
     assert_not_equal "has already been taken", t3.errors.on(:title)
478 478
   end
479 479
 
  480
+  def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
  481
+    Topic.validates_uniqueness_of(:title, :case_sensitve => true)
  482
+    t = Topic.create!('title' => 101)
  483
+
  484
+    t2 = Topic.new('title' => 101)
  485
+    assert !t2.valid?
  486
+    assert t2.errors.on(:title)
  487
+  end
  488
+
480 489
   def test_validate_uniqueness_with_non_standard_table_names
481 490
     i1 = WarehouseThing.create(:value => 1000)
482 491
     assert !i1.valid?, "i1 should not be valid"

0 notes on commit f205939

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