Skip to content

Commit

Permalink
Ensure checked value is a string when validating case-sensitive uniqu…
Browse files Browse the repository at this point in the history
…eness [#361 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
tomafro authored and lifo committed Jul 19, 2008
1 parent cab168a commit f205939
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/validations.rb
Expand Up @@ -664,7 +664,7 @@ def validates_uniqueness_of(*attr_names)
# As MySQL/Postgres don't have case sensitive SELECT queries, we try to find duplicate
# column in ruby when case sensitive option
if configuration[:case_sensitive] && finder_class.columns_hash[attr_name.to_s].text?
found = results.any? { |a| a[attr_name.to_s] == value }
found = results.any? { |a| a[attr_name.to_s] == value.to_s }
end

if found
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/validations_test.rb
Expand Up @@ -477,6 +477,15 @@ def test_validate_case_sensitive_uniqueness
assert_not_equal "has already been taken", t3.errors.on(:title)
end

def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
Topic.validates_uniqueness_of(:title, :case_sensitve => true)
t = Topic.create!('title' => 101)

t2 = Topic.new('title' => 101)
assert !t2.valid?
assert t2.errors.on(:title)
end

def test_validate_uniqueness_with_non_standard_table_names
i1 = WarehouseThing.create(:value => 1000)
assert !i1.valid?, "i1 should not be valid"
Expand Down

0 comments on commit f205939

Please sign in to comment.