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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
7c21abab
Commit
7c21abab
authored
Oct 06, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/gitlab@master
parent
b8331414
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
34 deletions
+56
-34
doc/development/testing_guide/best_practices.md
doc/development/testing_guide/best_practices.md
+22
-7
spec/policies/group_policy_spec.rb
spec/policies/group_policy_spec.rb
+25
-18
spec/spec_helper.rb
spec/spec_helper.rb
+1
-1
spec/support/shared_contexts/policies/group_policy_shared_context.rb
...t/shared_contexts/policies/group_policy_shared_context.rb
+8
-8
No files found.
doc/development/testing_guide/best_practices.md
View file @
7c21abab
...
@@ -202,15 +202,30 @@ so we need to set some guidelines for their use going forward:
...
@@ -202,15 +202,30 @@ so we need to set some guidelines for their use going forward:
order is required, otherwise
`let`
will suffice. Remember that
`let`
is lazy and won't
order is required, otherwise
`let`
will suffice. Remember that
`let`
is lazy and won't
be evaluated until it is referenced.
be evaluated until it is referenced.
### `let_it_be` variables
### Common test setup
In some cases there is no need to recreate the same object for tests
In some cases, there is no need to recreate the same object for tests
again for each example. For example, a project is needed to test issues
again for each example. For example, a project and a guest of that project
on the same project, one project will do for the entire file. This can
is needed to test issues on the same project, one project and user will do for the entire file.
be achieved by using
This can be achieved by using
[
`let_it_be`
](
https://test-prof.evilmartians.io/#/let_it_be
)
variables
[
`let_it_be`
](
https://test-prof.evilmartians.io/#/let_it_be
)
variables and the
[
`before_all`
](
https://test-prof.evilmartians.io/#/before_all
)
hook
from the
[
`test-prof` gem
](
https://rubygems.org/gems/test-prof
)
.
from the
[
`test-prof` gem
](
https://rubygems.org/gems/test-prof
)
.
```
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
before_all do
project.add_guest(user)
end
```
This will result in only one
`Project`
,
`User`
, and
`ProjectMember`
created for this context.
`let_it_be`
and
`before_all`
are also available within nested contexts. Cleanup after the context
is handled automatically using a transaction rollback.
Note that if you modify an object defined inside a
`let_it_be`
block,
Note that if you modify an object defined inside a
`let_it_be`
block,
then you will need to reload the object as needed, or specify the
`reload`
then you will need to reload the object as needed, or specify the
`reload`
option to reload for every example.
option to reload for every example.
...
...
spec/policies/group_policy_spec.rb
View file @
7c21abab
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
GroupPolicy
do
describe
GroupPolicy
do
include_context
'GroupPolicy context'
include_context
'GroupPolicy context'
context
'with no user'
do
context
'
public group
with no user'
do
let
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:current_user
)
{
nil
}
let
(
:current_user
)
{
nil
}
...
@@ -33,7 +33,6 @@ describe GroupPolicy do
...
@@ -33,7 +33,6 @@ describe GroupPolicy do
context
'with foreign user and public project'
do
context
'with foreign user and public project'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:current_user
)
{
create
(
:user
)
}
before
do
before
do
...
@@ -105,8 +104,8 @@ describe GroupPolicy do
...
@@ -105,8 +104,8 @@ describe GroupPolicy do
let
(
:current_user
)
{
maintainer
}
let
(
:current_user
)
{
maintainer
}
context
'with subgroup_creation level set to maintainer'
do
context
'with subgroup_creation level set to maintainer'
do
let
(
:group
)
do
before_all
do
create
(
:group
,
:private
,
subgroup_creation_level:
::
Gitlab
::
Access
::
MAINTAINER_SUBGROUP_ACCESS
)
group
.
update
(
subgroup_creation_level:
::
Gitlab
::
Access
::
MAINTAINER_SUBGROUP_ACCESS
)
end
end
it
'allows every maintainer permission plus creating subgroups'
do
it
'allows every maintainer permission plus creating subgroups'
do
...
@@ -164,11 +163,11 @@ describe GroupPolicy do
...
@@ -164,11 +163,11 @@ describe GroupPolicy do
end
end
describe
'private nested group use the highest access level from the group and inherited permissions'
do
describe
'private nested group use the highest access level from the group and inherited permissions'
do
let
(
:nested_group
)
do
let
_it_be
(
:nested_group
)
do
create
(
:group
,
:private
,
:owner_subgroup_creation_only
,
parent:
group
)
create
(
:group
,
:private
,
:owner_subgroup_creation_only
,
parent:
group
)
end
end
before
do
before
_all
do
nested_group
.
add_guest
(
guest
)
nested_group
.
add_guest
(
guest
)
nested_group
.
add_guest
(
reporter
)
nested_group
.
add_guest
(
reporter
)
nested_group
.
add_guest
(
developer
)
nested_group
.
add_guest
(
developer
)
...
@@ -268,6 +267,10 @@ describe GroupPolicy do
...
@@ -268,6 +267,10 @@ describe GroupPolicy do
context
'when the group share_with_group_lock is enabled'
do
context
'when the group share_with_group_lock is enabled'
do
let
(
:group
)
{
create
(
:group
,
share_with_group_lock:
true
,
parent:
parent
)
}
let
(
:group
)
{
create
(
:group
,
share_with_group_lock:
true
,
parent:
parent
)
}
before
do
group
.
add_owner
(
owner
)
end
context
'when the parent group share_with_group_lock is enabled'
do
context
'when the parent group share_with_group_lock is enabled'
do
context
'when the group has a grandparent'
do
context
'when the group has a grandparent'
do
let
(
:parent
)
{
create
(
:group
,
share_with_group_lock:
true
,
parent:
grandparent
)
}
let
(
:parent
)
{
create
(
:group
,
share_with_group_lock:
true
,
parent:
grandparent
)
}
...
@@ -353,7 +356,9 @@ describe GroupPolicy do
...
@@ -353,7 +356,9 @@ describe GroupPolicy do
context
"create_projects"
do
context
"create_projects"
do
context
'when group has no project creation level set'
do
context
'when group has no project creation level set'
do
let
(
:group
)
{
create
(
:group
,
project_creation_level:
nil
)
}
before_all
do
group
.
update
(
project_creation_level:
nil
)
end
context
'reporter'
do
context
'reporter'
do
let
(
:current_user
)
{
reporter
}
let
(
:current_user
)
{
reporter
}
...
@@ -381,7 +386,9 @@ describe GroupPolicy do
...
@@ -381,7 +386,9 @@ describe GroupPolicy do
end
end
context
'when group has project creation level set to no one'
do
context
'when group has project creation level set to no one'
do
let
(
:group
)
{
create
(
:group
,
project_creation_level:
::
Gitlab
::
Access
::
NO_ONE_PROJECT_ACCESS
)
}
before_all
do
group
.
update
(
project_creation_level:
::
Gitlab
::
Access
::
NO_ONE_PROJECT_ACCESS
)
end
context
'reporter'
do
context
'reporter'
do
let
(
:current_user
)
{
reporter
}
let
(
:current_user
)
{
reporter
}
...
@@ -409,7 +416,9 @@ describe GroupPolicy do
...
@@ -409,7 +416,9 @@ describe GroupPolicy do
end
end
context
'when group has project creation level set to maintainer only'
do
context
'when group has project creation level set to maintainer only'
do
let
(
:group
)
{
create
(
:group
,
project_creation_level:
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
)
}
before_all
do
group
.
update
(
project_creation_level:
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
)
end
context
'reporter'
do
context
'reporter'
do
let
(
:current_user
)
{
reporter
}
let
(
:current_user
)
{
reporter
}
...
@@ -437,7 +446,9 @@ describe GroupPolicy do
...
@@ -437,7 +446,9 @@ describe GroupPolicy do
end
end
context
'when group has project creation level set to developers + maintainer'
do
context
'when group has project creation level set to developers + maintainer'
do
let
(
:group
)
{
create
(
:group
,
project_creation_level:
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
)
}
before_all
do
group
.
update
(
project_creation_level:
::
Gitlab
::
Access
::
DEVELOPER_MAINTAINER_PROJECT_ACCESS
)
end
context
'reporter'
do
context
'reporter'
do
let
(
:current_user
)
{
reporter
}
let
(
:current_user
)
{
reporter
}
...
@@ -467,10 +478,8 @@ describe GroupPolicy do
...
@@ -467,10 +478,8 @@ describe GroupPolicy do
context
"create_subgroup"
do
context
"create_subgroup"
do
context
'when group has subgroup creation level set to owner'
do
context
'when group has subgroup creation level set to owner'
do
let
(
:group
)
do
before_all
do
create
(
group
.
update
(
subgroup_creation_level:
::
Gitlab
::
Access
::
OWNER_SUBGROUP_ACCESS
)
:group
,
subgroup_creation_level:
::
Gitlab
::
Access
::
OWNER_SUBGROUP_ACCESS
)
end
end
context
'reporter'
do
context
'reporter'
do
...
@@ -499,10 +508,8 @@ describe GroupPolicy do
...
@@ -499,10 +508,8 @@ describe GroupPolicy do
end
end
context
'when group has subgroup creation level set to maintainer'
do
context
'when group has subgroup creation level set to maintainer'
do
let
(
:group
)
do
before_all
do
create
(
group
.
update
(
subgroup_creation_level:
::
Gitlab
::
Access
::
MAINTAINER_SUBGROUP_ACCESS
)
:group
,
subgroup_creation_level:
::
Gitlab
::
Access
::
MAINTAINER_SUBGROUP_ACCESS
)
end
end
context
'reporter'
do
context
'reporter'
do
...
...
spec/spec_helper.rb
View file @
7c21abab
...
@@ -10,7 +10,7 @@ require 'rspec/rails'
...
@@ -10,7 +10,7 @@ require 'rspec/rails'
require
'shoulda/matchers'
require
'shoulda/matchers'
require
'rspec/retry'
require
'rspec/retry'
require
'rspec-parameterized'
require
'rspec-parameterized'
require
"test_prof/recipes/rspec/let_it_be"
require
'test_prof/recipes/rspec/let_it_be'
rspec_profiling_is_configured
=
rspec_profiling_is_configured
=
ENV
[
'RSPEC_PROFILING_POSTGRES_URL'
].
present?
||
ENV
[
'RSPEC_PROFILING_POSTGRES_URL'
].
present?
||
...
...
spec/support/shared_contexts/policies/group_policy_shared_context.rb
View file @
7c21abab
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_context
'GroupPolicy context'
do
RSpec
.
shared_context
'GroupPolicy context'
do
let
(
:guest
)
{
create
(
:user
)
}
let
_it_be
(
:guest
)
{
create
(
:user
)
}
let
(
:reporter
)
{
create
(
:user
)
}
let
_it_be
(
:reporter
)
{
create
(
:user
)
}
let
(
:developer
)
{
create
(
:user
)
}
let
_it_be
(
:developer
)
{
create
(
:user
)
}
let
(
:maintainer
)
{
create
(
:user
)
}
let
_it_be
(
:maintainer
)
{
create
(
:user
)
}
let
(
:owner
)
{
create
(
:user
)
}
let
_it_be
(
:owner
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
_it_be
(
:admin
)
{
create
(
:admin
)
}
let
(
:group
)
{
create
(
:group
,
:private
,
:owner_subgroup_creation_only
)
}
let
_it_be
(
:group
,
refind:
true
)
{
create
(
:group
,
:private
,
:owner_subgroup_creation_only
)
}
let
(
:guest_permissions
)
do
let
(
:guest_permissions
)
do
%i[
%i[
...
@@ -37,7 +37,7 @@ RSpec.shared_context 'GroupPolicy context' do
...
@@ -37,7 +37,7 @@ RSpec.shared_context 'GroupPolicy context' do
].
compact
].
compact
end
end
before
do
before
_all
do
group
.
add_guest
(
guest
)
group
.
add_guest
(
guest
)
group
.
add_reporter
(
reporter
)
group
.
add_reporter
(
reporter
)
group
.
add_developer
(
developer
)
group
.
add_developer
(
developer
)
...
...
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