2020-02-20 04:09:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe ForkTargetsFinder do
|
2020-02-20 04:09:13 -05:00
|
|
|
subject(:finder) { described_class.new(project, user) }
|
|
|
|
|
|
|
|
let(:project) { create(:project, namespace: create(:group)) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:maintained_group) do
|
|
|
|
create(:group).tap { |g| g.add_maintainer(user) }
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-02-20 04:09:13 -05:00
|
|
|
let!(:owned_group) do
|
|
|
|
create(:group).tap { |g| g.add_owner(user) }
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-02-20 04:09:13 -05:00
|
|
|
let!(:developer_group) do
|
2022-01-18 16:16:02 -05:00
|
|
|
create(:group, project_creation_level: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS).tap do |g|
|
|
|
|
g.add_developer(user)
|
|
|
|
end
|
2020-02-20 04:09:13 -05:00
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-02-20 04:09:13 -05:00
|
|
|
let!(:reporter_group) do
|
|
|
|
create(:group).tap { |g| g.add_reporter(user) }
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-02-20 04:09:13 -05:00
|
|
|
let!(:guest_group) do
|
|
|
|
create(:group).tap { |g| g.add_guest(user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.namespace.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
2020-03-03 13:08:16 -05:00
|
|
|
it 'returns all user manageable namespaces' do
|
2022-01-18 16:16:02 -05:00
|
|
|
expect(finder.execute).to match_array([user.namespace, maintained_group, owned_group, project.namespace, developer_group])
|
2020-02-20 04:09:13 -05:00
|
|
|
end
|
2020-08-20 20:10:44 -04:00
|
|
|
|
|
|
|
it 'returns only groups when only_groups option is passed' do
|
2022-01-18 16:16:02 -05:00
|
|
|
expect(finder.execute(only_groups: true)).to match_array([maintained_group, owned_group, project.namespace, developer_group])
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns groups relation when only_groups option is passed' do
|
|
|
|
expect(finder.execute(only_groups: true)).to include(a_kind_of(Group))
|
|
|
|
end
|
2020-02-20 04:09:13 -05:00
|
|
|
end
|
|
|
|
end
|