gitlab-org--gitlab-foss/spec/services/admin/propagate_service_template_spec.rb

143 lines
4.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-05-04 06:13:33 -04:00
require 'spec_helper'
RSpec.describe Admin::PropagateServiceTemplate do
2017-05-05 12:01:33 -04:00
describe '.propagate' do
let!(:service_template) do
PushoverService.create!(
template: true,
2017-05-04 06:13:33 -04:00
active: true,
push_events: false,
2017-05-04 06:13:33 -04:00
properties: {
device: 'MyDevice',
sound: 'mic',
priority: 4,
user_key: 'asdf',
api_key: '123456789'
}
)
2017-05-04 06:13:33 -04:00
end
let!(:project) { create(:project) }
let(:excluded_attributes) { %w[id project_id template created_at updated_at default] }
2017-05-04 06:13:33 -04:00
it 'creates services for projects' do
2017-05-05 12:57:52 -04:00
expect(project.pushover_service).to be_nil
described_class.propagate(service_template)
2017-05-05 12:57:52 -04:00
expect(project.reload.pushover_service).to be_present
2017-05-04 06:13:33 -04:00
end
2017-05-04 10:41:07 -04:00
it 'creates services for a project that has another service' do
BambooService.create!(
2017-05-04 10:41:07 -04:00
active: true,
2017-05-05 12:01:33 -04:00
project: project,
2017-05-04 10:41:07 -04:00
properties: {
bamboo_url: 'http://gitlab.com',
username: 'mic',
password: 'password',
2017-05-04 10:41:07 -04:00
build_key: 'build'
}
)
2017-05-05 12:57:52 -04:00
expect(project.pushover_service).to be_nil
described_class.propagate(service_template)
2017-05-05 12:57:52 -04:00
expect(project.reload.pushover_service).to be_present
2017-05-04 10:41:07 -04:00
end
2017-05-04 06:13:33 -04:00
it 'does not create the service if it exists already' do
other_service = BambooService.create!(
template: true,
2017-05-04 10:41:07 -04:00
active: true,
properties: {
bamboo_url: 'http://gitlab.com',
username: 'mic',
password: 'password',
2017-05-04 10:41:07 -04:00
build_key: 'build'
}
)
Service.build_from_integration(service_template, project_id: project.id).save!
Service.build_from_integration(other_service, project_id: project.id).save!
2017-05-04 06:13:33 -04:00
expect { described_class.propagate(service_template) }
2017-06-21 09:48:12 -04:00
.not_to change { Service.count }
2017-05-04 06:13:33 -04:00
end
it 'creates the service containing the template attributes' do
described_class.propagate(service_template)
2017-05-04 06:13:33 -04:00
expect(project.pushover_service.properties).to eq(service_template.properties)
expect(project.pushover_service.attributes.except(*excluded_attributes))
.to eq(service_template.attributes.except(*excluded_attributes))
end
context 'service with data fields' do
include JiraServiceHelper
let(:service_template) do
stub_jira_service_test
JiraService.create!(
template: true,
active: true,
push_events: false,
url: 'http://jira.instance.com',
username: 'user',
password: 'secret'
)
end
it 'creates the service containing the template attributes' do
described_class.propagate(service_template)
expect(project.jira_service.attributes.except(*excluded_attributes))
.to eq(service_template.attributes.except(*excluded_attributes))
excluded_attributes = %w[id service_id created_at updated_at]
expect(project.jira_service.data_fields.attributes.except(*excluded_attributes))
.to eq(service_template.data_fields.attributes.except(*excluded_attributes))
end
2017-05-04 06:13:33 -04:00
end
describe 'bulk update', :use_sql_query_cache do
let(:project_total) { 5 }
before do
stub_const('Admin::PropagateServiceTemplate::BATCH_SIZE', 3)
project_total.times { create(:project) }
described_class.propagate(service_template)
end
it 'creates services for all projects' do
expect(Service.all.reload.count).to eq(project_total + 2)
end
end
2017-05-05 10:16:02 -04:00
describe 'external tracker' do
it 'updates the project external tracker' do
service_template.update!(category: 'issue_tracker')
2017-05-05 10:16:02 -04:00
expect { described_class.propagate(service_template) }
2017-06-21 09:48:12 -04:00
.to change { project.reload.has_external_issue_tracker }.to(true)
2017-05-05 10:16:02 -04:00
end
end
describe 'external wiki' do
it 'updates the project external tracker' do
service_template.update!(type: 'ExternalWikiService')
2017-05-05 10:16:02 -04:00
expect { described_class.propagate(service_template) }
2017-06-21 09:48:12 -04:00
.to change { project.reload.has_external_wiki }.to(true)
2017-05-05 10:16:02 -04:00
end
end
2017-05-04 06:13:33 -04:00
end
end