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
Jérome Perrin
gitlab-ce
Commits
1502d564
Commit
1502d564
authored
Jan 19, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert most User model specs to use `:empty_project`
parent
d9f53a35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
45 deletions
+39
-45
spec/models/user_spec.rb
spec/models/user_spec.rb
+39
-45
No files found.
spec/models/user_spec.rb
View file @
1502d564
...
@@ -48,7 +48,7 @@ describe User, models: true do
...
@@ -48,7 +48,7 @@ describe User, models: true do
describe
'#project_members'
do
describe
'#project_members'
do
it
'does not include project memberships for which user is a requester'
do
it
'does not include project memberships for which user is a requester'
do
user
=
create
(
:user
)
user
=
create
(
:user
)
project
=
create
(
:project
,
:public
,
:access_requestable
)
project
=
create
(
:
empty_
project
,
:public
,
:access_requestable
)
project
.
request_access
(
user
)
project
.
request_access
(
user
)
expect
(
user
.
project_members
).
to
be_empty
expect
(
user
.
project_members
).
to
be_empty
...
@@ -386,13 +386,15 @@ describe User, models: true do
...
@@ -386,13 +386,15 @@ describe User, models: true do
describe
'projects'
do
describe
'projects'
do
before
do
before
do
@user
=
create
:user
@user
=
create
(
:user
)
@project
=
create
:project
,
namespace:
@user
.
namespace
@project_2
=
create
:project
,
group:
create
(
:group
)
# Grant MASTER access to the user
@project_3
=
create
:project
,
group:
create
(
:group
)
# Grant DEVELOPER access to the user
@project_2
.
team
<<
[
@user
,
:master
]
@project
=
create
(
:empty_project
,
namespace:
@user
.
namespace
)
@project_3
.
team
<<
[
@user
,
:developer
]
@project_2
=
create
(
:empty_project
,
group:
create
(
:group
))
do
|
project
|
project
.
add_master
(
@user
)
end
@project_3
=
create
(
:empty_project
,
group:
create
(
:group
))
do
|
project
|
project
.
add_developer
(
@user
)
end
end
end
it
{
expect
(
@user
.
authorized_projects
).
to
include
(
@project
)
}
it
{
expect
(
@user
.
authorized_projects
).
to
include
(
@project
)
}
...
@@ -435,7 +437,7 @@ describe User, models: true do
...
@@ -435,7 +437,7 @@ describe User, models: true do
describe
'namespaced'
do
describe
'namespaced'
do
before
do
before
do
@user
=
create
:user
@user
=
create
:user
@project
=
create
:project
,
namespace:
@user
.
namespace
@project
=
create
(
:empty_project
,
namespace:
@user
.
namespace
)
end
end
it
{
expect
(
@user
.
several_namespaces?
).
to
be_falsey
}
it
{
expect
(
@user
.
several_namespaces?
).
to
be_falsey
}
...
@@ -517,7 +519,7 @@ describe User, models: true do
...
@@ -517,7 +519,7 @@ describe User, models: true do
before
do
before
do
User
.
delete_all
User
.
delete_all
@user
=
create
:user
@user
=
create
:user
@project
=
create
:project
@project
=
create
(
:empty_project
)
end
end
it
{
expect
(
User
.
not_in_project
(
@project
)).
to
include
(
@user
,
@project
.
owner
)
}
it
{
expect
(
User
.
not_in_project
(
@project
)).
to
include
(
@user
,
@project
.
owner
)
}
...
@@ -927,8 +929,8 @@ describe User, models: true do
...
@@ -927,8 +929,8 @@ describe User, models: true do
describe
"#starred?"
do
describe
"#starred?"
do
it
"determines if user starred a project"
do
it
"determines if user starred a project"
do
user
=
create
:user
user
=
create
:user
project1
=
create
:project
,
:public
project1
=
create
(
:empty_project
,
:public
)
project2
=
create
:project
,
:public
project2
=
create
(
:empty_project
,
:public
)
expect
(
user
.
starred?
(
project1
)).
to
be_falsey
expect
(
user
.
starred?
(
project1
)).
to
be_falsey
expect
(
user
.
starred?
(
project2
)).
to
be_falsey
expect
(
user
.
starred?
(
project2
)).
to
be_falsey
...
@@ -954,7 +956,7 @@ describe User, models: true do
...
@@ -954,7 +956,7 @@ describe User, models: true do
describe
"#toggle_star"
do
describe
"#toggle_star"
do
it
"toggles stars"
do
it
"toggles stars"
do
user
=
create
:user
user
=
create
:user
project
=
create
:project
,
:public
project
=
create
(
:empty_project
,
:public
)
expect
(
user
.
starred?
(
project
)).
to
be_falsey
expect
(
user
.
starred?
(
project
)).
to
be_falsey
user
.
toggle_star
(
project
)
user
.
toggle_star
(
project
)
...
@@ -994,9 +996,9 @@ describe User, models: true do
...
@@ -994,9 +996,9 @@ describe User, models: true do
describe
"#contributed_projects"
do
describe
"#contributed_projects"
do
subject
{
create
(
:user
)
}
subject
{
create
(
:user
)
}
let!
(
:project1
)
{
create
(
:project
)
}
let!
(
:project1
)
{
create
(
:
empty_
project
)
}
let!
(
:project2
)
{
create
(
:project
,
forked_from_project:
project3
)
}
let!
(
:project2
)
{
create
(
:
empty_
project
,
forked_from_project:
project3
)
}
let!
(
:project3
)
{
create
(
:project
)
}
let!
(
:project3
)
{
create
(
:
empty_
project
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project2
,
target_project:
project3
,
author:
subject
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project2
,
target_project:
project3
,
author:
subject
)
}
let!
(
:push_event
)
{
create
(
:event
,
action:
Event
::
PUSHED
,
project:
project1
,
target:
project1
,
author:
subject
)
}
let!
(
:push_event
)
{
create
(
:event
,
action:
Event
::
PUSHED
,
project:
project1
,
target:
project1
,
author:
subject
)
}
let!
(
:merge_event
)
{
create
(
:event
,
action:
Event
::
CREATED
,
project:
project3
,
target:
merge_request
,
author:
subject
)
}
let!
(
:merge_event
)
{
create
(
:event
,
action:
Event
::
CREATED
,
project:
project3
,
target:
merge_request
,
author:
subject
)
}
...
@@ -1038,8 +1040,8 @@ describe User, models: true do
...
@@ -1038,8 +1040,8 @@ describe User, models: true do
describe
"#recent_push"
do
describe
"#recent_push"
do
subject
{
create
(
:user
)
}
subject
{
create
(
:user
)
}
let!
(
:project1
)
{
create
(
:project
)
}
let!
(
:project1
)
{
create
(
:project
,
:repository
)
}
let!
(
:project2
)
{
create
(
:project
,
forked_from_project:
project1
)
}
let!
(
:project2
)
{
create
(
:project
,
:repository
,
forked_from_project:
project1
)
}
let!
(
:push_data
)
do
let!
(
:push_data
)
do
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project2
,
subject
)
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project2
,
subject
)
end
end
...
@@ -1113,7 +1115,7 @@ describe User, models: true do
...
@@ -1113,7 +1115,7 @@ describe User, models: true do
it
"includes user's personal projects"
do
it
"includes user's personal projects"
do
user
=
create
(
:user
)
user
=
create
(
:user
)
project
=
create
(
:project
,
:private
,
namespace:
user
.
namespace
)
project
=
create
(
:
empty_
project
,
:private
,
namespace:
user
.
namespace
)
expect
(
user
.
authorized_projects
).
to
include
(
project
)
expect
(
user
.
authorized_projects
).
to
include
(
project
)
end
end
...
@@ -1121,7 +1123,7 @@ describe User, models: true do
...
@@ -1121,7 +1123,7 @@ describe User, models: true do
it
"includes personal projects user has been given access to"
do
it
"includes personal projects user has been given access to"
do
user1
=
create
(
:user
)
user1
=
create
(
:user
)
user2
=
create
(
:user
)
user2
=
create
(
:user
)
project
=
create
(
:project
,
:private
,
namespace:
user1
.
namespace
)
project
=
create
(
:
empty_
project
,
:private
,
namespace:
user1
.
namespace
)
project
.
team
<<
[
user2
,
Gitlab
::
Access
::
DEVELOPER
]
project
.
team
<<
[
user2
,
Gitlab
::
Access
::
DEVELOPER
]
...
@@ -1130,7 +1132,7 @@ describe User, models: true do
...
@@ -1130,7 +1132,7 @@ describe User, models: true do
it
"includes projects of groups user has been added to"
do
it
"includes projects of groups user has been added to"
do
group
=
create
(
:group
)
group
=
create
(
:group
)
project
=
create
(
:project
,
group:
group
)
project
=
create
(
:
empty_
project
,
group:
group
)
user
=
create
(
:user
)
user
=
create
(
:user
)
group
.
add_developer
(
user
)
group
.
add_developer
(
user
)
...
@@ -1140,7 +1142,7 @@ describe User, models: true do
...
@@ -1140,7 +1142,7 @@ describe User, models: true do
it
"does not include projects of groups user has been removed from"
do
it
"does not include projects of groups user has been removed from"
do
group
=
create
(
:group
)
group
=
create
(
:group
)
project
=
create
(
:project
,
group:
group
)
project
=
create
(
:
empty_
project
,
group:
group
)
user
=
create
(
:user
)
user
=
create
(
:user
)
member
=
group
.
add_developer
(
user
)
member
=
group
.
add_developer
(
user
)
...
@@ -1152,7 +1154,7 @@ describe User, models: true do
...
@@ -1152,7 +1154,7 @@ describe User, models: true do
it
"includes projects shared with user's group"
do
it
"includes projects shared with user's group"
do
user
=
create
(
:user
)
user
=
create
(
:user
)
project
=
create
(
:project
,
:private
)
project
=
create
(
:
empty_
project
,
:private
)
group
=
create
(
:group
)
group
=
create
(
:group
)
group
.
add_reporter
(
user
)
group
.
add_reporter
(
user
)
...
@@ -1164,7 +1166,7 @@ describe User, models: true do
...
@@ -1164,7 +1166,7 @@ describe User, models: true do
it
"does not include destroyed projects user had access to"
do
it
"does not include destroyed projects user had access to"
do
user1
=
create
(
:user
)
user1
=
create
(
:user
)
user2
=
create
(
:user
)
user2
=
create
(
:user
)
project
=
create
(
:project
,
:private
,
namespace:
user1
.
namespace
)
project
=
create
(
:
empty_
project
,
:private
,
namespace:
user1
.
namespace
)
project
.
team
<<
[
user2
,
Gitlab
::
Access
::
DEVELOPER
]
project
.
team
<<
[
user2
,
Gitlab
::
Access
::
DEVELOPER
]
expect
(
user2
.
authorized_projects
).
to
include
(
project
)
expect
(
user2
.
authorized_projects
).
to
include
(
project
)
...
@@ -1175,7 +1177,7 @@ describe User, models: true do
...
@@ -1175,7 +1177,7 @@ describe User, models: true do
it
"does not include projects of destroyed groups user had access to"
do
it
"does not include projects of destroyed groups user had access to"
do
group
=
create
(
:group
)
group
=
create
(
:group
)
project
=
create
(
:project
,
namespace:
group
)
project
=
create
(
:
empty_
project
,
namespace:
group
)
user
=
create
(
:user
)
user
=
create
(
:user
)
group
.
add_developer
(
user
)
group
.
add_developer
(
user
)
...
@@ -1190,14 +1192,9 @@ describe User, models: true do
...
@@ -1190,14 +1192,9 @@ describe User, models: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
it
'includes projects for which the user access level is above or equal to reporter'
do
it
'includes projects for which the user access level is above or equal to reporter'
do
create
(
:project
)
reporter_project
=
create
(
:empty_project
)
{
|
p
|
p
.
add_reporter
(
user
)
}
reporter_project
=
create
(
:project
)
developer_project
=
create
(
:empty_project
)
{
|
p
|
p
.
add_developer
(
user
)
}
developer_project
=
create
(
:project
)
master_project
=
create
(
:empty_project
)
{
|
p
|
p
.
add_master
(
user
)
}
master_project
=
create
(
:project
)
reporter_project
.
team
<<
[
user
,
:reporter
]
developer_project
.
team
<<
[
user
,
:developer
]
master_project
.
team
<<
[
user
,
:master
]
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
eq
([
master_project
,
developer_project
,
reporter_project
])
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
eq
([
master_project
,
developer_project
,
reporter_project
])
expect
(
user
.
can?
(
:admin_issue
,
master_project
)).
to
eq
(
true
)
expect
(
user
.
can?
(
:admin_issue
,
master_project
)).
to
eq
(
true
)
...
@@ -1206,10 +1203,8 @@ describe User, models: true do
...
@@ -1206,10 +1203,8 @@ describe User, models: true do
end
end
it
'does not include for which the user access level is below reporter'
do
it
'does not include for which the user access level is below reporter'
do
project
=
create
(
:project
)
project
=
create
(
:empty_project
)
guest_project
=
create
(
:project
)
guest_project
=
create
(
:empty_project
)
{
|
p
|
p
.
add_guest
(
user
)
}
guest_project
.
team
<<
[
user
,
:guest
]
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
be_empty
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
be_empty
expect
(
user
.
can?
(
:admin_issue
,
guest_project
)).
to
eq
(
false
)
expect
(
user
.
can?
(
:admin_issue
,
guest_project
)).
to
eq
(
false
)
...
@@ -1217,15 +1212,14 @@ describe User, models: true do
...
@@ -1217,15 +1212,14 @@ describe User, models: true do
end
end
it
'does not include archived projects'
do
it
'does not include archived projects'
do
project
=
create
(
:project
)
project
=
create
(
:empty_project
,
:archived
)
project
.
update_attributes
(
archived:
true
)
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
be_empty
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
be_empty
expect
(
user
.
can?
(
:admin_issue
,
project
)).
to
eq
(
false
)
expect
(
user
.
can?
(
:admin_issue
,
project
)).
to
eq
(
false
)
end
end
it
'does not include projects for which issues are disabled'
do
it
'does not include projects for which issues are disabled'
do
project
=
create
(
:project
,
issues_access_level:
ProjectFeature
::
DISABLED
)
project
=
create
(
:
empty_
project
,
issues_access_level:
ProjectFeature
::
DISABLED
)
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
be_empty
expect
(
user
.
projects_where_can_admin_issues
.
to_a
).
to
be_empty
expect
(
user
.
can?
(
:admin_issue
,
project
)).
to
eq
(
false
)
expect
(
user
.
can?
(
:admin_issue
,
project
)).
to
eq
(
false
)
...
@@ -1241,7 +1235,7 @@ describe User, models: true do
...
@@ -1241,7 +1235,7 @@ describe User, models: true do
end
end
context
'without any projects'
do
context
'without any projects'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:
empty_
project
)
}
it
'does not load'
do
it
'does not load'
do
expect
(
user
.
ci_authorized_runners
).
to
be_empty
expect
(
user
.
ci_authorized_runners
).
to
be_empty
...
@@ -1250,7 +1244,7 @@ describe User, models: true do
...
@@ -1250,7 +1244,7 @@ describe User, models: true do
context
'with personal projects runners'
do
context
'with personal projects runners'
do
let
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let
(
:namespace
)
{
create
(
:namespace
,
owner:
user
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
)
}
let
(
:project
)
{
create
(
:
empty_
project
,
namespace:
namespace
)
}
it
'loads'
do
it
'loads'
do
expect
(
user
.
ci_authorized_runners
).
to
contain_exactly
(
runner
)
expect
(
user
.
ci_authorized_runners
).
to
contain_exactly
(
runner
)
...
@@ -1281,7 +1275,7 @@ describe User, models: true do
...
@@ -1281,7 +1275,7 @@ describe User, models: true do
context
'with groups projects runners'
do
context
'with groups projects runners'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:project
)
{
create
(
:
empty_
project
,
group:
group
)
}
def
add_user
(
access
)
def
add_user
(
access
)
group
.
add_user
(
user
,
access
)
group
.
add_user
(
user
,
access
)
...
@@ -1291,7 +1285,7 @@ describe User, models: true do
...
@@ -1291,7 +1285,7 @@ describe User, models: true do
end
end
context
'with other projects runners'
do
context
'with other projects runners'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:
empty_
project
)
}
def
add_user
(
access
)
def
add_user
(
access
)
project
.
team
<<
[
user
,
access
]
project
.
team
<<
[
user
,
access
]
...
@@ -1321,8 +1315,8 @@ describe User, models: true do
...
@@ -1321,8 +1315,8 @@ describe User, models: true do
end
end
describe
'#projects_with_reporter_access_limited_to'
do
describe
'#projects_with_reporter_access_limited_to'
do
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project1
)
{
create
(
:
empty_
project
)
}
let
(
:project2
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:
empty_
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
before
do
...
...
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