Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@tomafro tomafro authored lifo committed
View
2  activerecord/lib/active_record/validations.rb
@@ -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
View
9 activerecord/test/cases/validations_test.rb
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.