2017-05-04 06:13:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Projects::PropagateServiceTemplate do
|
2017-05-05 12:01:33 -04:00
|
|
|
describe '.propagate' do
|
2017-05-04 06:13:33 -04:00
|
|
|
let!(:service_template) do
|
|
|
|
PushoverService.create(
|
|
|
|
template: true,
|
|
|
|
active: true,
|
|
|
|
properties: {
|
|
|
|
device: 'MyDevice',
|
|
|
|
sound: 'mic',
|
|
|
|
priority: 4,
|
|
|
|
user_key: 'asdf',
|
|
|
|
api_key: '123456789'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project) }
|
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)
|
|
|
|
|
|
|
|
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
|
2017-05-05 12:01:33 -04:00
|
|
|
BambooService.create(
|
2017-05-04 10:41:07 -04:00
|
|
|
template: true,
|
|
|
|
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",
|
|
|
|
build_key: 'build'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-05-05 12:57:52 -04:00
|
|
|
expect(project.pushover_service).to be_nil
|
|
|
|
|
|
|
|
described_class.propagate(service_template)
|
|
|
|
|
|
|
|
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
|
2017-05-04 10:41:07 -04:00
|
|
|
other_service = BambooService.create(
|
|
|
|
template: true,
|
|
|
|
active: true,
|
|
|
|
properties: {
|
|
|
|
bamboo_url: 'http://gitlab.com',
|
|
|
|
username: 'mic',
|
|
|
|
password: "password",
|
|
|
|
build_key: 'build'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2017-05-04 06:13:33 -04:00
|
|
|
Service.build_from_template(project.id, service_template).save!
|
2017-05-04 10:41:07 -04:00
|
|
|
Service.build_from_template(project.id, other_service).save!
|
2017-05-04 06:13:33 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.not_to change { Service.count }
|
2017-05-04 06:13:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the service containing the template attributes' do
|
2017-05-04 12:11:28 -04:00
|
|
|
described_class.propagate(service_template)
|
2017-05-04 06:13:33 -04:00
|
|
|
|
2017-05-05 12:57:52 -04:00
|
|
|
expect(project.pushover_service.properties).to eq(service_template.properties)
|
2017-05-04 06:13:33 -04:00
|
|
|
end
|
2017-05-05 04:43:56 -04:00
|
|
|
|
|
|
|
describe 'bulk update' do
|
2017-05-23 02:52:23 -04:00
|
|
|
let(:project_total) { 5 }
|
|
|
|
|
|
|
|
before do
|
2017-05-05 12:01:33 -04:00
|
|
|
stub_const 'Projects::PropagateServiceTemplate::BATCH_SIZE', 3
|
2017-05-05 04:43:56 -04:00
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
project_total.times { create(:project) }
|
2017-05-05 04:43:56 -04:00
|
|
|
|
2017-05-23 02:52:23 -04:00
|
|
|
described_class.propagate(service_template)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates services for all projects' do
|
|
|
|
expect(Service.all.reload.count).to eq(project_total + 2)
|
2017-05-05 04:43:56 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-05 10:16:02 -04:00
|
|
|
|
|
|
|
describe 'external tracker' do
|
|
|
|
it 'updates the project external tracker' do
|
2017-05-05 12:01:33 -04:00
|
|
|
service_template.update!(category: 'issue_tracker', default: false)
|
2017-05-05 10:16:02 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.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
|
2017-05-05 12:01:33 -04:00
|
|
|
service_template.update!(type: 'ExternalWikiService')
|
2017-05-05 10:16:02 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { described_class.propagate(service_template) }
|
|
|
|
.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
|