aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-03-04 19:59:58 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-03-04 19:59:58 -0800
commitef7e7ad7e9c11916865b7e3e9f0c754a4e6fc775 (patch)
treef26982595a12baeede08963ccf90da1250186714 /activerecord/test/cases/finder_test.rb
parentccf8f27dddcc36fa5c91f614647e0b0bac861d83 (diff)
parentf317cc8bc007978d7b135ddd1acdd7e3d1e582a3 (diff)
downloadrails-ef7e7ad7e9c11916865b7e3e9f0c754a4e6fc775.tar.gz
rails-ef7e7ad7e9c11916865b7e3e9f0c754a4e6fc775.tar.bz2
rails-ef7e7ad7e9c11916865b7e3e9f0c754a4e6fc775.zip
Merge pull request #14261 from MSch/bound-parameters-for-exists
Make exists? use bound values.
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r--activerecord/test/cases/finder_test.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index b1eded6494..78c4e02434 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -58,15 +58,27 @@ class FinderTest < ActiveRecord::TestCase
assert_equal false, Topic.exists?(45)
assert_equal false, Topic.exists?(Topic.new)
+ assert_raise(NoMethodError) { Topic.exists?([1,2]) }
+ end
+
+ def test_exists_fails_when_parameter_has_invalid_type
+ begin
+ assert_equal false, Topic.exists?(("9"*53).to_i) # number that's bigger than int
+ flunk if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter and Topic.connection.is_a? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter # PostgreSQL does raise here
+ rescue ActiveRecord::StatementInvalid
+ # PostgreSQL complains that it can't coerce a numeric that's bigger than int into int
+ rescue Exception
+ flunk
+ end
+
begin
assert_equal false, Topic.exists?("foo")
+ flunk if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter and Topic.connection.is_a? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter # PostgreSQL does raise here
rescue ActiveRecord::StatementInvalid
# PostgreSQL complains about string comparison with integer field
rescue Exception
flunk
end
-
- assert_raise(NoMethodError) { Topic.exists?([1,2]) }
end
def test_exists_does_not_select_columns_without_alias