summaryrefslogtreecommitdiff
path: root/spec/services/ci
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-14 13:54:23 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-11-14 13:54:23 +0100
commitd945300b8e49c927da8a12ba3a8bac68dbc4b9fc (patch)
tree6d82d5a6b8e94a54d6d936d02a65039b1d395a60 /spec/services/ci
parentec0daedbc45104324387804ef7c3c9337fde1fda (diff)
downloadgitlab-ce-d945300b8e49c927da8a12ba3a8bac68dbc4b9fc.tar.gz
Check permissions before stopping CI environments
Diffstat (limited to 'spec/services/ci')
-rw-r--r--spec/services/ci/stop_environment_service_spec.rb72
1 files changed, 49 insertions, 23 deletions
diff --git a/spec/services/ci/stop_environment_service_spec.rb b/spec/services/ci/stop_environment_service_spec.rb
index 047f9b0b2ca..e044b40679a 100644
--- a/spec/services/ci/stop_environment_service_spec.rb
+++ b/spec/services/ci/stop_environment_service_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Ci::StopEnvironmentService, services: true do
- let(:project) { create(:project) }
+ let(:project) { create(:project, :private) }
let(:user) { create(:user) }
let(:service) { described_class.new(project, user) }
@@ -12,38 +12,46 @@ describe Ci::StopEnvironmentService, services: true do
create(:environment, :with_review_app, project: project)
end
- it 'stops environment' do
- expect_any_instance_of(Environment).to receive(:stop!)
+ context 'when user has permission to stop environment' do
+ before do
+ project.team << [user, :developer]
+ end
- service.execute('master')
- end
+ it 'stops environment' do
+ expect_environment_stopped_on('master')
+ end
- context 'when specified branch does not exist' do
- it 'does not stop environment' do
- expect_any_instance_of(Environment).not_to receive(:stop!)
+ context 'when specified branch does not exist' do
+ it 'does not stop environment' do
+ expect_environment_not_stopped_on('non/existent/branch')
+ end
+ end
- service.execute('non/existent/branch')
+ context 'when no branch not specified' do
+ it 'does not stop environment' do
+ expect_environment_not_stopped_on(nil)
+ end
end
- end
- context 'when no branch not specified' do
- it 'does not stop environment' do
- expect_any_instance_of(Environment).not_to receive(:stop!)
+ context 'when environment is not stoppable' do
+ before do
+ allow_any_instance_of(Environment)
+ .to receive(:stoppable?).and_return(false)
+ end
- service.execute(nil)
+ it 'does not stop environment' do
+ expect_environment_not_stopped_on('master')
+ end
end
end
- context 'when environment is not stoppable' do
+ context 'when user does not have permission to stop environment' do
before do
- allow_any_instance_of(Environment)
- .to receive(:stoppable?).and_return(false)
+ project.team << [user, :guest]
end
it 'does not stop environment' do
- expect_any_instance_of(Environment).not_to receive(:stop!)
-
- service.execute('master')
+ expect_environment_not_stopped_on('master')
end
end
end
@@ -53,10 +61,14 @@ describe Ci::StopEnvironmentService, services: true do
create(:environment, project: project)
end
- it 'does not stop environment' do
- expect_any_instance_of(Environment).not_to receive(:stop!)
+ context 'when user has permission to stop environments' do
+ before do
+ project.team << [user, :master]
+ end
- service.execute('master')
+ it 'does not stop environment' do
+ expect_environment_not_stopped_on('master')
+ end
end
end
@@ -67,4 +79,18 @@ describe Ci::StopEnvironmentService, services: true do
end
end
end
+
+ def expect_environment_stopped_on(branch)
+ expect_any_instance_of(Environment)
+ .to receive(:stop!)
+
+ service.execute(branch)
+ end
+
+ def expect_environment_not_stopped_on(branch)
+ expect_any_instance_of(Environment)
+ .not_to receive(:stop!)
+
+ service.execute(branch)
+ end
end