2017-05-03 13:43:26 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-05-03 15:20:12 +00:00
|
|
|
describe PropagateProjectServiceWorker do
|
2017-05-03 13:43:26 +00:00
|
|
|
describe '#perform' do
|
|
|
|
let!(:service_template) do
|
|
|
|
PushoverService.create(
|
|
|
|
template: true,
|
2017-05-03 15:20:12 +00:00
|
|
|
active: true,
|
2017-05-03 13:43:26 +00:00
|
|
|
properties: {
|
|
|
|
device: 'MyDevice',
|
|
|
|
sound: 'mic',
|
|
|
|
priority: 4,
|
2017-05-03 15:20:12 +00:00
|
|
|
user_key: 'asdf',
|
2017-05-03 13:43:26 +00:00
|
|
|
api_key: '123456789'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:project) { create(:empty_project) }
|
|
|
|
|
2017-05-03 15:20:12 +00:00
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).
|
|
|
|
and_return(true)
|
|
|
|
end
|
|
|
|
|
2017-05-03 13:43:26 +00:00
|
|
|
it 'creates services for projects' do
|
2017-05-03 15:20:12 +00:00
|
|
|
expect { subject.perform(service_template.id) }.to change { Service.count }.by(1)
|
2017-05-03 13:43:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create the service if it exists already' do
|
|
|
|
Service.build_from_template(project.id, service_template).save!
|
|
|
|
|
2017-05-03 15:20:12 +00:00
|
|
|
expect { subject.perform(service_template.id) }.not_to change { Service.count }
|
2017-05-03 13:43:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the service containing the template attributes' do
|
2017-05-03 15:20:12 +00:00
|
|
|
subject.perform(service_template.id)
|
2017-05-03 13:43:26 +00:00
|
|
|
|
2017-05-03 15:20:12 +00:00
|
|
|
service = Service.find_by(type: service_template.type, template: false)
|
2017-05-03 13:43:26 +00:00
|
|
|
|
2017-05-03 15:20:12 +00:00
|
|
|
expect(service.properties).to eq(service_template.properties)
|
2017-05-03 13:43:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|