diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-06 15:19:52 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-06 17:15:15 +0200 |
commit | 6c0fc62ef5c4fa4535174a9f187b9853f0fb90ac (patch) | |
tree | 0db34e09c24d3b98baa48e4db6ac27e0b4324871 /spec | |
parent | e533d43a8c03a9b47a7016f3fea01a00ca797778 (diff) | |
download | gitlab-ce-6c0fc62ef5c4fa4535174a9f187b9853f0fb90ac.tar.gz |
Take branch access into account when stopping environment
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/environments.rb | 6 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 25 | ||||
-rw-r--r-- | spec/services/ci/stop_environments_service_spec.rb | 16 |
3 files changed, 45 insertions, 2 deletions
diff --git a/spec/factories/environments.rb b/spec/factories/environments.rb index f6595751d1e..d8d699fb3aa 100644 --- a/spec/factories/environments.rb +++ b/spec/factories/environments.rb @@ -20,14 +20,18 @@ FactoryGirl.define do after(:create) do |environment, evaluator| pipeline = create(:ci_pipeline, project: environment.project) + deployable = create(:ci_build, name: "#{environment.name}:deploy", + pipeline: pipeline) + deployment = create(:deployment, environment: environment, project: environment.project, + deployable: deployable, ref: evaluator.ref, sha: environment.project.commit(evaluator.ref).id) teardown_build = create(:ci_build, :manual, - name: "#{deployment.environment.name}:teardown", + name: "#{environment.name}:teardown", pipeline: pipeline) deployment.update_column(:on_stop, teardown_build.name) diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 9e00f2247e8..fb7cee47ae8 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -155,6 +155,31 @@ describe Environment, models: true do end end + describe '#can_trigger_stop_action?' do + let(:user) { create(:user) } + let(:project) { create(:project) } + + let(:environment) do + create(:environment, :with_review_app, project: project) + end + + context 'when user can trigger stop action' do + before do + project.add_developer(user) + end + + it 'returns value that evaluates to true' do + expect(environment.can_trigger_stop_action?(user)).to be_truthy + end + end + + context 'when user is not allowed to trigger stop action' do + it 'returns value that evaluates to false' do + expect(environment.can_trigger_stop_action?(user)).to be_falsey + end + end + end + describe '#stop_with_action!' do let(:user) { create(:admin) } diff --git a/spec/services/ci/stop_environments_service_spec.rb b/spec/services/ci/stop_environments_service_spec.rb index 32c72a9cf5e..98044ad232e 100644 --- a/spec/services/ci/stop_environments_service_spec.rb +++ b/spec/services/ci/stop_environments_service_spec.rb @@ -55,8 +55,22 @@ describe Ci::StopEnvironmentsService, services: true do end context 'when user does not have permission to stop environment' do + context 'when user has no access to manage deployments' do + before do + project.team << [user, :guest] + end + + it 'does not stop environment' do + expect_environment_not_stopped_on('master') + end + end + end + + context 'when branch for stop action is protected' do before do - project.team << [user, :guest] + project.add_developer(user) + create(:protected_branch, :no_one_can_push, + name: 'master', project: project) end it 'does not stop environment' do |