summaryrefslogtreecommitdiff
path: root/spec/models/service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/service_spec.rb')
-rw-r--r--spec/models/service_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
index 2bc8bdaed7c..825e5f5902f 100644
--- a/spec/models/service_spec.rb
+++ b/spec/models/service_spec.rb
@@ -18,6 +18,20 @@ describe Service do
expect(build(:service, project_id: nil, template: false)).to be_invalid
end
+ it 'validates presence of project_id if not instance', :aggregate_failures do
+ expect(build(:service, project_id: nil, instance: true)).to be_valid
+ expect(build(:service, project_id: nil, instance: false)).to be_invalid
+ end
+
+ it 'validates absence of project_id if instance', :aggregate_failures do
+ expect(build(:service, project_id: nil, instance: true)).to be_valid
+ expect(build(:service, instance: true)).to be_invalid
+ end
+
+ it 'validates service is template or instance' do
+ expect(build(:service, project_id: nil, template: true, instance: true)).to be_invalid
+ end
+
context 'with an existing service template' do
before do
create(:service, type: 'Service', template: true)
@@ -27,6 +41,16 @@ describe Service do
expect(build(:service, type: 'Service', template: true)).to be_invalid
end
end
+
+ context 'with an existing instance service' do
+ before do
+ create(:service, :instance)
+ end
+
+ it 'validates only one service instance per type' do
+ expect(build(:service, :instance)).to be_invalid
+ end
+ end
end
describe 'Scopes' do