diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-20 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-20 12:08:42 +0300 |
commit | 65a0673d76bb86d6acca6dc3ab42dc91a04f56c2 (patch) | |
tree | eb5691156a16c32f8d2e5f2bdec7b5aa582a2077 /spec/services | |
parent | 83cddbd52370f2845a9083d7e82cd5539703611b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/groups/update_shared_runners_service_spec.rb | 21 | ||||
-rw-r--r-- | spec/services/projects/participants_service_spec.rb | 146 | ||||
-rw-r--r-- | spec/services/projects/transfer_service_spec.rb | 12 |
3 files changed, 81 insertions, 98 deletions
diff --git a/spec/services/groups/update_shared_runners_service_spec.rb b/spec/services/groups/update_shared_runners_service_spec.rb index 00eabb5c875..dc0d50bdab4 100644 --- a/spec/services/groups/update_shared_runners_service_spec.rb +++ b/spec/services/groups/update_shared_runners_service_spec.rb @@ -67,6 +67,21 @@ RSpec.describe Groups::UpdateSharedRunnersService, feature_category: :groups_and .and change { sub_group.shared_runners_enabled }.from(false).to(true) .and change { project.shared_runners_enabled }.from(false).to(true) end + + context 'when already allowing descendants to override' do + let(:group) { create(:group, :shared_runners_disabled_and_overridable) } + + it 'enables shared Runners for itself and descendants' do + expect do + expect(subject[:status]).to eq(:success) + + reload_models(group, sub_group, project) + end.to change { group.shared_runners_enabled }.from(false).to(true) + .and change { group.allow_descendants_override_disabled_shared_runners }.from(true).to(false) + .and change { sub_group.shared_runners_enabled }.from(false).to(true) + .and change { project.shared_runners_enabled }.from(false).to(true) + end + end end context 'when group has pending builds' do @@ -101,7 +116,7 @@ RSpec.describe Groups::UpdateSharedRunnersService, feature_category: :groups_and context 'disable shared Runners' do let!(:group) { create(:group) } - let!(:sub_group) { create(:group, :shared_runners_disabled, :allow_descendants_override_disabled_shared_runners, parent: group) } + let!(:sub_group) { create(:group, :shared_runners_disabled_and_overridable, parent: group) } let!(:sub_group2) { create(:group, parent: group) } let!(:project) { create(:project, group: group, shared_runners_enabled: true) } let!(:project2) { create(:project, group: sub_group2, shared_runners_enabled: true) } @@ -124,7 +139,7 @@ RSpec.describe Groups::UpdateSharedRunnersService, feature_category: :groups_and end context 'with override on self' do - let(:group) { create(:group, :shared_runners_disabled, :allow_descendants_override_disabled_shared_runners) } + let(:group) { create(:group, :shared_runners_disabled_and_overridable) } it 'disables it' do expect do @@ -172,7 +187,7 @@ RSpec.describe Groups::UpdateSharedRunnersService, feature_category: :groups_and end context 'when ancestor disables shared Runners but allows to override' do - let!(:parent) { create(:group, :shared_runners_disabled, :allow_descendants_override_disabled_shared_runners) } + let!(:parent) { create(:group, :shared_runners_disabled_and_overridable) } let!(:group) { create(:group, :shared_runners_disabled, parent: parent) } let!(:project) { create(:project, shared_runners_enabled: false, group: group) } diff --git a/spec/services/projects/participants_service_spec.rb b/spec/services/projects/participants_service_spec.rb index 04c43dff2dc..b01e64439ec 100644 --- a/spec/services/projects/participants_service_spec.rb +++ b/spec/services/projects/participants_service_spec.rb @@ -120,120 +120,88 @@ RSpec.describe Projects::ParticipantsService, feature_category: :groups_and_proj describe '#project_members' do subject(:usernames) { service.project_members.map { |member| member[:username] } } - shared_examples 'return project members' do - context 'when there is a project in group namespace' do - let_it_be(:public_group) { create(:group, :public) } - let_it_be(:public_project) { create(:project, :public, namespace: public_group) } + context 'when there is a project in group namespace' do + let_it_be(:public_group) { create(:group, :public) } + let_it_be(:public_project, reload: true) { create(:project, :public, namespace: public_group) } - let_it_be(:public_group_owner) { create(:user) } + let_it_be(:public_group_owner) { create(:user) } - let(:service) { described_class.new(public_project, create(:user)) } - - before do - public_group.add_owner(public_group_owner) - end + let(:service) { described_class.new(public_project, create(:user)) } - it 'returns members of a group' do - expect(usernames).to include(public_group_owner.username) - end + before do + public_group.add_owner(public_group_owner) end - context 'when there is a private group and a public project' do - let_it_be(:public_group) { create(:group, :public) } - let_it_be(:private_group) { create(:group, :private, :nested) } - let_it_be(:public_project) { create(:project, :public, namespace: public_group) } - - let_it_be(:project_issue) { create(:issue, project: public_project) } - - let_it_be(:public_group_owner) { create(:user) } - let_it_be(:private_group_member) { create(:user) } - let_it_be(:public_project_maintainer) { create(:user) } - let_it_be(:private_group_owner) { create(:user) } - - let_it_be(:group_ancestor_owner) { create(:user) } - - before_all do - public_group.add_owner public_group_owner - private_group.add_developer private_group_member - public_project.add_maintainer public_project_maintainer - - private_group.add_owner private_group_owner - private_group.parent.add_owner group_ancestor_owner - end + it 'returns members of a group' do + expect(usernames).to include(public_group_owner.username) + end + end - context 'when the private group is invited to the public project' do - before_all do - create(:project_group_link, group: private_group, project: public_project) - end + context 'when there is a private group and a public project' do + let_it_be(:public_group) { create(:group, :public) } + let_it_be(:private_group) { create(:group, :private, :nested) } + let_it_be(:public_project, reload: true) { create(:project, :public, namespace: public_group) } - context 'when a user who is outside the public project and the private group is signed in' do - let(:service) { described_class.new(public_project, create(:user)) } + let_it_be(:project_issue) { create(:issue, project: public_project) } - it 'does not return the private group' do - expect(usernames).not_to include(private_group.name) - end + let_it_be(:public_group_owner) { create(:user) } + let_it_be(:private_group_member) { create(:user) } + let_it_be(:public_project_maintainer) { create(:user) } + let_it_be(:private_group_owner) { create(:user) } - it 'does not return private group members' do - expect(usernames).not_to include(private_group_member.username) - end + let_it_be(:group_ancestor_owner) { create(:user) } - it 'returns the project maintainer' do - expect(usernames).to include(public_project_maintainer.username) - end + before_all do + public_group.add_owner public_group_owner + private_group.add_developer private_group_member + public_project.add_maintainer public_project_maintainer - it 'returns project members from an invited public group' do - invited_public_group = create(:group, :public) - invited_public_group.add_owner create(:user) + private_group.add_owner private_group_owner + private_group.parent.add_owner group_ancestor_owner + end - create(:project_group_link, group: invited_public_group, project: public_project) + context 'when the private group is invited to the public project' do + before_all do + create(:project_group_link, group: private_group, project: public_project) + end - expect(usernames).to include(invited_public_group.users.first.username) - end + let(:service) { described_class.new(public_project, create(:user)) } - it 'does not return ancestors of the private group' do - expect(usernames).not_to include(group_ancestor_owner.username) - end - end + it 'does not return the private group' do + expect(usernames).not_to include(private_group.name) + end - context 'when public project maintainer is signed in' do - let(:service) { described_class.new(public_project, public_project_maintainer) } + it 'returns private group members' do + expect(usernames).to include(private_group_member.username) + end - it 'returns private group members' do - expect(usernames).to include(private_group_member.username) - end + it 'returns the project maintainer' do + expect(usernames).to include(public_project_maintainer.username) + end - it 'returns members of the ancestral groups of the private group' do - expect(usernames).to include(group_ancestor_owner.username) - end - end + it 'returns project members from an invited public group' do + invited_public_group = create(:group, :public) + invited_public_group.add_owner create(:user) - context 'when private group owner is signed in' do - let(:service) { described_class.new(public_project, private_group_owner) } + create(:project_group_link, group: invited_public_group, project: public_project) - it 'returns private group members' do - expect(usernames).to include(private_group_member.username) - end + expect(usernames).to include(invited_public_group.users.first.username) + end - it 'returns ancestors of the the private group' do - expect(usernames).to include(group_ancestor_owner.username) - end - end + it 'returns members of the ancestral groups of the private group' do + expect(usernames).to include(group_ancestor_owner.username) + end - context 'when the namespace owner of the public project is signed in' do - let(:service) { described_class.new(public_project, public_group_owner) } + it 'returns invited group members of the private group' do + invited_group = create(:group, :public) + create(:group_group_link, shared_group: private_group, shared_with_group: invited_group) - it 'returns private group members' do - expect(usernames).to include(private_group_member.username) - end + other_user = create(:user) + invited_group.add_guest(other_user) - it 'does not return members of the ancestral groups of the private group' do - expect(usernames).to include(group_ancestor_owner.username) - end - end + expect(usernames).to include(other_user.username) end end end - - it_behaves_like 'return project members' end end diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 46fe7d7bbbe..1ddf6168c07 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -570,12 +570,12 @@ RSpec.describe Projects::TransferService, feature_category: :groups_and_projects using RSpec::Parameterized::TableSyntax where(:project_shared_runners_enabled, :shared_runners_setting, :expected_shared_runners_enabled) do - true | :disabled_and_unoverridable | false - false | :disabled_and_unoverridable | false - true | :disabled_and_overridable | true - false | :disabled_and_overridable | false - true | :shared_runners_enabled | true - false | :shared_runners_enabled | false + true | :shared_runners_disabled_and_unoverridable | false + false | :shared_runners_disabled_and_unoverridable | false + true | :shared_runners_disabled_and_overridable | true + false | :shared_runners_disabled_and_overridable | false + true | :shared_runners_enabled | true + false | :shared_runners_enabled | false end with_them do |