diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-08-20 11:35:21 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-08-20 11:35:21 +0000 |
commit | 9e6a8bb93b6fbcbe5657079108332b99fc8749cc (patch) | |
tree | 07997c44727459b3c096e110cdd8937f3a363ea0 | |
parent | c44614dc47ae7d277531e4bdbc24b3a550dae1ad (diff) | |
parent | 3b7df66eef935046363c39d835b0a34d85b51584 (diff) | |
download | gitlab-ce-9e6a8bb93b6fbcbe5657079108332b99fc8749cc.tar.gz |
Merge branch 'docs-testing-n-1-request-sepcs' into 'master'
Docs: Require request specs when testing N+1 for controllers
See merge request gitlab-org/gitlab-ce!31940
-rw-r--r-- | doc/development/query_recorder.md | 7 | ||||
-rw-r--r-- | doc/development/testing_guide/testing_levels.md | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/doc/development/query_recorder.md b/doc/development/query_recorder.md index a6b60149ea4..3787e2ef187 100644 --- a/doc/development/query_recorder.md +++ b/doc/development/query_recorder.md @@ -36,6 +36,13 @@ it "avoids N+1 database queries" do 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 It may be useful to identify the source of the queries by looking at the call backtrace. diff --git a/doc/development/testing_guide/testing_levels.md b/doc/development/testing_guide/testing_levels.md index 6c3a3171d39..0090c84cbf0 100644 --- a/doc/development/testing_guide/testing_levels.md +++ b/doc/development/testing_guide/testing_levels.md @@ -63,7 +63,7 @@ They're useful to test permissions, redirections, what view is rendered etc. | 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 | | | `lib/api/` | `spec/requests/api/` | RSpec | | | `app/assets/javascripts/` | `spec/javascripts/`, `spec/frontend/` | Karma & Jest | More details in the [Frontend Testing guide](frontend_testing.md) section. | |