aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-10 18:03:41 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-10 22:05:38 -0300
commitbbec883edb350cc9f75beea183e335b91a11e242 (patch)
tree5f8b3f1fd88cd65109c602fec94e54ed32b8769b /activerecord
parent9e6eb8b648acf38474e46c335782c65d65b1a185 (diff)
downloadrails-bbec883edb350cc9f75beea183e335b91a11e242.tar.gz
rails-bbec883edb350cc9f75beea183e335b91a11e242.tar.bz2
rails-bbec883edb350cc9f75beea183e335b91a11e242.zip
Merge pull request #6521 from Empact/throw-result
Fix that #exists? can blow up with ThrowResult exception Conflicts: activerecord/lib/active_record/relation/finder_methods.rb
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
-rw-r--r--activerecord/test/cases/finder_test.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index fa457ae0c6..86f1d6936e 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -200,6 +200,8 @@ module ActiveRecord
end
connection.select_value(relation, "#{name} Exists") ? true : false
+ rescue ThrowResult
+ false
end
protected
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 8622a1a295..e3e3a1ca7c 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -69,7 +69,12 @@ class FinderTest < ActiveRecord::TestCase
assert Topic.order(:id).uniq.exists?
end
- def test_does_not_exist_with_empty_table_and_no_args_given
+ def test_exists_with_includes_limit_and_empty_result
+ assert !Topic.includes(:replies).limit(0).exists?
+ assert !Topic.includes(:replies).limit(1).where('0 = 1').exists?
+ end
+
+ def test_exists_with_empty_table_and_no_args_given
Topic.delete_all
assert !Topic.exists?
end