debian-mirror-gitlab/spec/finders/fork_targets_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.1 KiB
Ruby
Raw Permalink Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe ForkTargetsFinder do
2020-04-08 14:13:33 +05:30
subject(:finder) { described_class.new(project, user) }
2022-08-27 11:52:29 +05:30
let_it_be(:project) { create(:project, namespace: create(:group)) }
let_it_be(:user) { create(:user) }
let_it_be(:maintained_group) do
2020-04-08 14:13:33 +05:30
create(:group).tap { |g| g.add_maintainer(user) }
end
2020-10-24 23:57:45 +05:30
2022-08-27 11:52:29 +05:30
let_it_be(:owned_group) do
2020-04-08 14:13:33 +05:30
create(:group).tap { |g| g.add_owner(user) }
end
2020-10-24 23:57:45 +05:30
2022-08-27 11:52:29 +05:30
let_it_be(:developer_group) do
2022-03-02 08:16:31 +05:30
create(:group, project_creation_level: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS).tap do |g|
g.add_developer(user)
end
2020-04-08 14:13:33 +05:30
end
2020-10-24 23:57:45 +05:30
2022-08-27 11:52:29 +05:30
let_it_be(:reporter_group) do
2020-04-08 14:13:33 +05:30
create(:group).tap { |g| g.add_reporter(user) }
end
2020-10-24 23:57:45 +05:30
2022-08-27 11:52:29 +05:30
let_it_be(:guest_group) do
2020-04-08 14:13:33 +05:30
create(:group).tap { |g| g.add_guest(user) }
end
2023-06-20 00:43:36 +05:30
let_it_be(:shared_group_to_group_with_owner_access) do
create(:group)
end
2020-04-08 14:13:33 +05:30
before do
project.namespace.add_owner(user)
2023-06-20 00:43:36 +05:30
create(:group_group_link, :maintainer,
shared_with_group: owned_group,
shared_group: shared_group_to_group_with_owner_access
)
2020-04-08 14:13:33 +05:30
end
2022-08-27 11:52:29 +05:30
shared_examples 'returns namespaces and groups' do
2020-04-08 14:13:33 +05:30
it 'returns all user manageable namespaces' do
2023-06-20 00:43:36 +05:30
expect(finder.execute).to match_array([
user.namespace,
maintained_group,
owned_group,
project.namespace,
developer_group,
shared_group_to_group_with_owner_access
])
2020-04-08 14:13:33 +05:30
end
2020-11-24 15:15:51 +05:30
it 'returns only groups when only_groups option is passed' do
2023-06-20 00:43:36 +05:30
expect(finder.execute(only_groups: true)).to match_array([
maintained_group,
owned_group,
project.namespace,
developer_group,
shared_group_to_group_with_owner_access
])
2020-11-24 15:15:51 +05:30
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-04-08 14:13:33 +05:30
end
2022-08-27 11:52:29 +05:30
describe '#execute' do
it_behaves_like 'returns namespaces and groups'
context 'when search is provided' do
it 'filters the targets by the param' do
expect(finder.execute(search: maintained_group.path)).to eq([maintained_group])
end
end
end
2020-04-08 14:13:33 +05:30
end