Commit 413455ca authored by Arturo Herrero's avatar Arturo Herrero

Extract shared examples for service templates

parent 7204ffea
...@@ -152,14 +152,18 @@ describe Service do ...@@ -152,14 +152,18 @@ describe Service do
describe 'template' do describe 'template' do
let(:project) { create(:project) } 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 describe '.find_or_create_templates' do
it 'creates service 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) expect { Service.find_or_create_templates }.to change { Service.count }.from(0).to(Service.available_services_names.size)
end end
it 'returns the available service templates' do it_behaves_like 'retrieves service templates'
expect(Service.find_or_create_templates.map(&:type)).to match_array(Service.available_services_types)
end
context 'with all existing templates' do context 'with all existing templates' do
before do before do
...@@ -172,9 +176,7 @@ describe Service do ...@@ -172,9 +176,7 @@ describe Service do
expect { Service.find_or_create_templates }.to change { Service.count }.by(0) expect { Service.find_or_create_templates }.to change { Service.count }.by(0)
end end
it 'returns the available service templates' do it_behaves_like 'retrieves service templates'
expect(Service.find_or_create_templates.map(&:type)).to match_array(Service.available_services_types)
end
context 'with a previous existing service (Previous) and a new service (Asana)' do context 'with a previous existing service (Previous) and a new service (Asana)' do
before do before do
...@@ -182,24 +184,20 @@ describe Service do ...@@ -182,24 +184,20 @@ describe Service do
Service.delete_by(type: 'AsanaService', template: true) Service.delete_by(type: 'AsanaService', template: true)
end end
it 'returns the available service templates' do it_behaves_like 'retrieves service templates'
expect(Service.find_or_create_templates.map(&:type)).to match_array(Service.available_services_types)
end
end end
end end
context 'with a few existing templates' do context 'with a few existing templates' do
before do before do
JiraService.create(template: true) create(:jira_service, :template)
end end
it 'creates the rest of the service templates' do 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) expect { Service.find_or_create_templates }.to change { Service.count }.from(1).to(Service.available_services_names.size)
end end
it 'returns the available service templates' do it_behaves_like 'retrieves service templates'
expect(Service.find_or_create_templates.map(&:type)).to match_array(Service.available_services_types)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment