diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-03-13 19:00:07 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-03-16 22:41:03 +0300 |
commit | 26d3da4bfe5c4718d3dfb4407cee58da53b408aa (patch) | |
tree | b3252b0ff91763b3bc7f798ac329dc0e2f05375b /spec | |
parent | ce5d1b6fd7ed1aea2d2a675414ba81be624f2bf1 (diff) |
removes n+1 query from tags and branches indexes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/branches_spec.rb | 8 | ||||
-rw-r--r-- | spec/features/tags/master_views_tags_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 13 |
3 files changed, 31 insertions, 0 deletions
diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb index d26a0caf036..8e0306ce83b 100644 --- a/spec/features/projects/branches_spec.rb +++ b/spec/features/projects/branches_spec.rb @@ -17,6 +17,14 @@ describe 'Branches', feature: true do repository.branches { |branch| expect(page).to have_content("#{branch.name}") } expect(page).to have_content("Protected branches can be managed in project settings") end + + it 'avoids a N+1 query in branches index' do + control_count = ActiveRecord::QueryRecorder.new { visit namespace_project_branches_path(project.namespace, project) }.count + + %w(one two three four five).each { |ref| repository.add_branch(@user, ref, 'master') } + + expect { visit namespace_project_branches_path(project.namespace, project) }.not_to exceed_query_limit(control_count) + end end describe 'Find branches' do diff --git a/spec/features/tags/master_views_tags_spec.rb b/spec/features/tags/master_views_tags_spec.rb index 29d2c244720..555f84c4772 100644 --- a/spec/features/tags/master_views_tags_spec.rb +++ b/spec/features/tags/master_views_tags_spec.rb @@ -27,10 +27,20 @@ feature 'Master views tags', feature: true do context 'when project has tags' do let(:project) { create(:project, namespace: user.namespace) } + let(:repository) { project.repository } + before do visit namespace_project_tags_path(project.namespace, project) end + scenario 'avoids a N+1 query in branches index' do + control_count = ActiveRecord::QueryRecorder.new { visit namespace_project_tags_path(project.namespace, project) }.count + + %w(one two three four five).each { |tag| repository.add_tag(user, tag, 'master', 'foo') } + + expect { visit namespace_project_tags_path(project.namespace, project) }.not_to exceed_query_limit(control_count) + end + scenario 'views the tags list page' do expect(page).to have_content 'v1.0.0' end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 4a664e4fae2..53282b999dc 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -532,6 +532,19 @@ describe Ci::Pipeline, models: true do end end + describe '.latest_successful_for_refs' do + include_context 'with some outdated pipelines' + + let!(:latest_successful_pipeline1) { create_pipeline(:success, 'ref1', 'D') } + let!(:latest_successful_pipeline2) { create_pipeline(:success, 'ref2', 'D') } + + it 'returns the latest successful pipeline for both refs' do + refs = %w(ref1 ref2 ref3) + + expect(described_class.latest_successful_for_refs(refs)).to eq({ 'ref1' => latest_successful_pipeline1, 'ref2' => latest_successful_pipeline2 }) + end + end + describe '#status' do let(:build) do create(:ci_build, :created, pipeline: pipeline, name: 'test') |