Commit f7ef7bea authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add environment factory review app trait

parent 04a8372c
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|
......@@ -16,8 +17,12 @@ module Ci
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?
......@@ -25,7 +30,7 @@ module Ci
end
def environments
@environments ||= project.environments_for(@ref, @commit)
@environments ||= project.environments_for(ref, commit)
end
end
end
......@@ -3,8 +3,9 @@ FactoryGirl.define do
sha '97de212e80737a608d939f648d959671fb0a0142'
ref 'master'
tag false
user
project nil
deployable factory: :ci_build
environment factory: :environment
after(:build) do |deployment, evaluator|
......
......@@ -4,5 +4,28 @@ FactoryGirl.define do
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
......@@ -8,21 +8,8 @@ describe Ci::StopEnvironmentService, services: true do
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment