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 https://gitlab.com/gitlab-org/gitlab-ce/issues/3646
This commit is contained in:
parent
4a2a6d521a
commit
b401b3025b
|
@ -234,6 +234,8 @@ module ProjectsHelper
|
||||||
# If no limit is applied we'll just issue a COUNT since the result set could
|
# If no limit is applied we'll just issue a COUNT since the result set could
|
||||||
# be too large to load into memory.
|
# be too large to load into memory.
|
||||||
def any_projects?(projects)
|
def any_projects?(projects)
|
||||||
|
return projects.any? if projects.is_a?(Array)
|
||||||
|
|
||||||
if projects.limit_value
|
if projects.limit_value
|
||||||
projects.to_a.any?
|
projects.to_a.any?
|
||||||
else
|
else
|
||||||
|
|
|
@ -432,9 +432,7 @@ describe ProjectsHelper do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#any_projects?' do
|
describe '#any_projects?' do
|
||||||
before do
|
let!(:project) { create(:project) }
|
||||||
create(:project)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true when projects will be returned' do
|
it 'returns true when projects will be returned' do
|
||||||
expect(helper.any_projects?(Project.all)).to eq(true)
|
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)
|
expect(helper.any_projects?(Project.none)).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns true when using a non-empty Array' do
|
||||||
|
expect(helper.any_projects?([project])).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when using an empty Array' do
|
||||||
|
expect(helper.any_projects?([])).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
it 'only executes a single query when a LIMIT is applied' do
|
it 'only executes a single query when a LIMIT is applied' do
|
||||||
relation = Project.limit(1)
|
relation = Project.limit(1)
|
||||||
recorder = ActiveRecord::QueryRecorder.new do
|
recorder = ActiveRecord::QueryRecorder.new do
|
||||||
|
|
Loading…
Reference in New Issue