2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe JoinedGroupsFinder do
|
|
|
|
describe '#execute' do
|
|
|
|
let!(:profile_owner) { create(:user) }
|
|
|
|
let!(:profile_visitor) { create(:user) }
|
|
|
|
|
|
|
|
let!(:private_group) { create(:group, :private) }
|
|
|
|
let!(:private_group_2) { create(:group, :private) }
|
|
|
|
let!(:internal_group) { create(:group, :internal) }
|
|
|
|
let!(:internal_group_2) { create(:group, :internal) }
|
|
|
|
let!(:public_group) { create(:group, :public) }
|
|
|
|
let!(:public_group_2) { create(:group, :public) }
|
|
|
|
let!(:finder) { described_class.new(profile_owner) }
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
public_group.add_maintainer(profile_owner)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'only shows public groups from profile owner' do
|
|
|
|
expect(finder.execute).to eq([public_group])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a user" do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
private_group.add_maintainer(profile_owner)
|
|
|
|
internal_group.add_maintainer(profile_owner)
|
|
|
|
public_group.add_maintainer(profile_owner)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "when the profile visitor is in the private group" do
|
|
|
|
before do
|
|
|
|
private_group.add_developer(profile_visitor)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only shows groups where both users are authorized to see' do
|
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if profile visitor is in one of the private group projects' do
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
project = create(:project, :private, group: private_group, name: 'B', path: 'B')
|
2016-11-03 12:29:30 +05:30
|
|
|
project.add_user(profile_visitor, Gitlab::Access::DEVELOPER)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows group' do
|
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'external users' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
profile_visitor.update(external: true)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'if not a member' do
|
|
|
|
it "does not show internal groups" do
|
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "if authorized" do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
internal_group.add_maintainer(profile_visitor)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "shows internal groups if authorized" do
|
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group, internal_group])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|