summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 21:08:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 21:08:13 +0000
commitd3c29eae5c389e36d4751539fad0462053fb2b20 (patch)
treecc3ae497193f9334d0bc6ee4224637102f6e0d4e /spec
parentad4dbe36445360521fc73a57df13bc8f12eeaa92 (diff)
downloadgitlab-ce-d3c29eae5c389e36d4751539fad0462053fb2b20.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/services_controller_spec.rb10
-rw-r--r--spec/features/merge_request/user_manages_subscription_spec.rb2
-rw-r--r--spec/helpers/auth_helper_spec.rb30
-rw-r--r--spec/javascripts/diffs/components/diff_file_spec.js7
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb9
-rw-r--r--spec/services/projects/create_service_spec.rb63
6 files changed, 108 insertions, 13 deletions
diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb
index fb7cca3997b..c669119fa4e 100644
--- a/spec/controllers/projects/services_controller_spec.rb
+++ b/spec/controllers/projects/services_controller_spec.rb
@@ -153,16 +153,6 @@ describe Projects::ServicesController do
expect(flash[:notice]).to eq 'Jira settings saved, but not activated.'
end
end
-
- context 'when activating Jira service from a template' do
- let(:service) do
- create(:jira_service, project: project, template: true)
- end
-
- it 'activate Jira service from template' do
- expect(flash[:notice]).to eq 'Jira activated.'
- end
- end
end
describe 'as JSON' do
diff --git a/spec/features/merge_request/user_manages_subscription_spec.rb b/spec/features/merge_request/user_manages_subscription_spec.rb
index 5c6072c57ff..54d27a06bb1 100644
--- a/spec/features/merge_request/user_manages_subscription_spec.rb
+++ b/spec/features/merge_request/user_manages_subscription_spec.rb
@@ -16,6 +16,8 @@ describe 'User manages subscription', :js do
it 'toggles subscription' do
page.within('.js-issuable-subscribe-button') do
+ wait_for_requests
+
expect(page).to have_css 'button:not(.is-checked)'
find('button:not(.is-checked)').click
diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb
index 9179019cd6a..073ce581741 100644
--- a/spec/helpers/auth_helper_spec.rb
+++ b/spec/helpers/auth_helper_spec.rb
@@ -154,4 +154,34 @@ describe AuthHelper do
expect(helper.unlink_provider_allowed?(provider)).to eq 'policy_unlink_result'
end
end
+
+ describe '#provider_has_icon?' do
+ it 'returns true for defined providers' do
+ expect(helper.provider_has_icon?(described_class::PROVIDERS_WITH_ICONS.sample)).to eq true
+ end
+
+ it 'returns false for undefined providers' do
+ expect(helper.provider_has_icon?('test')).to be_falsey
+ end
+
+ context 'when provider is defined by config' do
+ before do
+ allow(Gitlab::Auth::OAuth::Provider).to receive(:icon_for).with('test').and_return('icon')
+ end
+
+ it 'returns true' do
+ expect(helper.provider_has_icon?('test')).to be_truthy
+ end
+ end
+
+ context 'when provider is not defined by config' do
+ before do
+ allow(Gitlab::Auth::OAuth::Provider).to receive(:icon_for).with('test').and_return(nil)
+ end
+
+ it 'returns true' do
+ expect(helper.provider_has_icon?('test')).to be_falsey
+ end
+ end
+ end
end
diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js
index eab4f4fb17f..e2b64a5418e 100644
--- a/spec/javascripts/diffs/components/diff_file_spec.js
+++ b/spec/javascripts/diffs/components/diff_file_spec.js
@@ -23,6 +23,9 @@ describe('DiffFile', () => {
vm.$destroy();
});
+ const findDiffContent = () => vm.$el.querySelector('.diff-content');
+ const isVisible = el => el.style.display !== 'none';
+
describe('template', () => {
it('should render component with file header, file content components', done => {
const el = vm.$el;
@@ -69,13 +72,13 @@ describe('DiffFile', () => {
describe('collapsed', () => {
it('should not have file content', done => {
- expect(vm.$el.querySelectorAll('.diff-content').length).toEqual(1);
+ expect(isVisible(findDiffContent())).toBe(true);
expect(vm.isCollapsed).toEqual(false);
vm.isCollapsed = true;
vm.file.renderIt = true;
vm.$nextTick(() => {
- expect(vm.$el.querySelectorAll('.diff-content').length).toEqual(0);
+ expect(isVisible(findDiffContent())).toBe(false);
done();
});
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index 1922bb065cf..fd4783a60f2 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -176,6 +176,15 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
it 'returns true' do
expect(service.prometheus_available?).to be(true)
end
+
+ it 'avoids N+1 queries' do
+ service
+ 5.times do |i|
+ other_cluster = create(:cluster_for_group, :with_installed_helm, groups: [group], environment_scope: i)
+ create(:clusters_applications_prometheus, :installing, cluster: other_cluster)
+ end
+ expect { service.prometheus_available? }.not_to exceed_query_limit(1)
+ end
end
context 'cluster belongs to gitlab instance' do
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index a8e7919dc81..c5c16130edc 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -344,7 +344,7 @@ describe Projects::CreateService, '#execute' do
context 'when there is an active service template' do
before do
- create(:service, project: nil, template: true, active: true)
+ create(:prometheus_service, project: nil, template: true, active: true)
end
it 'creates a service from this template' do
@@ -394,6 +394,67 @@ describe Projects::CreateService, '#execute' do
expect(rugged.config['gitlab.fullpath']).to eq project.full_path
end
+ context 'when project has access to shared service' do
+ context 'Prometheus application is shared via group cluster' do
+ let(:cluster) { create(:cluster, :group, groups: [group]) }
+ let(:group) do
+ create(:group).tap do |group|
+ group.add_owner(user)
+ end
+ end
+
+ before do
+ create(:clusters_applications_prometheus, :installed, cluster: cluster)
+ end
+
+ it 'creates PrometheusService record', :aggregate_failures do
+ project = create_project(user, opts.merge!(namespace_id: group.id))
+ service = project.prometheus_service
+
+ expect(service.active).to be true
+ expect(service.manual_configuration?).to be false
+ expect(service.persisted?).to be true
+ end
+ end
+
+ context 'Prometheus application is shared via instance cluster' do
+ let(:cluster) { create(:cluster, :instance) }
+
+ before do
+ create(:clusters_applications_prometheus, :installed, cluster: cluster)
+ end
+
+ it 'creates PrometheusService record', :aggregate_failures do
+ project = create_project(user, opts)
+ service = project.prometheus_service
+
+ expect(service.active).to be true
+ expect(service.manual_configuration?).to be false
+ expect(service.persisted?).to be true
+ end
+
+ it 'cleans invalid record and logs warning', :aggregate_failures do
+ invalid_service_record = build(:prometheus_service, properties: { api_url: nil, manual_configuration: true }.to_json)
+ allow_next_instance_of(Project) do |instance|
+ allow(instance).to receive(:build_prometheus_service).and_return(invalid_service_record)
+ end
+
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(an_instance_of(ActiveRecord::RecordInvalid), include(extra: { project_id: a_kind_of(Integer) }))
+ project = create_project(user, opts)
+
+ expect(project.prometheus_service).to be_nil
+ end
+ end
+
+ context 'shared Prometheus application is not available' do
+ it 'does not persist PrometheusService record', :aggregate_failures do
+ project = create_project(user, opts)
+
+ expect(project.prometheus_service).to be_nil
+ end
+ end
+ end
+
context 'with external authorization enabled' do
before do
enable_external_authorization_service_check