Commit d2526c10 authored by Stan Hu's avatar Stan Hu

Merge branch '324704-add-n-1-query-specs-for-the-snippet-index-actions' into 'master'

Add N+1 query specs for the snippet index actions

See merge request gitlab-org/gitlab!58732
parents 077ada55 3eb57b81
......@@ -29,23 +29,6 @@ RSpec.describe Dashboard::SnippetsController do
it_behaves_like 'snippets sort order'
context 'when views are rendered' do
render_views
it 'avoids N+1 database queries' do
# Warming call to load everything non snippet related
get(:index)
project = create(:project, namespace: user.namespace)
create(:project_snippet, project: project, author: user)
control_count = ActiveRecord::QueryRecorder.new { get(:index) }.count
project = create(:project, namespace: user.namespace)
create(:project_snippet, project: project, author: user)
expect { get(:index) }.not_to exceed_query_limit(control_count)
end
end
it_behaves_like 'snippets views'
end
end
......@@ -32,5 +32,9 @@ RSpec.describe Explore::SnippetsController do
expect(assigns(:snippets)).to all(be_a(PersonalSnippet))
expect(response).to have_gitlab_http_status(:ok)
end
it_behaves_like 'snippets views' do
let_it_be(:user) { create(:user) }
end
end
end
......@@ -46,6 +46,10 @@ RSpec.describe Projects::SnippetsController do
let(:params) { base_params }
end
it_behaves_like 'snippets views' do
let(:params) { base_params }
end
context 'when the project snippet is private' do
let_it_be(:project_snippet) { create(:project_snippet, :private, project: project, author: user) }
......
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment