diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-14 14:51:12 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-14 14:51:12 +0300 |
commit | 3ade826065f38e3734090cf34fbfc28b68ba79d0 (patch) | |
tree | 8894c90dc892086df16782f2c54ca8f6b8b4adb6 /spec/services | |
parent | e8f09f02bf8b0053f276a8e5ce0bdd18c621a1a3 (diff) |
Add specs for models and services
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/create_deployment_service_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/services/create_deployment_service_spec.rb b/spec/services/create_deployment_service_spec.rb new file mode 100644 index 00000000000..76f3e0ac9ff --- /dev/null +++ b/spec/services/create_deployment_service_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe CreateDeploymentService, services: true do + let(:build) { create(:ci_build) } + let(:project) { build.project } + let(:user) { create(:user) } + + let(:service) { described_class.new(project, user, params) } + + describe '#execute' do + let(:params) do + { environment: 'production', + ref: 'master', + sha: build.sha, + } + end + + subject { service.execute } + + context 'when no environments exist' do + it 'does create a new environment' do + expect { subject }.to change { Environment.count }.by(1) + end + + it 'does create a deployment' do + expect(subject).to be_persisted + end + end + + context 'when environment exist' do + before { create(:environment, project: project, name: 'production') } + + it 'does not create a new environment' do + expect { subject }.not_to change { Environment.count } + end + + it 'does create a deployment' do + expect(subject).to be_persisted + end + end + + context 'for environment with invalid name' do + let(:params) do + { environment: 'name with spaces', + ref: 'master', + sha: build.sha, + } + end + + it 'does not create a new environment' do + expect { subject }.not_to change { Environment.count } + end + + it 'does not create a deployment' do + expect(subject).not_to be_persisted + end + end + end +end |