Permalink
Browse files

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
  • Loading branch information...
1 parent 9e6eb8b commit bbec883edb350cc9f75beea183e335b91a11e242 @rafaelfranca rafaelfranca committed Jun 11, 2012
@@ -200,6 +200,8 @@ def exists?(id = false)
end
connection.select_value(relation, "#{name} Exists") ? true : false
+ rescue ThrowResult
+ false
end
protected
@@ -69,7 +69,12 @@ def test_exists_with_order
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

0 comments on commit bbec883

Please sign in to comment.