diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/models/commit_collection_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
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.rb | 29 |
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 |