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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 12:09:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-06 12:09:17 +0300
commiteaea945e0355826c58c3dcf887496ea91064f85c (patch)
tree0f20e03304d35e68375e99a606b9b94483e37ee5 /spec
parentcce8cf03d3bebe8b05375e4db0004328f84b28a2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/projects/services/user_activates_asana_spec.rb19
-rw-r--r--spec/features/projects/services/user_activates_assembla_spec.rb17
-rw-r--r--spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb19
-rw-r--r--spec/features/projects/services/user_activates_emails_on_push_spec.rb19
-rw-r--r--spec/features/projects/services/user_activates_flowdock_spec.rb19
-rw-r--r--spec/features/projects/services/user_activates_hipchat_spec.rb32
-rw-r--r--spec/features/projects/services/user_activates_irker_spec.rb19
-rw-r--r--spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb17
-rw-r--r--spec/features/projects/services/user_activates_packagist_spec.rb17
-rw-r--r--spec/features/projects/services/user_activates_pivotaltracker_spec.rb17
-rw-r--r--spec/features/projects/services/user_activates_prometheus_spec.rb14
-rw-r--r--spec/features/projects/services/user_activates_pushover_spec.rb17
-rw-r--r--spec/features/projects/services/user_activates_slack_notifications_spec.rb22
-rw-r--r--spec/features/projects/services/user_views_services_spec.rb12
-rw-r--r--spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js22
-rw-r--r--spec/frontend/fixtures/merge_requests.rb2
-rw-r--r--spec/lib/gitlab/closing_issue_extractor_spec.rb4
-rw-r--r--spec/lib/gitlab/database/batch_count_spec.rb46
-rw-r--r--spec/services/projects/prometheus/metrics/destroy_service_spec.rb28
-rw-r--r--spec/services/projects/prometheus/metrics/update_service_spec.rb44
-rw-r--r--spec/support/shared_contexts/project_service_shared_context.rb32
21 files changed, 260 insertions, 178 deletions
diff --git a/spec/features/projects/services/user_activates_asana_spec.rb b/spec/features/projects/services/user_activates_asana_spec.rb
index b07c77da554..dac60fce6e9 100644
--- a/spec/features/projects/services/user_activates_asana_spec.rb
+++ b/spec/features/projects/services/user_activates_asana_spec.rb
@@ -3,23 +3,14 @@
require 'spec_helper'
describe 'User activates Asana' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
- before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Asana')
- end
-
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Asana')
fill_in('Api key', with: 'verySecret')
fill_in('Restrict to branch', with: 'verySecret')
- click_button('Save')
+
+ click_test_then_save_integration
expect(page).to have_content('Asana activated.')
end
diff --git a/spec/features/projects/services/user_activates_assembla_spec.rb b/spec/features/projects/services/user_activates_assembla_spec.rb
index 56f7beb8f4b..999a95e3e23 100644
--- a/spec/features/projects/services/user_activates_assembla_spec.rb
+++ b/spec/features/projects/services/user_activates_assembla_spec.rb
@@ -3,22 +3,17 @@
require 'spec_helper'
describe 'User activates Assembla' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Assembla')
+ stub_request(:post, /.*atlas.assembla.com.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Assembla')
fill_in('Token', with: 'verySecret')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('Assembla activated.')
end
diff --git a/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb b/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb
index c694eeb1cc2..28ed08f71b6 100644
--- a/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb
+++ b/spec/features/projects/services/user_activates_atlassian_bamboo_ci_spec.rb
@@ -3,31 +3,26 @@
require 'spec_helper'
describe 'User activates Atlassian Bamboo CI' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Atlassian Bamboo CI')
+ stub_request(:get, /.*bamboo.example.com.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Atlassian Bamboo CI')
fill_in('Bamboo url', with: 'http://bamboo.example.com')
fill_in('Build key', with: 'KEY')
fill_in('Username', with: 'user')
fill_in('Password', with: 'verySecret')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('Atlassian Bamboo CI activated.')
# Password field should not be filled in.
click_link('Atlassian Bamboo CI')
- expect(find_field('Enter new password').value).to be_nil
+ expect(find_field('Enter new password').value).to be_blank
end
end
diff --git a/spec/features/projects/services/user_activates_emails_on_push_spec.rb b/spec/features/projects/services/user_activates_emails_on_push_spec.rb
index 2015b658295..42c069eb29e 100644
--- a/spec/features/projects/services/user_activates_emails_on_push_spec.rb
+++ b/spec/features/projects/services/user_activates_emails_on_push_spec.rb
@@ -3,22 +3,13 @@
require 'spec_helper'
describe 'User activates Emails on push' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
- before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Emails on push')
- end
-
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Emails on push')
fill_in('Recipients', with: 'qa@company.name')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('Emails on push activated.')
end
diff --git a/spec/features/projects/services/user_activates_flowdock_spec.rb b/spec/features/projects/services/user_activates_flowdock_spec.rb
index fc8e75daa0d..4762363b3fe 100644
--- a/spec/features/projects/services/user_activates_flowdock_spec.rb
+++ b/spec/features/projects/services/user_activates_flowdock_spec.rb
@@ -3,22 +3,19 @@
require 'spec_helper'
describe 'User activates Flowdock' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation' do
+ let(:project) { create(:project, :repository) }
+ end
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Flowdock')
+ stub_request(:post, /.*api.flowdock.com.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Flowdock')
fill_in('Token', with: 'verySecret')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('Flowdock activated.')
end
diff --git a/spec/features/projects/services/user_activates_hipchat_spec.rb b/spec/features/projects/services/user_activates_hipchat_spec.rb
index d6b69a5bd68..2fb056f3533 100644
--- a/spec/features/projects/services/user_activates_hipchat_spec.rb
+++ b/spec/features/projects/services/user_activates_hipchat_spec.rb
@@ -2,37 +2,37 @@
require 'spec_helper'
-describe 'User activates HipChat' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
-
- before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('HipChat')
- end
+describe 'User activates HipChat', :js do
+ include_context 'project service activation'
context 'with standart settings' do
+ before do
+ stub_request(:post, /.*api.hipchat.com.*/)
+ end
+
it 'activates service' do
- check('Active')
+ visit_project_integration('HipChat')
fill_in('Room', with: 'gitlab')
fill_in('Token', with: 'verySecret')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('HipChat activated.')
end
end
context 'with custom settings' do
+ before do
+ stub_request(:post, /.*chat.example.com.*/)
+ end
+
it 'activates service' do
- check('Active')
+ visit_project_integration('HipChat')
fill_in('Room', with: 'gitlab_custom')
fill_in('Token', with: 'secretCustom')
fill_in('Server', with: 'https://chat.example.com')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('HipChat activated.')
end
diff --git a/spec/features/projects/services/user_activates_irker_spec.rb b/spec/features/projects/services/user_activates_irker_spec.rb
index 898e16ce835..56df403499c 100644
--- a/spec/features/projects/services/user_activates_irker_spec.rb
+++ b/spec/features/projects/services/user_activates_irker_spec.rb
@@ -3,23 +3,14 @@
require 'spec_helper'
describe 'User activates Irker (IRC gateway)' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
- before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Irker (IRC gateway)')
- end
-
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Irker (IRC gateway)')
check('Colorize messages')
fill_in('Recipients', with: 'irc://chat.freenode.net/#commits')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('Irker (IRC gateway) activated.')
end
diff --git a/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb b/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb
index 9842141285a..8c84a81ac89 100644
--- a/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb
+++ b/spec/features/projects/services/user_activates_jetbrains_teamcity_ci_spec.rb
@@ -3,27 +3,22 @@
require 'spec_helper'
describe 'User activates JetBrains TeamCity CI' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('JetBrains TeamCity CI')
+ stub_request(:post, /.*teamcity.example.com.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('JetBrains TeamCity CI')
check('Push')
check('Merge request')
fill_in('Teamcity url', with: 'http://teamcity.example.com')
fill_in('Build type', with: 'GitlabTest_Build')
fill_in('Username', with: 'user')
fill_in('Password', with: 'verySecret')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('JetBrains TeamCity CI activated.')
end
diff --git a/spec/features/projects/services/user_activates_packagist_spec.rb b/spec/features/projects/services/user_activates_packagist_spec.rb
index 85bd15adbe5..274f293ebf3 100644
--- a/spec/features/projects/services/user_activates_packagist_spec.rb
+++ b/spec/features/projects/services/user_activates_packagist_spec.rb
@@ -3,23 +3,18 @@
require 'spec_helper'
describe 'User activates Packagist' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Packagist')
+ stub_request(:post, /.*packagist.org.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Packagist')
fill_in('Username', with: 'theUser')
fill_in('Token', with: 'verySecret')
- click_button('Save')
+
+ click_test_then_save_integration
expect(page).to have_content('Packagist activated.')
end
diff --git a/spec/features/projects/services/user_activates_pivotaltracker_spec.rb b/spec/features/projects/services/user_activates_pivotaltracker_spec.rb
index 67ff99c0295..c81c5081867 100644
--- a/spec/features/projects/services/user_activates_pivotaltracker_spec.rb
+++ b/spec/features/projects/services/user_activates_pivotaltracker_spec.rb
@@ -3,22 +3,17 @@
require 'spec_helper'
describe 'User activates PivotalTracker' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('PivotalTracker')
+ stub_request(:post, /.*www.pivotaltracker.com.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('PivotalTracker')
fill_in('Token', with: 'verySecret')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('PivotalTracker activated.')
end
diff --git a/spec/features/projects/services/user_activates_prometheus_spec.rb b/spec/features/projects/services/user_activates_prometheus_spec.rb
index ab372d532aa..76dc7d1bbc8 100644
--- a/spec/features/projects/services/user_activates_prometheus_spec.rb
+++ b/spec/features/projects/services/user_activates_prometheus_spec.rb
@@ -3,21 +3,17 @@
require 'spec_helper'
describe 'User activates Prometheus' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Prometheus')
+ stub_request(:get, /.*prometheus.example.com.*/)
end
- it 'does not activate service and informs about deprecation' do
+ it 'does not activate service and informs about deprecation', :js do
+ visit_project_integration('Prometheus')
check('Active')
fill_in('API URL', with: 'http://prometheus.example.com')
+
click_button('Save changes')
expect(page).not_to have_content('Prometheus activated.')
diff --git a/spec/features/projects/services/user_activates_pushover_spec.rb b/spec/features/projects/services/user_activates_pushover_spec.rb
index 34e1cf33f36..62e03e68aee 100644
--- a/spec/features/projects/services/user_activates_pushover_spec.rb
+++ b/spec/features/projects/services/user_activates_pushover_spec.rb
@@ -3,26 +3,21 @@
require 'spec_helper'
describe 'User activates Pushover' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
+ include_context 'project service activation'
before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
-
- click_link('Pushover')
+ stub_request(:post, /.*api.pushover.net.*/)
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
+ visit_project_integration('Pushover')
fill_in('Api key', with: 'verySecret')
fill_in('User key', with: 'verySecret')
fill_in('Device', with: 'myDevice')
select('High Priority', from: 'Priority')
select('Bike', from: 'Sound')
- click_button('Save')
+
+ click_test_integration
expect(page).to have_content('Pushover activated.')
end
diff --git a/spec/features/projects/services/user_activates_slack_notifications_spec.rb b/spec/features/projects/services/user_activates_slack_notifications_spec.rb
index f23b1d3102a..12f15699e26 100644
--- a/spec/features/projects/services/user_activates_slack_notifications_spec.rb
+++ b/spec/features/projects/services/user_activates_slack_notifications_spec.rb
@@ -3,32 +3,26 @@
require 'spec_helper'
describe 'User activates Slack notifications' do
- let(:user) { create(:user) }
- let(:service) { SlackService.new }
- let(:project) { create(:project, slack_service: service) }
-
- before do
- project.add_maintainer(user)
- sign_in(user)
- end
+ include_context 'project service activation'
context 'when service is not configured yet' do
before do
- visit(project_settings_integrations_path(project))
-
- click_link('Slack notifications')
+ visit_project_integration('Slack notifications')
end
- it 'activates service' do
- check('Active')
+ it 'activates service', :js do
fill_in('Webhook', with: 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685')
- click_button('Save')
+
+ click_test_then_save_integration
expect(page).to have_content('Slack notifications activated.')
end
end
context 'when service is already configured' do
+ let(:service) { SlackService.new }
+ let(:project) { create(:project, slack_service: service) }
+
before do
service.fields
service.update(
diff --git a/spec/features/projects/services/user_views_services_spec.rb b/spec/features/projects/services/user_views_services_spec.rb
index cf403a131b0..6df0123c30a 100644
--- a/spec/features/projects/services/user_views_services_spec.rb
+++ b/spec/features/projects/services/user_views_services_spec.rb
@@ -3,17 +3,11 @@
require 'spec_helper'
describe 'User views services' do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
-
- before do
- project.add_maintainer(user)
- sign_in(user)
-
- visit(project_settings_integrations_path(project))
- end
+ include_context 'project service activation'
it 'shows the list of available services' do
+ visit_project_integrations
+
expect(page).to have_content('Integrations')
expect(page).to have_content('Campfire')
expect(page).to have_content('HipChat')
diff --git a/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js b/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js
index 68f4c5c9e02..fb0964a3f32 100644
--- a/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js
+++ b/spec/frontend/blob/suggest_gitlab_ci_yml/components/popover_spec.js
@@ -1,7 +1,8 @@
import { shallowMount } from '@vue/test-utils';
import Popover from '~/blob/suggest_gitlab_ci_yml/components/popover.vue';
-import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
+import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
import * as utils from '~/lib/utils/common_utils';
+import { GlDeprecatedButton } from '@gitlab/ui';
jest.mock('~/lib/utils/common_utils', () => ({
...jest.requireActual('~/lib/utils/common_utils'),
@@ -27,6 +28,9 @@ describe('Suggest gitlab-ci.yml Popover', () => {
dismissKey,
humanAccess,
},
+ stubs: {
+ 'gl-popover': '<div><slot name="title"></slot><slot></slot></div>',
+ },
});
}
@@ -88,6 +92,22 @@ describe('Suggest gitlab-ci.yml Popover', () => {
property: expectedProperty,
});
});
+
+ it('sends a tracking event when the popover is dismissed', () => {
+ const expectedLabel = commitTrackLabel;
+ const expectedAction = 'click_button';
+ const expectedProperty = 'owner';
+ const expectedValue = '10';
+ const dismissButton = wrapper.find(GlDeprecatedButton);
+
+ triggerEvent(dismissButton.element);
+
+ expect(trackingSpy).toHaveBeenCalledWith('_category_', expectedAction, {
+ label: expectedLabel,
+ property: expectedProperty,
+ value: expectedValue,
+ });
+ });
});
describe('when the popover is mounted with the trackLabel of the Confirm button popover at the bottom of the page', () => {
diff --git a/spec/frontend/fixtures/merge_requests.rb b/spec/frontend/fixtures/merge_requests.rb
index be11423ec41..a347ef683e7 100644
--- a/spec/frontend/fixtures/merge_requests.rb
+++ b/spec/frontend/fixtures/merge_requests.rb
@@ -94,7 +94,7 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
end
it 'merge_requests/discussions.json' do
- create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
+ create(:discussion_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
render_discussions_json(merge_request)
end
diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb
index 510876a5945..4e1bf2840dc 100644
--- a/spec/lib/gitlab/closing_issue_extractor_spec.rb
+++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb
@@ -103,7 +103,7 @@ describe Gitlab::ClosingIssueExtractor do
end
it do
- message = "Awesome commit (Fixes: #{reference})"
+ message = "Awesome commit (fixes: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
@@ -396,7 +396,7 @@ describe Gitlab::ClosingIssueExtractor do
end
it 'allows mixed comma-separated and non-comma-separated issue numbers in single line message' do
- message = "Closes #{reference}, #{reference2} and #{reference3}"
+ message = "Closes #{reference}, #{reference2} #{reference3}"
expect(subject.closed_by_message(message))
.to match_array([issue, other_issue, third_issue])
diff --git a/spec/lib/gitlab/database/batch_count_spec.rb b/spec/lib/gitlab/database/batch_count_spec.rb
index b126d8579fc..ec161cd6dcb 100644
--- a/spec/lib/gitlab/database/batch_count_spec.rb
+++ b/spec/lib/gitlab/database/batch_count_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
describe Gitlab::Database::BatchCount do
+ let_it_be(:fallback) { ::Gitlab::Database::BatchCounter::FALLBACK }
+ let_it_be(:small_batch_size) { ::Gitlab::Database::BatchCounter::MIN_REQUIRED_BATCH_SIZE - 1 }
let(:model) { Issue }
let(:column) { :author_id }
@@ -37,9 +39,8 @@ describe Gitlab::Database::BatchCount do
expect(described_class.batch_count(model, batch_size: 50_000)).to eq(5)
end
- it 'will not count table with batch_size 1K' do
- fallback = ::Gitlab::Database::BatchCounter::FALLBACK
- expect(described_class.batch_count(model, batch_size: fallback / 2)).to eq(fallback)
+ it 'will not count table with a batch size less than allowed' do
+ expect(described_class.batch_count(model, batch_size: small_batch_size)).to eq(fallback)
end
it 'counts with a small edge case batch_sizes than result' do
@@ -57,6 +58,25 @@ describe Gitlab::Database::BatchCount do
end.to raise_error 'BatchCount can not be run inside a transaction'
end
end
+
+ it 'counts with a start and finish' do
+ expect(described_class.batch_count(model, start: model.minimum(:id), finish: model.maximum(:id))).to eq(5)
+ end
+
+ context 'disallowed configurations' do
+ it 'returns fallback if start is bigger than finish' do
+ expect(described_class.batch_count(model, start: 1, finish: 0)).to eq(fallback)
+ end
+
+ it 'returns fallback if loops more than allowed' do
+ large_finish = Gitlab::Database::BatchCounter::MAX_ALLOWED_LOOPS * Gitlab::Database::BatchCounter::DEFAULT_BATCH_SIZE + 1
+ expect(described_class.batch_count(model, start: 1, finish: large_finish)).to eq(fallback)
+ end
+
+ it 'returns fallback if batch size is less than min required' do
+ expect(described_class.batch_count(model, batch_size: small_batch_size)).to eq(fallback)
+ end
+ end
end
describe '#batch_distinct_count' do
@@ -80,9 +100,8 @@ describe Gitlab::Database::BatchCount do
expect(described_class.batch_distinct_count(model, column, batch_size: 50_000)).to eq(2)
end
- it 'will not count table with batch_size 1K' do
- fallback = ::Gitlab::Database::BatchCounter::FALLBACK
- expect(described_class.batch_distinct_count(model, column, batch_size: fallback / 2)).to eq(fallback)
+ it 'will not count table with a batch size less than allowed' do
+ expect(described_class.batch_distinct_count(model, column, batch_size: small_batch_size)).to eq(fallback)
end
it 'counts with a small edge case batch_sizes than result' do
@@ -98,5 +117,20 @@ describe Gitlab::Database::BatchCount do
it 'counts with User min and max as start and finish' do
expect(described_class.batch_distinct_count(model, column, start: User.minimum(:id), finish: User.maximum(:id))).to eq(2)
end
+
+ context 'disallowed configurations' do
+ it 'returns fallback if start is bigger than finish' do
+ expect(described_class.batch_distinct_count(model, column, start: 1, finish: 0)).to eq(fallback)
+ end
+
+ it 'returns fallback if loops more than allowed' do
+ large_finish = Gitlab::Database::BatchCounter::MAX_ALLOWED_LOOPS * Gitlab::Database::BatchCounter::DEFAULT_DISTINCT_BATCH_SIZE + 1
+ expect(described_class.batch_distinct_count(model, column, start: 1, finish: large_finish)).to eq(fallback)
+ end
+
+ it 'returns fallback if batch size is less than min required' do
+ expect(described_class.batch_distinct_count(model, column, batch_size: small_batch_size)).to eq(fallback)
+ end
+ end
end
end
diff --git a/spec/services/projects/prometheus/metrics/destroy_service_spec.rb b/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
new file mode 100644
index 00000000000..81fce82cf46
--- /dev/null
+++ b/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::Prometheus::Metrics::DestroyService do
+ let(:metric) { create(:prometheus_metric) }
+
+ subject { described_class.new(metric) }
+
+ it 'destroys metric' do
+ subject.execute
+
+ expect(PrometheusMetric.find_by(id: metric.id)).to be_nil
+ end
+
+ context 'when metric has a prometheus alert associated' do
+ it 'schedules a prometheus alert update' do
+ create(:prometheus_alert, project: metric.project, prometheus_metric: metric)
+
+ schedule_update_service = spy
+ allow(::Clusters::Applications::ScheduleUpdateService).to receive(:new).and_return(schedule_update_service)
+
+ subject.execute
+
+ expect(schedule_update_service).to have_received(:execute)
+ end
+ end
+end
diff --git a/spec/services/projects/prometheus/metrics/update_service_spec.rb b/spec/services/projects/prometheus/metrics/update_service_spec.rb
new file mode 100644
index 00000000000..a53c6ae37cd
--- /dev/null
+++ b/spec/services/projects/prometheus/metrics/update_service_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::Prometheus::Metrics::UpdateService do
+ let(:metric) { create(:prometheus_metric) }
+
+ it 'updates the prometheus metric' do
+ expect do
+ described_class.new(metric, { title: "bar" }).execute
+ end.to change { metric.reload.title }.to("bar")
+ end
+
+ context 'when metric has a prometheus alert associated' do
+ let(:schedule_update_service) { spy }
+
+ before do
+ create(:prometheus_alert, project: metric.project, prometheus_metric: metric)
+ allow(::Clusters::Applications::ScheduleUpdateService).to receive(:new).and_return(schedule_update_service)
+ end
+
+ context 'when updating title' do
+ it 'schedules a prometheus alert update' do
+ described_class.new(metric, { title: "bar" }).execute
+
+ expect(schedule_update_service).to have_received(:execute)
+ end
+ end
+
+ context 'when updating query' do
+ it 'schedules a prometheus alert update' do
+ described_class.new(metric, { query: "sum(bar)" }).execute
+
+ expect(schedule_update_service).to have_received(:execute)
+ end
+ end
+
+ it 'does not schedule a prometheus alert update without title nor query being changed' do
+ described_class.new(metric, { y_label: "bar" }).execute
+
+ expect(schedule_update_service).not_to have_received(:execute)
+ end
+ end
+end
diff --git a/spec/support/shared_contexts/project_service_shared_context.rb b/spec/support/shared_contexts/project_service_shared_context.rb
new file mode 100644
index 00000000000..89b196e7039
--- /dev/null
+++ b/spec/support/shared_contexts/project_service_shared_context.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+shared_context 'project service activation' do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ before do
+ project.add_maintainer(user)
+ sign_in(user)
+ end
+
+ def visit_project_integrations
+ visit project_settings_integrations_path(project)
+ end
+
+ def visit_project_integration(name)
+ visit_project_integrations
+ click_link(name)
+ end
+
+ def click_test_integration
+ click_button('Test settings and save changes')
+ end
+
+ def click_test_then_save_integration
+ click_test_integration
+
+ expect(page).to have_content('Test failed.')
+
+ click_link('Save anyway')
+ end
+end