Merge branch 'fix-any-projects-array' into 'master'

Allow usage of any_projects? with an Array

Closes #3646

See merge request !13559
This commit is contained in:
Douwe Maan 2017-08-15 15:05:28 +00:00
commit bb9db75fcf
2 changed files with 11 additions and 3 deletions

View file

@ -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
projects.to_a.any?
else

View file

@ -432,9 +432,7 @@ describe ProjectsHelper do
end
describe '#any_projects?' do
before do
create(:project)
end
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)
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
relation = Project.limit(1)
recorder = ActiveRecord::QueryRecorder.new do