summaryrefslogtreecommitdiff
path: root/spec/models/environment_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-07 00:06:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-07 00:06:18 +0000
commitee6b185429b62857a5e490526095a7699e8539f3 (patch)
treede54f53b76c5da2bf05cbd333e1910bbe655d653 /spec/models/environment_spec.rb
parentcf85de264d049f1f8ff14b23f38f8331ae4c60fa (diff)
downloadgitlab-ce-ee6b185429b62857a5e490526095a7699e8539f3.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r--spec/models/environment_spec.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 4566045bffd..8f3f45e159d 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
describe Environment, :use_clean_rails_memory_store_caching do
include ReactiveCachingHelpers
using RSpec::Parameterized::TableSyntax
+ include RepoHelpers
let(:project) { create(:project, :stubbed_repository) }
subject(:environment) { create(:environment, project: project) }
@@ -505,6 +506,14 @@ describe Environment, :use_clean_rails_memory_store_caching do
end
end
+ context 'when there is a deployment record with failed status' do
+ let!(:deployment) { create(:deployment, :failed, 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) }
@@ -557,6 +566,89 @@ describe Environment, :use_clean_rails_memory_store_caching do
end
end
+ describe '#last_visible_pipeline' do
+ let(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :repository) }
+ let(:environment) { create(:environment, project: project) }
+ let(:commit) { project.commit }
+
+ let(:success_pipeline) do
+ create(:ci_pipeline, :success, project: project, user: user, sha: commit.sha)
+ end
+
+ let(:failed_pipeline) do
+ create(:ci_pipeline, :failed, project: project, user: user, sha: commit.sha)
+ end
+
+ it 'uses the last deployment even if it failed' do
+ pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
+ ci_build = create(:ci_build, project: project, pipeline: pipeline)
+ create(:deployment, :failed, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
+
+ last_pipeline = environment.last_visible_pipeline
+
+ expect(last_pipeline).to eq(pipeline)
+ end
+
+ it 'returns nil if there is no deployment' do
+ create(:ci_build, project: project, pipeline: success_pipeline)
+
+ expect(environment.last_visible_pipeline).to be_nil
+ end
+
+ it 'does not return an invisible pipeline' do
+ failed_pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
+ ci_build_a = create(:ci_build, project: project, pipeline: failed_pipeline)
+ create(:deployment, :failed, project: project, environment: environment, deployable: ci_build_a, sha: commit.sha)
+ pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
+ ci_build_b = create(:ci_build, project: project, pipeline: pipeline)
+ create(:deployment, :created, project: project, environment: environment, deployable: ci_build_b, sha: commit.sha)
+
+ last_pipeline = environment.last_visible_pipeline
+
+ expect(last_pipeline).to eq(failed_pipeline)
+ end
+
+ context 'for the environment' do
+ it 'returns the last pipeline' do
+ pipeline = create(:ci_pipeline, project: project, user: user, sha: commit.sha)
+ ci_build = create(:ci_build, project: project, pipeline: pipeline)
+ create(:deployment, :success, project: project, environment: environment, deployable: ci_build, sha: commit.sha)
+
+ last_pipeline = environment.last_visible_pipeline
+
+ expect(last_pipeline).to eq(pipeline)
+ end
+
+ context 'with multiple deployments' do
+ it 'returns the last pipeline' do
+ pipeline_a = create(:ci_pipeline, project: project, user: user)
+ pipeline_b = create(:ci_pipeline, project: project, user: user)
+ ci_build_a = create(:ci_build, project: project, pipeline: pipeline_a)
+ ci_build_b = create(:ci_build, project: project, pipeline: pipeline_b)
+ create(:deployment, :success, project: project, environment: environment, deployable: ci_build_a)
+ create(:deployment, :success, project: project, environment: environment, deployable: ci_build_b)
+
+ last_pipeline = environment.last_visible_pipeline
+
+ expect(last_pipeline).to eq(pipeline_b)
+ end
+ end
+
+ context 'with multiple pipelines' do
+ it 'returns the last pipeline' do
+ create(:ci_build, project: project, pipeline: success_pipeline)
+ ci_build_b = create(:ci_build, project: project, pipeline: failed_pipeline)
+ create(:deployment, :failed, project: project, environment: environment, deployable: ci_build_b, sha: commit.sha)
+
+ last_pipeline = environment.last_visible_pipeline
+
+ expect(last_pipeline).to eq(failed_pipeline)
+ end
+ end
+ end
+ end
+
describe '#has_terminals?' do
subject { environment.has_terminals? }