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
42fdbbe3
Commit
42fdbbe3
authored
Sep 22, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor spec/policies/project_policy_spec.rb to minimize the diff with EE
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
9e46a897
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
47 deletions
+86
-47
spec/policies/project_policy_spec.rb
spec/policies/project_policy_spec.rb
+86
-47
No files found.
spec/policies/project_policy_spec.rb
View file @
42fdbbe3
require
'spec_helper'
require
'spec_helper'
describe
ProjectPolicy
do
describe
ProjectPolicy
do
l
et
(
:guest
)
{
create
(
:user
)
}
s
et
(
:guest
)
{
create
(
:user
)
}
l
et
(
:reporter
)
{
create
(
:user
)
}
s
et
(
:reporter
)
{
create
(
:user
)
}
let
(
:dev
)
{
create
(
:user
)
}
set
(
:developer
)
{
create
(
:user
)
}
l
et
(
:master
)
{
create
(
:user
)
}
s
et
(
:master
)
{
create
(
:user
)
}
l
et
(
:owner
)
{
create
(
:user
)
}
s
et
(
:owner
)
{
create
(
:user
)
}
l
et
(
:admin
)
{
create
(
:admin
)
}
s
et
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
owner
.
namespace
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
owner
.
namespace
)
}
let
(
:guest_permissions
)
do
let
(
:
base_
guest_permissions
)
do
%i[
%i[
read_project read_board read_list read_wiki read_issue read_label
read_project read_board read_list read_wiki read_issue read_label
read_milestone read_project_snippet read_project_member
read_milestone read_project_snippet read_project_member
...
@@ -18,7 +18,7 @@ describe ProjectPolicy do
...
@@ -18,7 +18,7 @@ describe ProjectPolicy do
]
]
end
end
let
(
:reporter_permissions
)
do
let
(
:
base_
reporter_permissions
)
do
%i[
%i[
download_code fork_project create_project_snippet update_issue
download_code fork_project create_project_snippet update_issue
admin_issue admin_label admin_list read_commit_status read_build
admin_issue admin_label admin_list read_commit_status read_build
...
@@ -41,7 +41,7 @@ describe ProjectPolicy do
...
@@ -41,7 +41,7 @@ describe ProjectPolicy do
]
]
end
end
let
(
:master_permissions
)
do
let
(
:
base_
master_permissions
)
do
%i[
%i[
delete_protected_branch update_project_snippet update_environment
delete_protected_branch update_project_snippet update_environment
update_deployment admin_project_snippet
update_deployment admin_project_snippet
...
@@ -66,11 +66,20 @@ describe ProjectPolicy do
...
@@ -66,11 +66,20 @@ describe ProjectPolicy do
]
]
end
end
# Used in EE specs
let
(
:additional_guest_permissions
)
{
[]
}
let
(
:additional_reporter_permissions
)
{
[]
}
let
(
:additional_master_permissions
)
{
[]
}
let
(
:guest_permissions
)
{
base_guest_permissions
+
additional_guest_permissions
}
let
(
:reporter_permissions
)
{
base_reporter_permissions
+
additional_reporter_permissions
}
let
(
:master_permissions
)
{
base_master_permissions
+
additional_master_permissions
}
before
do
before
do
project
.
team
<<
[
guest
,
:guest
]
project
.
add_guest
(
guest
)
project
.
team
<<
[
master
,
:master
]
project
.
add_master
(
master
)
project
.
team
<<
[
dev
,
:developer
]
project
.
add_developer
(
developer
)
project
.
team
<<
[
reporter
,
:reporter
]
project
.
add_reporter
(
reporter
)
end
end
def
expect_allowed
(
*
permissions
)
def
expect_allowed
(
*
permissions
)
...
@@ -127,38 +136,41 @@ describe ProjectPolicy do
...
@@ -127,38 +136,41 @@ describe ProjectPolicy do
end
end
end
end
context
'when a project has pending invites, and the current user is anonymous'
do
shared_examples
'project policies as anonymous'
do
let
(
:group
)
{
create
(
:group
,
:public
)
}
context
'abilities for public projects'
do
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
context
'when a project has pending invites'
do
let
(
:user_permissions
)
{
[
:create_project
,
:create_issue
,
:create_note
,
:upload_file
]
}
let
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:anonymous_permissions
)
{
guest_permissions
-
user_permissions
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let
(
:user_permissions
)
{
[
:create_project
,
:create_issue
,
:create_note
,
:upload_file
]
}
let
(
:anonymous_permissions
)
{
guest_permissions
-
user_permissions
}
subject
{
described_class
.
new
(
nil
,
project
)
}
subject
{
described_class
.
new
(
nil
,
project
)
}
before
do
before
do
create
(
:group_member
,
:invited
,
group:
group
)
create
(
:group_member
,
:invited
,
group:
group
)
end
end
it
'does not grant owner access'
do
it
'does not grant owner access'
do
expect_allowed
(
*
anonymous_permissions
)
expect_allowed
(
*
anonymous_permissions
)
expect_disallowed
(
*
user_permissions
)
expect_disallowed
(
*
user_permissions
)
end
end
end
end
end
context
'abilities for non-public projects'
do
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
subject
{
described_class
.
new
(
current_user
,
project
)
}
subject
{
described_class
.
new
(
nil
,
project
)
}
context
'with no user'
do
let
(
:current_user
)
{
nil
}
it
{
is_expected
.
to
be_banned
}
it
{
is_expected
.
to
be_banned
}
end
end
end
context
'guests
'
do
shared_examples
'project policies as guest
'
do
let
(
:current_user
)
{
guest
}
subject
{
described_class
.
new
(
guest
,
project
)
}
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
let
(
:reporter_public_build_permissions
)
do
let
(
:reporter_public_build_permissions
)
do
reporter_permissions
-
[
:read_build
,
:read_pipeline
]
reporter_permissions
-
[
:read_build
,
:read_pipeline
]
end
end
...
@@ -179,7 +191,7 @@ describe ProjectPolicy do
...
@@ -179,7 +191,7 @@ describe ProjectPolicy do
end
end
end
end
context
'public builds disabled'
do
context
'
when
public builds disabled'
do
before
do
before
do
project
.
update
(
public_builds:
false
)
project
.
update
(
public_builds:
false
)
end
end
...
@@ -192,8 +204,7 @@ describe ProjectPolicy do
...
@@ -192,8 +204,7 @@ describe ProjectPolicy do
context
'when builds are disabled'
do
context
'when builds are disabled'
do
before
do
before
do
project
.
project_feature
.
update
(
project
.
project_feature
.
update
(
builds_access_level:
ProjectFeature
::
DISABLED
)
builds_access_level:
ProjectFeature
::
DISABLED
)
end
end
it
do
it
do
...
@@ -202,9 +213,13 @@ describe ProjectPolicy do
...
@@ -202,9 +213,13 @@ describe ProjectPolicy do
end
end
end
end
end
end
end
shared_examples
'project policies as reporter'
do
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
context
'reporter'
do
subject
{
described_class
.
new
(
reporter
,
project
)
}
let
(
:current_user
)
{
reporter
}
it
do
it
do
expect_allowed
(
*
guest_permissions
)
expect_allowed
(
*
guest_permissions
)
...
@@ -216,9 +231,13 @@ describe ProjectPolicy do
...
@@ -216,9 +231,13 @@ describe ProjectPolicy do
expect_disallowed
(
*
owner_permissions
)
expect_disallowed
(
*
owner_permissions
)
end
end
end
end
end
context
'developer'
do
shared_examples
'project policies as developer'
do
let
(
:current_user
)
{
dev
}
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
subject
{
described_class
.
new
(
developer
,
project
)
}
it
do
it
do
expect_allowed
(
*
guest_permissions
)
expect_allowed
(
*
guest_permissions
)
...
@@ -229,9 +248,13 @@ describe ProjectPolicy do
...
@@ -229,9 +248,13 @@ describe ProjectPolicy do
expect_disallowed
(
*
owner_permissions
)
expect_disallowed
(
*
owner_permissions
)
end
end
end
end
end
shared_examples
'project policies as master'
do
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
context
'master'
do
subject
{
described_class
.
new
(
master
,
project
)
}
let
(
:current_user
)
{
master
}
it
do
it
do
expect_allowed
(
*
guest_permissions
)
expect_allowed
(
*
guest_permissions
)
...
@@ -242,9 +265,13 @@ describe ProjectPolicy do
...
@@ -242,9 +265,13 @@ describe ProjectPolicy do
expect_disallowed
(
*
owner_permissions
)
expect_disallowed
(
*
owner_permissions
)
end
end
end
end
end
shared_examples
'project policies as owner'
do
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
context
'owner'
do
subject
{
described_class
.
new
(
owner
,
project
)
}
let
(
:current_user
)
{
owner
}
it
do
it
do
expect_allowed
(
*
guest_permissions
)
expect_allowed
(
*
guest_permissions
)
...
@@ -255,9 +282,13 @@ describe ProjectPolicy do
...
@@ -255,9 +282,13 @@ describe ProjectPolicy do
expect_allowed
(
*
owner_permissions
)
expect_allowed
(
*
owner_permissions
)
end
end
end
end
end
context
'admin'
do
shared_examples
'project policies as admin'
do
let
(
:current_user
)
{
admin
}
context
'abilities for non-public projects'
do
let
(
:project
)
{
create
(
:project
,
namespace:
owner
.
namespace
)
}
subject
{
described_class
.
new
(
admin
,
project
)
}
it
do
it
do
expect_allowed
(
*
guest_permissions
)
expect_allowed
(
*
guest_permissions
)
...
@@ -269,4 +300,12 @@ describe ProjectPolicy do
...
@@ -269,4 +300,12 @@ describe ProjectPolicy do
end
end
end
end
end
end
it_behaves_like
'project policies as anonymous'
it_behaves_like
'project policies as guest'
it_behaves_like
'project policies as reporter'
it_behaves_like
'project policies as developer'
it_behaves_like
'project policies as master'
it_behaves_like
'project policies as owner'
it_behaves_like
'project policies as admin'
end
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