summaryrefslogtreecommitdiff
path: root/spec/models/ci/pipeline_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-09-12 18:13:07 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-09-14 13:20:05 +0200
commit72190099934badcb3296983a457123c9e0303060 (patch)
treee1f447f2fea15b29860475d5830016b287c81925 /spec/models/ci/pipeline_spec.rb
parent3e999684f9c3b7306dea7a7feee90536ee100ccf (diff)
downloadgitlab-ce-72190099934badcb3296983a457123c9e0303060.tar.gz
Memoize the latest builds of a pipelineprojects-controller-show
This ensures that if a pipeline is present for the last commit on a project's homepage we only run 1 query to get the builds, instead of running 2 queries. See https://gitlab.com/gitlab-org/gitlab-ce/issues/36878#note_40073339 for more information.
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 95da97b7bc5..77f0be6b120 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1439,4 +1439,24 @@ describe Ci::Pipeline, :mailer do
it_behaves_like 'not sending any notification'
end
end
+
+ describe '#latest_builds_with_artifacts' do
+ let!(:pipeline) { create(:ci_pipeline, :success) }
+
+ let!(:build) do
+ create(:ci_build, :success, :artifacts, pipeline: pipeline)
+ end
+
+ it 'returns the latest builds' do
+ expect(pipeline.latest_builds_with_artifacts).to eq([build])
+ end
+
+ it 'memoizes the returned relation' do
+ query_count = ActiveRecord::QueryRecorder
+ .new { 2.times { pipeline.latest_builds_with_artifacts.to_a } }
+ .count
+
+ expect(query_count).to eq(1)
+ end
+ end
end