diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-14 12:08:53 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-14 12:08:53 +0000 |
| commit | 8a5138ed7d38ccff8b5ca2fe0f7bbb77f8fdaad3 (patch) | |
| tree | 4c0d373c990fc01cacff9b4093366ab398fcb7d3 /doc/development/testing_guide | |
| parent | 6d8f30ab0ae82678f10450d2158f24772f0c765c (diff) | |
| download | gitlab-ce-8a5138ed7d38ccff8b5ca2fe0f7bbb77f8fdaad3.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/testing_guide')
| -rw-r--r-- | doc/development/testing_guide/best_practices.md | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index cd4dc6b21e4..2af9d12a251 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -315,6 +315,27 @@ NOTE: WARNING: `stub_method` is supposed to be used in factories only. It's strongly discouraged to be used elsewhere. Please consider using [RSpec mocks](https://rspec.info/features/3-12/rspec-mocks/) if available. +#### Stubbing member access level + +To stub [member access level](../../user/permissions.md#roles) for factory stubs like `Project` or `Group` use +[`stub_member_access_level`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/support/stub_member_access_level.rb): + +```ruby +let(:project) { build_stubbed(:project) } +let(:maintainer) { build_stubbed(:user) } +let(:policy) { ProjectPolicy.new(maintainer, project) } + +it 'allows admin_project ability' do + stub_member_access_level(project, maintainer: maintainer) + + expect(policy).to be_allowed(:admin_project) +end +``` + +NOTE: +Refrain from using this stub helper if the test code relies on persisting +`project_authorizations` or `Member` records. Use `Project#add_member` or `Group#add_member` instead. + #### Identify slow tests Running a spec with profiling is a good way to start optimizing a spec. This can |
