2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Dashboard::SnippetsController do
|
2020-07-28 23:09:34 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it_behaves_like 'paginated collection' do
|
|
|
|
let(:collection) { Snippet.all }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:personal_snippet, :public, author: user)
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'fetches snippet counts via the snippet count service' do
|
|
|
|
service = double(:count_service, execute: {})
|
|
|
|
expect(Snippets::CountService)
|
|
|
|
.to receive(:new).with(user, author: user)
|
|
|
|
.and_return(service)
|
|
|
|
|
|
|
|
get :index
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
it_behaves_like 'snippets sort order'
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
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
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|