Verified Commit b401b302 authored by Yorick Peterse's avatar Yorick Peterse 🌴

Allow usage of any_projects? with an Array

In some cases we pass an Array to this method which would previously
fail since Array does not respond to "limit_value".

Fixes gitlab-org/gitlab-ce#3646
parent 4a2a6d52
Pipeline #10878306 passed with stages
in 71 minutes and 26 seconds
......@@ -234,6 +234,8 @@ module ProjectsHelper
# If no limit is applied we'll just issue a COUNT since the result set could
# be too large to load into memory.
def any_projects?(projects)
return projects.any? if projects.is_a?(Array)
if projects.limit_value
......@@ -432,9 +432,7 @@ describe ProjectsHelper do
describe '#any_projects?' do
before do
let!(:project) { create(:project) }
it 'returns true when projects will be returned' do
expect(helper.any_projects?(Project.all)).to eq(true)
......@@ -444,6 +442,14 @@ describe ProjectsHelper do
expect(helper.any_projects?(Project.none)).to eq(false)
it 'returns true when using a non-empty Array' do
expect(helper.any_projects?([project])).to eq(true)
it 'returns false when using an empty Array' do
expect(helper.any_projects?([])).to eq(false)
it 'only executes a single query when a LIMIT is applied' do
relation = Project.limit(1)
recorder = do
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment