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
9ee5229b
Commit
9ee5229b
authored
Mar 26, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EE] Reduce the diff with CE in spec/policies/project_snippet_policy_spec.rb
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
d8a5e326
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
71 deletions
+88
-71
ee/spec/policies/project_snippet_policy_spec.rb
ee/spec/policies/project_snippet_policy_spec.rb
+38
-0
spec/policies/project_snippet_policy_spec.rb
spec/policies/project_snippet_policy_spec.rb
+50
-71
No files found.
ee/spec/policies/project_snippet_policy_spec.rb
0 → 100644
View file @
9ee5229b
# frozen_string_literal: true
require
'spec_helper'
# Snippet visibility scenarios are included in more details in spec/support/snippet_visibility.rb
describe
ProjectSnippetPolicy
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
snippet_visibility
,
project:
project
)
}
let
(
:author_permissions
)
do
[
:update_project_snippet
,
:admin_project_snippet
]
end
subject
{
described_class
.
new
(
current_user
,
snippet
)
}
def
expect_allowed
(
*
permissions
)
permissions
.
each
{
|
p
|
is_expected
.
to
be_allowed
(
p
)
}
end
def
expect_disallowed
(
*
permissions
)
permissions
.
each
{
|
p
|
is_expected
.
not_to
be_allowed
(
p
)
}
end
context
'private snippet'
do
let
(
:snippet_visibility
)
{
:private
}
context
'auditor user'
do
let
(
:current_user
)
{
create
(
:user
,
:auditor
)
}
it
do
is_expected
.
to
be_allowed
(
:read_project_snippet
)
is_expected
.
to
be_disallowed
(
*
author_permissions
)
end
end
end
end
spec/policies/project_snippet_policy_spec.rb
View file @
9ee5229b
...
@@ -5,7 +5,7 @@ describe ProjectSnippetPolicy do
...
@@ -5,7 +5,7 @@ describe ProjectSnippetPolicy do
let
(
:regular_user
)
{
create
(
:user
)
}
let
(
:regular_user
)
{
create
(
:user
)
}
let
(
:external_user
)
{
create
(
:user
,
:external
)
}
let
(
:external_user
)
{
create
(
:user
,
:external
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
snippet_visibility
,
project:
project
)
}
let
(
:author_permissions
)
do
let
(
:author_permissions
)
do
[
[
:update_project_snippet
,
:update_project_snippet
,
...
@@ -13,11 +13,7 @@ describe ProjectSnippetPolicy do
...
@@ -13,11 +13,7 @@ describe ProjectSnippetPolicy do
]
]
end
end
def
abilities
(
user
,
snippet_visibility
)
subject
{
described_class
.
new
(
current_user
,
snippet
)
}
snippet
=
create
(
:project_snippet
,
snippet_visibility
,
project:
project
)
described_class
.
new
(
user
,
snippet
)
end
def
expect_allowed
(
*
permissions
)
def
expect_allowed
(
*
permissions
)
permissions
.
each
{
|
p
|
is_expected
.
to
be_allowed
(
p
)
}
permissions
.
each
{
|
p
|
is_expected
.
to
be_allowed
(
p
)
}
...
@@ -28,8 +24,10 @@ describe ProjectSnippetPolicy do
...
@@ -28,8 +24,10 @@ describe ProjectSnippetPolicy do
end
end
context
'public snippet'
do
context
'public snippet'
do
let
(
:snippet_visibility
)
{
:public
}
context
'no user'
do
context
'no user'
do
subject
{
abilities
(
nil
,
:public
)
}
let
(
:current_user
)
{
nil
}
it
do
it
do
expect_allowed
(
:read_project_snippet
)
expect_allowed
(
:read_project_snippet
)
...
@@ -38,7 +36,7 @@ describe ProjectSnippetPolicy do
...
@@ -38,7 +36,7 @@ describe ProjectSnippetPolicy do
end
end
context
'regular user'
do
context
'regular user'
do
subject
{
abilities
(
regular_user
,
:public
)
}
let
(
:current_user
)
{
regular_user
}
it
do
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
...
@@ -47,7 +45,7 @@ describe ProjectSnippetPolicy do
...
@@ -47,7 +45,7 @@ describe ProjectSnippetPolicy do
end
end
context
'external user'
do
context
'external user'
do
subject
{
abilities
(
external_user
,
:public
)
}
let
(
:current_user
)
{
external_user
}
it
do
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
...
@@ -57,8 +55,10 @@ describe ProjectSnippetPolicy do
...
@@ -57,8 +55,10 @@ describe ProjectSnippetPolicy do
end
end
context
'internal snippet'
do
context
'internal snippet'
do
let
(
:snippet_visibility
)
{
:internal
}
context
'no user'
do
context
'no user'
do
subject
{
abilities
(
nil
,
:internal
)
}
let
(
:current_user
)
{
nil
}
it
do
it
do
expect_disallowed
(
:read_project_snippet
)
expect_disallowed
(
:read_project_snippet
)
...
@@ -67,7 +67,7 @@ describe ProjectSnippetPolicy do
...
@@ -67,7 +67,7 @@ describe ProjectSnippetPolicy do
end
end
context
'regular user'
do
context
'regular user'
do
subject
{
abilities
(
regular_user
,
:internal
)
}
let
(
:current_user
)
{
regular_user
}
it
do
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
...
@@ -76,41 +76,31 @@ describe ProjectSnippetPolicy do
...
@@ -76,41 +76,31 @@ describe ProjectSnippetPolicy do
end
end
context
'external user'
do
context
'external user'
do
subject
{
abilities
(
external_user
,
:internal
)
}
let
(
:current_user
)
{
external_user
}
it
do
it
do
expect_disallowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
*
author_permissions
)
expect_disallowed
(
*
author_permissions
)
end
end
end
context
'project team member external user'
do
subject
{
abilities
(
external_user
,
:internal
)
}
before
do
project
.
add_developer
(
external_user
)
end
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
*
author_permissions
)
end
end
context
'external user'
do
context
'project team member'
do
let
(
:current_user
)
{
create
(
:user
,
:external
)
}
before
do
subject
{
abilities
(
current_user
,
:private
)
}
project
.
add_developer
(
external_user
)
end
it
do
it
do
is_expected
.
to
be_disallowed
(
:read_project_snippet
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
is_expected
.
to
be_disallowed
(
*
author_permissions
)
expect_disallowed
(
*
author_permissions
)
end
end
end
end
end
end
end
context
'private snippet'
do
context
'private snippet'
do
let
(
:snippet_visibility
)
{
:private
}
context
'no user'
do
context
'no user'
do
subject
{
abilities
(
nil
,
:private
)
}
let
(
:current_user
)
{
nil
}
it
do
it
do
expect_disallowed
(
:read_project_snippet
)
expect_disallowed
(
:read_project_snippet
)
...
@@ -119,63 +109,52 @@ describe ProjectSnippetPolicy do
...
@@ -119,63 +109,52 @@ describe ProjectSnippetPolicy do
end
end
context
'regular user'
do
context
'regular user'
do
subject
{
abilities
(
regular_user
,
:private
)
}
let
(
:current_user
)
{
regular_user
}
it
do
it
do
expect_disallowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
*
author_permissions
)
expect_disallowed
(
*
author_permissions
)
end
end
end
context
'snippet author'
do
let
(
:snippet
)
{
create
(
:project_snippet
,
:private
,
author:
regular_user
,
project:
project
)
}
subject
{
described_class
.
new
(
regular_user
,
snippet
)
}
context
'snippet author'
do
let
(
:snippet
)
{
create
(
:project_snippet
,
:private
,
author:
regular_user
,
project:
project
)
}
it
do
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
*
author_permissions
)
expect_allowed
(
*
author_permissions
)
end
end
end
end
context
'project team member normal user'
do
subject
{
abilities
(
regular_user
,
:private
)
}
before
do
context
'project team member normal user'
do
project
.
add_developer
(
regular_user
)
before
do
end
project
.
add_developer
(
regular_user
)
end
it
do
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
*
author_permissions
)
expect_disallowed
(
*
author_permissions
)
end
end
end
end
end
context
'project team member external user'
do
context
'external user'
do
subject
{
abilities
(
external_user
,
:private
)
}
context
'project team member'
do
let
(
:current_user
)
{
external_user
}
before
do
project
.
add_developer
(
external_user
)
end
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_disallowed
(
*
author_permissions
)
end
end
context
'auditor user'
do
before
do
let
(
:current_user
)
{
create
(
:user
,
:auditor
)
}
project
.
add_developer
(
external_user
)
subject
{
abilities
(
current_user
,
:private
)
}
end
it
do
it
do
is_expected
.
to
be_allowed
(
:read_project_snippet
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
is_expected
.
to
be_disallowed
(
*
author_permissions
)
expect_disallowed
(
*
author_permissions
)
end
end
end
end
end
context
'admin user'
do
context
'admin user'
do
subject
{
abilities
(
create
(
:admin
),
:private
)
}
let
(
:snippet_visibility
)
{
:private
}
let
(
:current_user
)
{
create
(
:admin
)
}
it
do
it
do
expect_allowed
(
:read_project_snippet
,
:create_note
)
expect_allowed
(
:read_project_snippet
,
:create_note
)
...
...
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