Skip to content
Snippets Groups Projects
Commit f7ef7bea authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Add environment factory review app trait

parent 04a8372c
No related branches found
No related tags found
No related merge requests found
module Ci
class StopEnvironmentService < BaseService
def execute(ref)
@ref = ref
@commit = project.commit(ref)
attr_reader :ref
 
return unless has_ref_sha_pair?
def execute(branch_name)
@ref = branch_name
return unless has_ref_commit_pair?
return unless has_environments?
 
environments.each do |environment|
Loading
Loading
@@ -16,8 +17,12 @@ def execute(ref)
 
private
 
def has_ref_sha_pair?
@ref && @commit
def has_ref_commit_pair?
ref && commit
end
def commit
@commit ||= project.commit(ref)
end
 
def has_environments?
Loading
Loading
@@ -25,7 +30,7 @@ def has_environments?
end
 
def environments
@environments ||= project.environments_for(@ref, @commit)
@environments ||= project.environments_for(ref, commit)
end
end
end
Loading
Loading
@@ -3,8 +3,9 @@
sha '97de212e80737a608d939f648d959671fb0a0142'
ref 'master'
tag false
user
project nil
deployable factory: :ci_build
environment factory: :environment
 
after(:build) do |deployment, evaluator|
Loading
Loading
Loading
Loading
@@ -4,5 +4,28 @@
 
project factory: :empty_project
sequence(:external_url) { |n| "https://env#{n}.example.gitlab.com" }
trait :with_review_app do |environment|
project
# 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|
deployment = create(:deployment,
environment: environment,
project: environment.project,
sha: environment.project.commit.id)
teardown_build = create(:ci_build, :manual,
name: "#{deployment.environment.name}:teardown",
pipeline: deployment.deployable.pipeline)
deployment.update_column(:on_stop, teardown_build.name)
environment.update_attribute(:deployments, [deployment])
end
end
end
end
Loading
Loading
@@ -8,21 +8,8 @@
 
describe '#execute' do
context 'when environment exists' do
let(:environment) { create(:environment, project: project) }
let(:deployable) { create(:ci_build) }
let(:stop_build) do
create(:ci_build, :manual, name: 'environment/teardown',
pipeline: deployable.pipeline)
end
before do
create(:deployment, environment: environment,
deployable: deployable,
on_stop: stop_build.name,
user: user,
project: project,
sha: project.commit.id)
create(:environment, :with_review_app, project: project)
end
 
it 'stops environment' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment