public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure checked value is a string when validating case-sensitive uniqueness [#361 
state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
tomafro (author)
Sat Jul 19 01:58:09 -0700 2008
lifo (committer)
Sat Jul 19 08:14:39 -0700 2008
commit  f2059393481ceb632abc7a9d92670e409020d5bd
tree    42dc11440ca28e59d2c49b9e2bde61ee98ce23e1
parent  cab168ac9bbe24e5842fb7677d3fac820ddbc18c
...
664
665
666
667
 
668
669
670
...
664
665
666
 
667
668
669
670
0
@@ -664,7 +664,7 @@ module ActiveRecord
0
             # As MySQL/Postgres don't have case sensitive SELECT queries, we try to find duplicate
0
             # column in ruby when case sensitive option
0
             if configuration[:case_sensitive] && finder_class.columns_hash[attr_name.to_s].text?
0
-              found = results.any? { |a| a[attr_name.to_s] == value }
0
+              found = results.any? { |a| a[attr_name.to_s] == value.to_s }
0
             end
0
             
0
             if found
...
477
478
479
 
 
 
 
 
 
 
 
 
480
481
482
...
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
0
@@ -477,6 +477,15 @@ class ValidationsTest < ActiveRecord::TestCase
0
     assert_not_equal "has already been taken", t3.errors.on(:title)
0
   end
0
 
0
+  def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
0
+    Topic.validates_uniqueness_of(:title, :case_sensitve => true)
0
+    t = Topic.create!('title' => 101)
0
+
0
+    t2 = Topic.new('title' => 101)
0
+    assert !t2.valid?
0
+    assert t2.errors.on(:title)
0
+  end
0
+
0
   def test_validate_uniqueness_with_non_standard_table_names
0
     i1 = WarehouseThing.create(:value => 1000)
0
     assert !i1.valid?, "i1 should not be valid"

Comments