Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/services/groups
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/services/groups')
-rw-r--r--spec/services/groups/autocomplete_service_spec.rb119
-rw-r--r--spec/services/groups/create_service_spec.rb18
-rw-r--r--spec/services/groups/open_issues_count_service_spec.rb11
-rw-r--r--spec/services/groups/transfer_service_spec.rb9
4 files changed, 144 insertions, 13 deletions
diff --git a/spec/services/groups/autocomplete_service_spec.rb b/spec/services/groups/autocomplete_service_spec.rb
new file mode 100644
index 00000000000..00d0ad3b347
--- /dev/null
+++ b/spec/services/groups/autocomplete_service_spec.rb
@@ -0,0 +1,119 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Groups::AutocompleteService do
+ let_it_be(:group, refind: true) { create(:group, :nested, :private, avatar: fixture_file_upload('spec/fixtures/dk.png')) }
+ let_it_be(:sub_group) { create(:group, :private, parent: group) }
+
+ let(:user) { create(:user) }
+
+ subject { described_class.new(group, user) }
+
+ before do
+ group.add_developer(user)
+ end
+
+ def expect_labels_to_equal(labels, expected_labels)
+ extract_title = lambda { |label| label['title'] }
+ expect(labels.map(&extract_title)).to match_array(expected_labels.map(&extract_title))
+ end
+
+ describe '#labels_as_hash' do
+ let!(:label1) { create(:group_label, group: group) }
+ let!(:label2) { create(:group_label, group: group) }
+ let!(:sub_group_label) { create(:group_label, group: sub_group) }
+ let!(:parent_group_label) { create(:group_label, group: group.parent) }
+
+ it 'returns labels from own group and ancestor groups' do
+ results = subject.labels_as_hash(nil)
+
+ expected_labels = [label1, label2, parent_group_label]
+
+ expect_labels_to_equal(results, expected_labels)
+ end
+ end
+
+ describe '#issues' do
+ let(:project) { create(:project, group: group) }
+ let(:sub_group_project) { create(:project, group: sub_group) }
+
+ let!(:project_issue) { create(:issue, project: project) }
+ let!(:sub_group_project_issue) { create(:issue, confidential: true, project: sub_group_project) }
+
+ it 'returns issues in group and subgroups' do
+ issues = subject.issues
+
+ expect(issues.map(&:iid)).to contain_exactly(project_issue.iid, sub_group_project_issue.iid)
+ expect(issues.map(&:title)).to contain_exactly(project_issue.title, sub_group_project_issue.title)
+ end
+
+ it 'returns only confidential issues if confidential_only is true' do
+ issues = subject.issues(confidential_only: true)
+
+ expect(issues.map(&:iid)).to contain_exactly(sub_group_project_issue.iid)
+ expect(issues.map(&:title)).to contain_exactly(sub_group_project_issue.title)
+ end
+ end
+
+ describe '#merge_requests' do
+ let(:project) { create(:project, :repository, group: group) }
+ let(:sub_group_project) { create(:project, :repository, group: sub_group) }
+
+ let!(:project_mr) { create(:merge_request, source_project: project) }
+ let!(:sub_group_project_mr) { create(:merge_request, source_project: sub_group_project) }
+
+ it 'returns merge requests in group and subgroups' do
+ expect(subject.merge_requests.map(&:iid)).to contain_exactly(project_mr.iid, sub_group_project_mr.iid)
+ expect(subject.merge_requests.map(&:title)).to contain_exactly(project_mr.title, sub_group_project_mr.title)
+ end
+ end
+
+ describe '#milestones' do
+ let!(:group_milestone) { create(:milestone, group: group) }
+ let!(:subgroup_milestone) { create(:milestone, group: sub_group) }
+
+ before do
+ sub_group.add_maintainer(user)
+ end
+
+ context 'when group is public' do
+ let(:public_group) { create(:group, :public) }
+ let(:public_subgroup) { create(:group, :public, parent: public_group) }
+
+ before do
+ group_milestone.update!(group: public_group)
+ subgroup_milestone.update!(group: public_subgroup)
+ end
+
+ it 'returns milestones from groups and subgroups' do
+ subject = described_class.new(public_subgroup, user)
+
+ expect(subject.milestones.map(&:iid)).to contain_exactly(group_milestone.iid, subgroup_milestone.iid)
+ expect(subject.milestones.map(&:title)).to contain_exactly(group_milestone.title, subgroup_milestone.title)
+ end
+ end
+
+ it 'returns milestones from group' do
+ expect(subject.milestones.map(&:iid)).to contain_exactly(group_milestone.iid)
+ expect(subject.milestones.map(&:title)).to contain_exactly(group_milestone.title)
+ end
+
+ it 'returns milestones from groups and subgroups' do
+ milestones = described_class.new(sub_group, user).milestones
+
+ expect(milestones.map(&:iid)).to contain_exactly(group_milestone.iid, subgroup_milestone.iid)
+ expect(milestones.map(&:title)).to contain_exactly(group_milestone.title, subgroup_milestone.title)
+ end
+
+ it 'returns only milestones that user can read' do
+ user = create(:user)
+ sub_group.add_guest(user)
+
+ milestones = described_class.new(sub_group, user).milestones
+
+ expect(milestones.map(&:iid)).to contain_exactly(subgroup_milestone.iid)
+ expect(milestones.map(&:title)).to contain_exactly(subgroup_milestone.title)
+ end
+ end
+end
diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb
index f0cd42c1948..dca5497de06 100644
--- a/spec/services/groups/create_service_spec.rb
+++ b/spec/services/groups/create_service_spec.rb
@@ -164,9 +164,9 @@ RSpec.describe Groups::CreateService, '#execute' do
let!(:instance_integration) { create(:prometheus_service, :instance, api_url: 'https://prometheus.instance.com/') }
it 'creates a service from the instance-level integration' do
- expect(created_group.services.count).to eq(1)
- expect(created_group.services.first.api_url).to eq(instance_integration.api_url)
- expect(created_group.services.first.inherit_from_id).to eq(instance_integration.id)
+ expect(created_group.integrations.count).to eq(1)
+ expect(created_group.integrations.first.api_url).to eq(instance_integration.api_url)
+ expect(created_group.integrations.first.inherit_from_id).to eq(instance_integration.id)
end
context 'with an active group-level integration' do
@@ -179,9 +179,9 @@ RSpec.describe Groups::CreateService, '#execute' do
end
it 'creates a service from the group-level integration' do
- expect(created_group.services.count).to eq(1)
- expect(created_group.services.first.api_url).to eq(group_integration.api_url)
- expect(created_group.services.first.inherit_from_id).to eq(group_integration.id)
+ expect(created_group.integrations.count).to eq(1)
+ expect(created_group.integrations.first.api_url).to eq(group_integration.api_url)
+ expect(created_group.integrations.first.inherit_from_id).to eq(group_integration.id)
end
context 'with an active subgroup' do
@@ -194,9 +194,9 @@ RSpec.describe Groups::CreateService, '#execute' do
end
it 'creates a service from the subgroup-level integration' do
- expect(created_group.services.count).to eq(1)
- expect(created_group.services.first.api_url).to eq(subgroup_integration.api_url)
- expect(created_group.services.first.inherit_from_id).to eq(subgroup_integration.id)
+ expect(created_group.integrations.count).to eq(1)
+ expect(created_group.integrations.first.api_url).to eq(subgroup_integration.api_url)
+ expect(created_group.integrations.first.inherit_from_id).to eq(subgroup_integration.id)
end
end
end
diff --git a/spec/services/groups/open_issues_count_service_spec.rb b/spec/services/groups/open_issues_count_service_spec.rb
index 740e9846119..fca09bfdebe 100644
--- a/spec/services/groups/open_issues_count_service_spec.rb
+++ b/spec/services/groups/open_issues_count_service_spec.rb
@@ -57,4 +57,15 @@ RSpec.describe Groups::OpenIssuesCountService, :use_clean_rails_memory_store_cac
it_behaves_like 'a counter caching service with threshold'
end
end
+
+ describe '#clear_all_cache_keys' do
+ it 'calls `Rails.cache.delete` with the correct keys' do
+ expect(Rails.cache).to receive(:delete)
+ .with(['groups', 'open_issues_count_service', 1, group.id, described_class::PUBLIC_COUNT_KEY])
+ expect(Rails.cache).to receive(:delete)
+ .with(['groups', 'open_issues_count_service', 1, group.id, described_class::TOTAL_COUNT_KEY])
+
+ subject.clear_all_cache_keys
+ end
+ end
end
diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb
index 3a1197970f4..2fbd5eeef5f 100644
--- a/spec/services/groups/transfer_service_spec.rb
+++ b/spec/services/groups/transfer_service_spec.rb
@@ -240,6 +240,7 @@ RSpec.describe Groups::TransferService do
end
context 'when the group is allowed to be transferred' do
+ let_it_be(:new_parent_group, reload: true) { create(:group, :public) }
let_it_be(:new_parent_group_integration) { create(:slack_service, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') }
before do
@@ -273,17 +274,16 @@ RSpec.describe Groups::TransferService do
end
context 'with a group integration' do
- let_it_be(:instance_integration) { create(:slack_service, :instance, webhook: 'http://project.slack.com') }
-
- let(:new_created_integration) { Service.find_by(group: group) }
+ let(:new_created_integration) { Integration.find_by(group: group) }
context 'with an inherited integration' do
+ let_it_be(:instance_integration) { create(:slack_service, :instance, webhook: 'http://project.slack.com') }
let_it_be(:group_integration) { create(:slack_service, group: group, project: nil, webhook: 'http://group.slack.com', inherit_from_id: instance_integration.id) }
it 'replaces inherited integrations', :aggregate_failures do
expect(new_created_integration.webhook).to eq(new_parent_group_integration.webhook)
expect(PropagateIntegrationWorker).to have_received(:perform_async).with(new_created_integration.id)
- expect(Service.count).to eq(3)
+ expect(Integration.count).to eq(3)
end
end
@@ -603,6 +603,7 @@ RSpec.describe Groups::TransferService do
create(:group_member, :owner, group: new_parent_group, user: user)
create(:group, :private, parent: group, require_two_factor_authentication: true)
group.update!(require_two_factor_authentication: true)
+ new_parent_group.reload # make sure traversal_ids are reloaded
end
it 'does not update group two factor authentication setting' do