Commit ceb06983 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Make it possible to fabricate environment on branch

parent 990765ed
......@@ -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",
......
......@@ -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
......
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