Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3eb57b81
Commit
3eb57b81
authored
Apr 12, 2021
by
Athar Hameed
Committed by
Stan Hu
Apr 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add N+1 query specs for the snippet index actions
parent
72191923
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
18 deletions
+37
-18
spec/controllers/dashboard/snippets_controller_spec.rb
spec/controllers/dashboard/snippets_controller_spec.rb
+1
-18
spec/controllers/explore/snippets_controller_spec.rb
spec/controllers/explore/snippets_controller_spec.rb
+4
-0
spec/controllers/projects/snippets_controller_spec.rb
spec/controllers/projects/snippets_controller_spec.rb
+4
-0
spec/support/shared_examples/controllers/snippet_shared_examples.rb
...rt/shared_examples/controllers/snippet_shared_examples.rb
+28
-0
No files found.
spec/controllers/dashboard/snippets_controller_spec.rb
View file @
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
spec/controllers/explore/snippets_controller_spec.rb
View file @
3eb57b81
...
...
@@ -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
spec/controllers/projects/snippets_controller_spec.rb
View file @
3eb57b81
...
...
@@ -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
)
}
...
...
spec/support/shared_examples/controllers/snippet_shared_examples.rb
0 → 100644
View file @
3eb57b81
# 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment