summaryrefslogtreecommitdiff
path: root/spec/models/commit_collection_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/models/commit_collection_spec.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/models/commit_collection_spec.rb')
-rw-r--r--spec/models/commit_collection_spec.rb29
1 files changed, 20 insertions, 9 deletions
diff --git a/spec/models/commit_collection_spec.rb b/spec/models/commit_collection_spec.rb
index f4e86f3292b..de9b72c1da2 100644
--- a/spec/models/commit_collection_spec.rb
+++ b/spec/models/commit_collection_spec.rb
@@ -52,27 +52,38 @@ RSpec.describe CommitCollection do
end
describe '#with_latest_pipeline' do
+ let(:another_commit) { project.commit("60ecb67744cb56576c30214ff52294f8ce2def98") }
+
let!(:pipeline) do
- create(
- :ci_empty_pipeline,
- ref: 'master',
- sha: commit.id,
- status: 'success',
- project: project
- )
+ create(:ci_empty_pipeline, ref: 'master', sha: commit.id, status: 'success', project: project)
+ end
+
+ let!(:another_pipeline) do
+ create(:ci_empty_pipeline, ref: 'master', sha: another_commit.id, status: 'success', project: project)
end
- let(:collection) { described_class.new(project, [commit]) }
+
+ let(:collection) { described_class.new(project, [commit, another_commit]) }
it 'sets the latest pipeline for every commit so no additional queries are necessary' do
commits = collection.with_latest_pipeline('master')
recorder = ActiveRecord::QueryRecorder.new do
expect(commits.map { |c| c.latest_pipeline('master') })
- .to eq([pipeline])
+ .to eq([pipeline, another_pipeline])
end
expect(recorder.count).to be_zero
end
+
+ it 'performs a single query to fetch pipeline warnings' do
+ recorder = ActiveRecord::QueryRecorder.new do
+ collection.with_latest_pipeline('master').each do |c|
+ c.latest_pipeline('master').number_of_warnings.itself
+ end
+ end
+
+ expect(recorder.count).to eq(2) # 1 for pipelines, 1 for warnings counts
+ end
end
describe '#with_markdown_cache' do