diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/support/shared_examples/controllers/snippet_shared_examples.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/support/shared_examples/controllers/snippet_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/controllers/snippet_shared_examples.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/support/shared_examples/controllers/snippet_shared_examples.rb b/spec/support/shared_examples/controllers/snippet_shared_examples.rb new file mode 100644 index 00000000000..f49cc979368 --- /dev/null +++ b/spec/support/shared_examples/controllers/snippet_shared_examples.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'snippets views' do + let(:params) { {} } + + before do + sign_in(user) + end + + context 'when rendered' do + render_views + + it 'avoids N+1 database queries' do + # Warming call to load everything non snippet related + get(:index, params: params) + + project = create(:project, namespace: user.namespace) + create(:project_snippet, project: project, author: user) + + control_count = ActiveRecord::QueryRecorder.new { get(:index, params: params) }.count + + project = create(:project, namespace: user.namespace) + create(:project_snippet, project: project, author: user) + + expect { get(:index, params: params) }.not_to exceed_query_limit(control_count) + end + end +end |