diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:07:55 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-24 18:07:55 +0000 |
commit | 603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc (patch) | |
tree | 907f5b8ee1b6f5aad396e95e3327a08400b9e8ea /spec/models/service_spec.rb | |
parent | 120f4aaedc8fe830a3f572491d240d8ee6addefb (diff) | |
download | gitlab-ce-603c7d4cac5e28bc1c75e50c23ed2cbe56f1aafc.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/service_spec.rb')
-rw-r--r-- | spec/models/service_spec.rb | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 7c80b5231d1..cecd4f76fc5 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -149,9 +149,58 @@ describe Service do end end - describe "Template" do + describe 'template' do let(:project) { create(:project) } + shared_examples 'retrieves service templates' do + it 'returns the available service templates' do + expect(Service.find_or_create_templates.pluck(:type)).to match_array(Service.available_services_types) + end + end + + describe '.find_or_create_templates' do + it 'creates service templates' do + expect { Service.find_or_create_templates }.to change { Service.count }.from(0).to(Service.available_services_names.size) + end + + it_behaves_like 'retrieves service templates' + + context 'with all existing templates' do + before do + Service.insert_all( + Service.available_services_types.map { |type| { template: true, type: type } } + ) + end + + it 'does not create service templates' do + expect { Service.find_or_create_templates }.to change { Service.count }.by(0) + end + + it_behaves_like 'retrieves service templates' + + context 'with a previous existing service (Previous) and a new service (Asana)' do + before do + Service.insert(type: 'PreviousService', template: true) + Service.delete_by(type: 'AsanaService', template: true) + end + + it_behaves_like 'retrieves service templates' + end + end + + context 'with a few existing templates' do + before do + create(:jira_service, :template) + end + + it 'creates the rest of the service templates' do + expect { Service.find_or_create_templates }.to change { Service.count }.from(1).to(Service.available_services_names.size) + end + + it_behaves_like 'retrieves service templates' + end + end + describe '.build_from_template' do context 'when template is invalid' do it 'sets service template to inactive when template is invalid' do |