BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c4de6ec4
Commit
c4de6ec4
authored
Nov 22, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'improve-extra-queries-output' into 'master'
Improve output for extra queries in specs See merge request gitlab-org/gitlab-ce!15537
parents
e72804ed
db1925f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+3
-3
query_recorder.rb
spec/support/query_recorder.rb
+9
-2
No files found.
spec/requests/api/merge_requests_spec.rb
View file @
c4de6ec4
...
...
@@ -172,15 +172,15 @@ describe API::MergeRequests do
context
"when authenticated"
do
it
'avoids N+1 queries'
do
control
_count
=
ActiveRecord
::
QueryRecorder
.
new
do
control
=
ActiveRecord
::
QueryRecorder
.
new
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
)
end
.
count
end
create
(
:merge_request
,
state:
'closed'
,
milestone:
milestone1
,
author:
user
,
assignee:
user
,
source_project:
project
,
target_project:
project
,
title:
"Test"
,
created_at:
base_time
)
expect
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
)
end
.
not_to
exceed_query_limit
(
control
_count
)
end
.
not_to
exceed_query_limit
(
control
)
end
it
"returns an array of all merge_requests"
do
...
...
spec/support/query_recorder.rb
View file @
c4de6ec4
...
...
@@ -76,10 +76,17 @@ RSpec::Matchers.define :exceed_query_limit do |expected|
@recorder
.
count
end
def
count_queries
(
queries
)
queries
.
each_with_object
(
Hash
.
new
(
0
))
{
|
query
,
counts
|
counts
[
query
]
+=
1
}
end
def
log_message
if
expected
.
is_a?
(
ActiveRecord
::
QueryRecorder
)
extra_queries
=
(
expected
.
log
-
@recorder
.
log
).
join
(
"
\n\n
"
)
"Extra queries:
\n\n
#{
extra_queries
}
"
counts
=
count_queries
(
expected
.
log
)
extra_queries
=
@recorder
.
log
.
reject
{
|
query
|
counts
[
query
]
-=
1
unless
counts
[
query
].
zero?
}
extra_queries_display
=
count_queries
(
extra_queries
).
map
{
|
query
,
count
|
"[
#{
count
}
]
#{
query
}
"
}
([
'Extra queries:'
]
+
extra_queries_display
).
join
(
"
\n\n
"
)
else
@recorder
.
log_message
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