Commit e920414e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'gitlab-ee-d39de0ea-backport' into 'master'

Port GitLab EE ProjectsFinder changes

These changes were added in GitLab EE commit
d39de0ea. The tests were a bit bugged
(they used a non existing group, thus not testing a crucial part) which
I only noticed when porting CE changes to EE.

See merge request !1854
parents 03755fb3 fed059a1
...@@ -23,17 +23,17 @@ class ProjectsFinder ...@@ -23,17 +23,17 @@ class ProjectsFinder
group = options[:group] group = options[:group]
if group if group
base, extra = group_projects(current_user, group) segments = group_projects(current_user, group)
else else
base, extra = all_projects(current_user) segments = all_projects(current_user)
end end
if base and extra if segments.length > 1
union = Gitlab::SQL::Union.new([base.select(:id), extra.select(:id)]) union = Gitlab::SQL::Union.new(segments.map { |s| s.select(:id) })
Project.where("projects.id IN (#{union.to_sql})") Project.where("projects.id IN (#{union.to_sql})")
else else
base segments.first
end end
end end
......
...@@ -3,10 +3,19 @@ require 'spec_helper' ...@@ -3,10 +3,19 @@ require 'spec_helper'
describe ProjectsFinder do describe ProjectsFinder do
describe '#execute' do describe '#execute' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:group) { create(:group) }
let!(:private_project) { create(:project, :private) } let!(:private_project) do
let!(:internal_project) { create(:project, :internal) } create(:project, :private, name: 'A', path: 'A')
let!(:public_project) { create(:project, :public) } end
let!(:internal_project) do
create(:project, :internal, group: group, name: 'B', path: 'B')
end
let!(:public_project) do
create(:project, :public, group: group, name: 'C', path: 'C')
end
let(:finder) { described_class.new } let(:finder) { described_class.new }
...@@ -38,8 +47,6 @@ describe ProjectsFinder do ...@@ -38,8 +47,6 @@ describe ProjectsFinder do
end end
describe 'with a group' do describe 'with a group' do
let(:group) { public_project.group }
describe 'without a user' do describe 'without a user' do
subject { finder.execute(nil, group: group) } subject { finder.execute(nil, group: group) }
......
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