Work on specs
This commit is contained in:
parent
25dd1712ca
commit
4a369185d7
|
@ -9,7 +9,7 @@ class CreateDeploymentService < BaseService
|
|||
|
||||
@environment = environment
|
||||
@environment.external_url = expanded_url if expanded_url
|
||||
@environment.state_event = action
|
||||
@environment.fire_state_event(action)
|
||||
@environment.save!
|
||||
|
||||
return if @environment.stopped?
|
||||
|
@ -68,6 +68,6 @@ class CreateDeploymentService < BaseService
|
|||
end
|
||||
|
||||
def action
|
||||
params[:options].fetch(:action, 'start')
|
||||
options[:action] || 'start'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,4 +48,50 @@ describe Deployment, models: true do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stop_action' do
|
||||
let(:build) { create(:ci_build) }
|
||||
|
||||
subject { deployment.stop_action }
|
||||
|
||||
context 'when no other actions' do
|
||||
let(:deployment) { FactoryGirl.build(:deployment, deployable: build) }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'with other actions' do
|
||||
let!(:close_action) { create(:ci_build, pipeline: build.pipeline, name: 'close_app', when: :manual) }
|
||||
|
||||
context 'when matching action is defined' do
|
||||
let(:deployment) { FactoryGirl.build(:deployment, deployable: build, on_stop: 'close_other_app') }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when no matching action is defined' do
|
||||
let(:deployment) { FactoryGirl.build(:deployment, deployable: build, on_stop: 'close_app') }
|
||||
|
||||
it { is_expected.to eq(close_action) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stoppable?' do
|
||||
subject { deployment.stoppable? }
|
||||
|
||||
context 'when no other actions' do
|
||||
let(:deployment) { build(:deployment) }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
context 'when matching action is defined' do
|
||||
let(:build) { create(:ci_build) }
|
||||
let(:deployment) { FactoryGirl.build(:deployment, deployable: build, on_stop: 'close_app') }
|
||||
let!(:close_action) { create(:ci_build, pipeline: build.pipeline, name: 'close_app', when: :manual) }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,8 @@ describe Environment, models: true do
|
|||
|
||||
it { is_expected.to delegate_method(:last_deployment).to(:deployments).as(:last) }
|
||||
|
||||
it { is_expected.to delegate_method(:stop_action).to(:last_deployment).as(:last) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
|
||||
it { is_expected.to validate_length_of(:name).is_within(0..255) }
|
||||
|
@ -96,4 +98,34 @@ describe Environment, models: true do
|
|||
is_expected.to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stoppable?' do
|
||||
subject { environment.stoppable? }
|
||||
|
||||
context 'when no other actions' do
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
context 'when matching action is defined' do
|
||||
let(:build) { create(:ci_build) }
|
||||
let!(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') }
|
||||
let!(:close_action) { create(:ci_build, pipeline: build.pipeline, name: 'close_app', when: :manual) }
|
||||
|
||||
context 'when environment is available' do
|
||||
before do
|
||||
environment.start
|
||||
end
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when environment is stopped' do
|
||||
before do
|
||||
environment.stop
|
||||
end
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,11 +7,13 @@ describe CreateDeploymentService, services: true do
|
|||
let(:service) { described_class.new(project, user, params) }
|
||||
|
||||
describe '#execute' do
|
||||
let(:options) { nil }
|
||||
let(:params) do
|
||||
{ environment: 'production',
|
||||
ref: 'master',
|
||||
tag: false,
|
||||
sha: '97de212e80737a608d939f648d959671fb0a0142',
|
||||
options: options
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -28,7 +30,7 @@ describe CreateDeploymentService, services: true do
|
|||
end
|
||||
|
||||
context 'when environment exist' do
|
||||
before { create(:environment, project: project, name: 'production') }
|
||||
let!(:environment) { create(:environment, project: project, name: 'production') }
|
||||
|
||||
it 'does not create a new environment' do
|
||||
expect { subject }.not_to change { Environment.count }
|
||||
|
@ -37,6 +39,46 @@ describe CreateDeploymentService, services: true do
|
|||
it 'does create a deployment' do
|
||||
expect(subject).to be_persisted
|
||||
end
|
||||
|
||||
context 'and start action is defined' do
|
||||
let(:options) { { action: 'start' } }
|
||||
|
||||
context 'and environment is stopped' do
|
||||
before do
|
||||
environment.stop
|
||||
end
|
||||
|
||||
it 'makes environment available' do
|
||||
subject
|
||||
|
||||
expect(environment.reload).to be_available
|
||||
end
|
||||
|
||||
it 'does not create a deployment' do
|
||||
expect(subject).not_to be_persisted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'and stop action is defined' do
|
||||
let(:options) { { action: 'stop' } }
|
||||
|
||||
context 'and environment is available' do
|
||||
before do
|
||||
environment.start
|
||||
end
|
||||
|
||||
it 'makes environment stopped' do
|
||||
subject
|
||||
|
||||
expect(environment.reload).to be_stopped
|
||||
end
|
||||
|
||||
it 'does not create a deployment' do
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'for environment with invalid name' do
|
||||
|
@ -83,6 +125,23 @@ describe CreateDeploymentService, services: true do
|
|||
it 'does create a new deployment' do
|
||||
expect(subject).to be_persisted
|
||||
end
|
||||
|
||||
context 'and environment exist' do
|
||||
it 'does not create a new environment' do
|
||||
expect { subject }.not_to change { Environment.count }
|
||||
end
|
||||
|
||||
it 'updates external url' do
|
||||
subject
|
||||
|
||||
expect(subject.environment.name).to eq('review-apps/feature-review-apps')
|
||||
expect(subject.environment.external_url).to eq('http://feature-review-apps.review-apps.gitlab.com')
|
||||
end
|
||||
|
||||
it 'does create a new deployment' do
|
||||
expect(subject).to be_persisted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when project was removed' do
|
||||
|
|
Loading…
Reference in New Issue