From ceb06983ec186bcc1c6fce28613bdb92297e5bf1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 14 Nov 2016 14:10:54 +0100 Subject: [PATCH] Make it possible to fabricate environment on branch --- spec/factories/environments.rb | 9 +++++++-- .../ci/stop_environments_service_spec.rb | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/spec/factories/environments.rb b/spec/factories/environments.rb index bb6558a403f..0852dda6b29 100644 --- a/spec/factories/environments.rb +++ b/spec/factories/environments.rb @@ -8,16 +8,21 @@ FactoryGirl.define do trait :with_review_app do |environment| project + transient do + ref 'master' + end + # At this point `review app` is an ephemeral concept related to # deployments being deployed for given environment. There is no # first-class `review app` available so we need to create set of # interconnected objects to simulate a review app. # - after(:create) do |environment| + after(:create) do |environment, evaluator| deployment = create(:deployment, environment: environment, project: environment.project, - sha: environment.project.commit.id) + ref: evaluator.ref, + sha: environment.project.commit(evaluator.ref).id) teardown_build = create(:ci_build, :manual, name: "#{deployment.environment.name}:teardown", diff --git a/spec/services/ci/stop_environments_service_spec.rb b/spec/services/ci/stop_environments_service_spec.rb index c3e1af3afe2..6f7d1a5d28d 100644 --- a/spec/services/ci/stop_environments_service_spec.rb +++ b/spec/services/ci/stop_environments_service_spec.rb @@ -9,7 +9,8 @@ describe Ci::StopEnvironmentsService, services: true do describe '#execute' do context 'when environment with review app exists' do before do - create(:environment, :with_review_app, project: project) + create(:environment, :with_review_app, project: project, + ref: 'feature') end context 'when user has permission to stop environment' do @@ -17,8 +18,16 @@ describe Ci::StopEnvironmentsService, services: true do project.team << [user, :developer] end - it 'stops environment' do - expect_environment_stopped_on('master') + context 'when environment is associated with removed branch' do + it 'stops environment' do + expect_environment_stopped_on('feature') + end + end + + context 'when environment is associated with different branch' do + it 'does not stop environment' do + expect_environment_not_stopped_on('master') + end end context 'when specified branch does not exist' do @@ -40,7 +49,7 @@ describe Ci::StopEnvironmentsService, services: true do end it 'does not stop environment' do - expect_environment_not_stopped_on('master') + expect_environment_not_stopped_on('feature') end end end