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
3b7df66e
Commit
3b7df66e
authored
Aug 18, 2019
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require request specs when testing N+1 for controllers
parent
1068483f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
doc/development/query_recorder.md
doc/development/query_recorder.md
+7
-0
doc/development/testing_guide/testing_levels.md
doc/development/testing_guide/testing_levels.md
+1
-1
No files found.
doc/development/query_recorder.md
View file @
3b7df66e
...
@@ -36,6 +36,13 @@ it "avoids N+1 database queries" do
...
@@ -36,6 +36,13 @@ it "avoids N+1 database queries" do
end
end
```
```
## Use request specs instead of controller specs
Use a
[
request spec
](
https://gitlab.com/gitlab-org/gitlab-ce/tree/master/spec/requests
)
when writing a N+1 test on the controller level.
Controller specs should not be used to write N+1 tests as the controller is only initialized once per example.
This could lead to false successes where subsequent "requests" could have queries reduced (e.g. because of memoization).
## Finding the source of the query
## Finding the source of the query
It may be useful to identify the source of the queries by looking at the call backtrace.
It may be useful to identify the source of the queries by looking at the call backtrace.
...
...
doc/development/testing_guide/testing_levels.md
View file @
3b7df66e
...
@@ -63,7 +63,7 @@ They're useful to test permissions, redirections, what view is rendered etc.
...
@@ -63,7 +63,7 @@ They're useful to test permissions, redirections, what view is rendered etc.
| Code path | Tests path | Testing engine | Notes |
| Code path | Tests path | Testing engine | Notes |
| --------- | ---------- | -------------- | ----- |
| --------- | ---------- | -------------- | ----- |
|
`app/controllers/`
|
`spec/controllers/`
| RSpec | |
|
`app/controllers/`
|
`spec/controllers/`
| RSpec |
For N+1 tests, use
[
request specs
](
../query_recorder.md#use-request-specs-instead-of-controller-specs
)
|
|
`app/mailers/`
|
`spec/mailers/`
| RSpec | |
|
`app/mailers/`
|
`spec/mailers/`
| RSpec | |
|
`lib/api/`
|
`spec/requests/api/`
| RSpec | |
|
`lib/api/`
|
`spec/requests/api/`
| RSpec | |
|
`lib/ci/api/`
|
`spec/requests/ci/api/`
| RSpec | |
|
`lib/ci/api/`
|
`spec/requests/ci/api/`
| RSpec | |
...
...
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