diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-28 09:09:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-28 09:09:56 +0300 |
commit | 1d42c38d9b4d4ca651db435c8eb0c47bd24a25e2 (patch) | |
tree | add5ce3542470c7d3626c5669898ca3546f29285 /spec | |
parent | 3f5f07675c4205c28791486d66bcbe80b7e0eca4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/service_spec.rb | 24 | ||||
-rw-r--r-- | spec/services/admin/propagate_service_template_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/groups/create_service_spec.rb | 47 | ||||
-rw-r--r-- | spec/services/projects/create_service_spec.rb | 2 |
4 files changed, 69 insertions, 8 deletions
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index a166e913ea4..42a12a98d63 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -320,7 +320,7 @@ RSpec.describe Service do end it 'sets service to inactive' do - service = described_class.build_from_integration(project.id, integration) + service = described_class.build_from_integration(integration, project_id: project.id) expect(service).to be_valid expect(service.active).to be false @@ -331,7 +331,7 @@ RSpec.describe Service do let(:integration) { create(:jira_service, :instance) } it 'sets inherit_from_id from integration' do - service = described_class.build_from_integration(project.id, integration) + service = described_class.build_from_integration(integration, project_id: project.id) expect(service.inherit_from_id).to eq(integration.id) end @@ -341,7 +341,7 @@ RSpec.describe Service do let(:integration) { create(:jira_service, group: group, project: nil) } it 'sets inherit_from_id from integration' do - service = described_class.build_from_integration(project.id, integration) + service = described_class.build_from_integration(integration, project_id: project.id) expect(service.inherit_from_id).to eq(integration.id) end @@ -360,8 +360,8 @@ RSpec.describe Service do end shared_examples 'service creation from an integration' do - it 'creates a correct service' do - service = described_class.build_from_integration(project.id, integration) + it 'creates a correct service for a project integration' do + service = described_class.build_from_integration(integration, project_id: project.id) expect(service).to be_active expect(service.url).to eq(url) @@ -373,6 +373,20 @@ RSpec.describe Service do expect(service.project).to eq(project) expect(service.group).to eq(nil) end + + it 'creates a correct service for a group integration' do + service = described_class.build_from_integration(integration, group_id: group.id) + + expect(service).to be_active + expect(service.url).to eq(url) + expect(service.api_url).to eq(api_url) + expect(service.username).to eq(username) + expect(service.password).to eq(password) + expect(service.template).to eq(false) + expect(service.instance).to eq(false) + expect(service.project).to eq(nil) + expect(service.group).to eq(group) + end end # this will be removed as part of https://gitlab.com/gitlab-org/gitlab/issues/29404 diff --git a/spec/services/admin/propagate_service_template_spec.rb b/spec/services/admin/propagate_service_template_spec.rb index 15654653095..814a9db55de 100644 --- a/spec/services/admin/propagate_service_template_spec.rb +++ b/spec/services/admin/propagate_service_template_spec.rb @@ -61,8 +61,8 @@ RSpec.describe Admin::PropagateServiceTemplate do } ) - Service.build_from_integration(project.id, service_template).save! - Service.build_from_integration(project.id, other_service).save! + Service.build_from_integration(service_template, project_id: project.id).save! + Service.build_from_integration(other_service, project_id: project.id).save! expect { described_class.propagate(service_template) } .not_to change { Service.count } diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb index fc877f45a39..6995caa9e6e 100644 --- a/spec/services/groups/create_service_spec.rb +++ b/spec/services/groups/create_service_spec.rb @@ -138,4 +138,51 @@ RSpec.describe Groups::CreateService, '#execute' do expect(group.namespace_settings).to be_persisted end end + + describe 'create service for the group' do + let(:service) { described_class.new(user, group_params) } + let(:created_group) { service.execute } + + context 'with an active instance-level integration' 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) + end + + context 'with an active group-level integration' do + let(:service) { described_class.new(user, group_params.merge(parent_id: group.id)) } + let!(:group_integration) { create(:prometheus_service, group: group, project: nil, api_url: 'https://prometheus.group.com/') } + let(:group) do + create(:group).tap do |group| + group.add_owner(user) + end + 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) + end + + context 'with an active subgroup' do + let(:service) { described_class.new(user, group_params.merge(parent_id: subgroup.id)) } + let!(:subgroup_integration) { create(:prometheus_service, group: subgroup, project: nil, api_url: 'https://prometheus.subgroup.com/') } + let(:subgroup) do + create(:group, parent: group).tap do |subgroup| + subgroup.add_owner(user) + end + 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) + end + end + end + end + end end diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb index d027083d846..fde90dc8c80 100644 --- a/spec/services/projects/create_service_spec.rb +++ b/spec/services/projects/create_service_spec.rb @@ -541,7 +541,7 @@ RSpec.describe Projects::CreateService, '#execute' do } end - it 'creates a service from the group-level integration' do + it 'creates a service from the subgroup-level integration' do expect(project.services.count).to eq(1) expect(project.services.first.api_url).to eq(subgroup_integration.api_url) expect(project.services.first.inherit_from_id).to eq(subgroup_integration.id) |