Merge pull request #6521 from Empact/throw-result
Fix that #exists? can blow up with ThrowResult exception
This commit is contained in:
commit
f48e7676e9
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user