diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-10-25 11:58:07 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-10-30 07:42:13 +0300 |
commit | fefe3fdfff4f89b48cc30bddf4b2cd191ad81da0 (patch) | |
tree | 22f30573e7e7382503c5d72a5110cc3ebb6ba771 | |
parent | 6e000e972b991edf3b6abe6d876593a6f8538661 (diff) |
Add spec for Environment
-rw-r--r-- | spec/models/environment_spec.rb | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 992ae81a5c5..0ebc49ae5d5 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -331,6 +331,90 @@ describe Environment do end end + describe '.deployments' do + subject { environment.deployments } + + before do + allow_any_instance_of(Deployment).to receive(:create_ref) + end + + context 'when there is a deployment record with created status' do + let(:deployment) { create(:deployment, :created, environment: environment) } + + it 'does not return the record' do + is_expected.to be_empty + end + end + + context 'when there is a deployment record with running status' do + let(:deployment) { create(:deployment, :running, environment: environment) } + + it 'does not return the record' do + is_expected.to be_empty + end + end + + context 'when there is a deployment record with success status' do + let(:deployment) { create(:deployment, :success, environment: environment) } + + it 'returns the record' do + is_expected.to eq([deployment]) + end + end + + context 'when there is a deployment record with legacy successful status' do + let(:deployment) { create(:deployment, environment: environment) } + + it 'returns the record' do + is_expected.to eq([deployment]) + end + end + end + + describe '.last_deployment' do + subject { environment.last_deployment } + + before do + allow_any_instance_of(Deployment).to receive(:create_ref) + end + + context 'when there is an old deployment record' do + let!(:previous_deployment) { create(:deployment, environment: environment) } + + context 'when there is a deployment record with created status' do + let!(:deployment) { create(:deployment, :created, environment: environment) } + + it 'returns the previous deployment' do + is_expected.to eq(previous_deployment) + end + end + + context 'when there is a deployment record with running status' do + let!(:deployment) { create(:deployment, :running, environment: environment) } + + it 'returns the previous deployment' do + is_expected.to eq(previous_deployment) + end + end + + context 'when there is a deployment record with success status' do + let!(:deployment) { create(:deployment, :success, environment: environment) } + + it 'returns the latest successful deployment' do + is_expected.to eq(deployment) + end + end + + context 'when there is a deployment record with legacy successful status' do + let!(:deployment) { create(:deployment, environment: environment) } + + it 'returns the latest successful deployment' do + is_expected.to eq(deployment) + end + end + end + end + describe '#has_terminals?' do subject { environment.has_terminals? } |