diff options
Diffstat (limited to 'spec/services/environments')
-rw-r--r-- | spec/services/environments/stop_service_spec.rb | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/spec/services/environments/stop_service_spec.rb b/spec/services/environments/stop_service_spec.rb index 3ed8a0b1da0..4f766b73710 100644 --- a/spec/services/environments/stop_service_spec.rb +++ b/spec/services/environments/stop_service_spec.rb @@ -193,7 +193,7 @@ RSpec.describe Environments::StopService do end it 'has active environment at first' do - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end context 'when user is a developer' do @@ -201,21 +201,43 @@ RSpec.describe Environments::StopService do project.add_developer(user) end + context 'and merge request has associated created_environments' do + let!(:environment1) { create(:environment, project: project, merge_request: merge_request) } + let!(:environment2) { create(:environment, project: project, merge_request: merge_request) } + + before do + subject + end + + it 'stops the associated created_environments' do + expect(environment1.reload).to be_stopped + expect(environment2.reload).to be_stopped + end + + it 'does not affect environments that are not associated to the merge request' do + expect(pipeline.environments_in_self_and_project_descendants.first.merge_request).to be_nil + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available + end + end + it 'stops the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_stopping + expect(pipeline.environments_in_self_and_project_descendants.first).to be_stopping end context 'when pipeline is a branch pipeline for merge request' do let(:pipeline) do - create(:ci_pipeline, source: :push, project: project, sha: merge_request.diff_head_sha, - merge_requests_as_head_pipeline: [merge_request]) + create(:ci_pipeline, + source: :push, + project: project, + sha: merge_request.diff_head_sha, + merge_requests_as_head_pipeline: [merge_request]) end it 'does not stop the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end end @@ -241,7 +263,7 @@ RSpec.describe Environments::StopService do it 'does not stop the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end end @@ -265,7 +287,7 @@ RSpec.describe Environments::StopService do it 'does not stop the active environment' do subject - expect(pipeline.environments_in_self_and_descendants.first).to be_available + expect(pipeline.environments_in_self_and_project_descendants.first).to be_available end end end |