Merge pull request #6521 from Empact/throw-result

Fix that #exists? can blow up with ThrowResult exception
This commit is contained in:
Rafael Mendonça França 2012-06-10 18:03:41 -07:00
commit f48e7676e9
2 changed files with 8 additions and 1 deletions

@ -186,6 +186,8 @@ def exists?(id = false)
end end
connection.select_value(relation, "#{name} Exists", relation.bind_values) connection.select_value(relation, "#{name} Exists", relation.bind_values)
rescue ThrowResult
false
end end
protected protected

@ -69,7 +69,12 @@ def test_exists_with_order
assert Topic.order(:id).uniq.exists? assert Topic.order(:id).uniq.exists?
end 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 Topic.delete_all
assert !Topic.exists? assert !Topic.exists?
end end