Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix that #exists? can blow up with ThrowResult exception #6521

Merged
merged 1 commit into from Jun 11, 2012
Jump to file or symbol
Failed to load files and symbols.
+8 −1
Split
@@ -186,6 +186,8 @@ def exists?(id = false)
end
connection.select_value(relation, "#{name} Exists", relation.bind_values)
+ 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