diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-11 01:53:54 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-12-11 01:53:54 +0000 |
commit | f67add4283069653f5707bd45cff214913dfc579 (patch) | |
tree | 38e9c474c0e04b0a2abe5534185e20923b474773 /activerecord | |
parent | 9aca06fbee44479eb8cccc5c19ecd8a85f0e0060 (diff) | |
download | rails-f67add4283069653f5707bd45cff214913dfc579.tar.gz rails-f67add4283069653f5707bd45cff214913dfc579.tar.bz2 rails-f67add4283069653f5707bd45cff214913dfc579.zip |
Base.exists? doesn't rescue exceptions to avoid hiding SQL errors. Closes #10458.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8375 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 5 | ||||
-rw-r--r-- | activerecord/test/finder_test.rb | 10 |
3 files changed, 13 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 12ff96f64f..7d924284a4 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Base.exists? doesn't rescue exceptions to avoid hiding SQL errors. #10458 [Michael Klishin] + * Documentation: Active Record exceptions, destroy_all and delete_all. #10444, #10447 [Michael Klishin] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 03aff854fa..77565b805d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -550,9 +550,8 @@ module ActiveRecord #:nodoc: # Person.exists?(:name => "David") # Person.exists?(['name LIKE ?', "%#{query}%"]) def exists?(id_or_conditions) - !find(:first, :select => "#{table_name}.#{primary_key}", :conditions => expand_id_conditions(id_or_conditions)).nil? - rescue ActiveRecord::ActiveRecordError - false + !find(:first, :select => "#{quoted_table_name}.#{primary_key}", + :conditions => expand_id_conditions(id_or_conditions)).nil? end # Creates an object (or multiple objects) and saves it to the database, if validations pass. diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 0c7a519bbb..13cac2ac22 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -28,7 +28,15 @@ class FinderTest < Test::Unit::TestCase assert Topic.exists?(:author_name => "Mary", :approved => true) assert Topic.exists?(["parent_id = ?", 1]) assert !Topic.exists?(45) - assert !Topic.exists?("foo") + + begin + assert !Topic.exists?("foo") + rescue ActiveRecord::StatementInvalid + # PostgreSQL complains about string comparison with integer field + rescue Exception + flunk + end + assert_raise(NoMethodError) { Topic.exists?([1,2]) } end |