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
Tatuya Kamada
gitlab-ce
Commits
d431e433
Commit
d431e433
authored
Jan 02, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix few bugs and tests after refactoring ownership logic
parent
00a1f5bc
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
58 additions
and
61 deletions
+58
-61
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+2
-2
app/helpers/namespaces_helper.rb
app/helpers/namespaces_helper.rb
+1
-1
app/models/ability.rb
app/models/ability.rb
+2
-13
app/models/key.rb
app/models/key.rb
+1
-1
app/models/project.rb
app/models/project.rb
+1
-1
app/models/user.rb
app/models/user.rb
+5
-0
app/roles/account.rb
app/roles/account.rb
+1
-1
app/views/admin/projects/index.html.haml
app/views/admin/projects/index.html.haml
+4
-1
app/views/admin/users/show.html.haml
app/views/admin/users/show.html.haml
+3
-3
app/views/profiles/show.html.haml
app/views/profiles/show.html.haml
+1
-1
lib/api/projects.rb
lib/api/projects.rb
+1
-1
spec/factories.rb
spec/factories.rb
+1
-1
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+1
-1
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+1
-1
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+1
-1
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+1
-1
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+27
-27
spec/requests/projects_spec.rb
spec/requests/projects_spec.rb
+3
-3
spec/spec_helper.rb
spec/spec_helper.rb
+1
-1
No files found.
app/controllers/admin/users_controller.rb
View file @
d431e433
...
@@ -9,7 +9,7 @@ class Admin::UsersController < AdminController
...
@@ -9,7 +9,7 @@ class Admin::UsersController < AdminController
def
show
def
show
@admin_user
=
User
.
find
(
params
[
:id
])
@admin_user
=
User
.
find
(
params
[
:id
])
@projects
=
if
@admin_user
.
projects
.
empty?
@projects
=
if
@admin_user
.
authorized_
projects
.
empty?
Project
Project
else
else
Project
.
without_user
(
@admin_user
)
Project
.
without_user
(
@admin_user
)
...
@@ -98,7 +98,7 @@ class Admin::UsersController < AdminController
...
@@ -98,7 +98,7 @@ class Admin::UsersController < AdminController
def
destroy
def
destroy
@admin_user
=
User
.
find
(
params
[
:id
])
@admin_user
=
User
.
find
(
params
[
:id
])
if
@admin_user
.
my_own
_projects
.
count
>
0
if
@admin_user
.
personal
_projects
.
count
>
0
redirect_to
admin_users_path
,
alert:
"User is a project owner and can't be removed."
and
return
redirect_to
admin_users_path
,
alert:
"User is a project owner and can't be removed."
and
return
end
end
@admin_user
.
destroy
@admin_user
.
destroy
...
...
app/helpers/namespaces_helper.rb
View file @
d431e433
module
NamespacesHelper
module
NamespacesHelper
def
namespaces_options
(
selected
=
:current_user
,
scope
=
:default
)
def
namespaces_options
(
selected
=
:current_user
,
scope
=
:default
)
groups
=
current_user
.
namespace
s
.
select
{
|
n
|
n
.
type
==
'Group'
}
groups
=
current_user
.
owned_group
s
.
select
{
|
n
|
n
.
type
==
'Group'
}
users
=
if
scope
==
:all
users
=
if
scope
==
:all
Namespace
.
root
Namespace
.
root
...
...
app/models/ability.rb
View file @
d431e433
...
@@ -29,20 +29,9 @@ class Ability
...
@@ -29,20 +29,9 @@ class Ability
rules
<<
project_guest_rules
rules
<<
project_guest_rules
end
end
if
project
.
namespace
# If user own project namespace
# (Ex. group owner or account owner)
if
project
.
namespace
.
owner
==
user
rules
<<
project_admin_rules
end
else
# For compatibility with global projects
# use projects.owner_id
if
project
.
owner
==
user
if
project
.
owner
==
user
rules
<<
project_admin_rules
rules
<<
project_admin_rules
end
end
end
rules
.
flatten
rules
.
flatten
end
end
...
...
app/models/key.rb
View file @
d431e433
...
@@ -73,7 +73,7 @@ class Key < ActiveRecord::Base
...
@@ -73,7 +73,7 @@ class Key < ActiveRecord::Base
if
is_deploy_key
if
is_deploy_key
[
project
]
[
project
]
else
else
user
.
projects
user
.
authorized_
projects
end
end
end
end
...
...
app/models/project.rb
View file @
d431e433
...
@@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
...
@@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
# Scopes
# Scopes
scope
:public_only
,
where
(
private_flag:
false
)
scope
:public_only
,
where
(
private_flag:
false
)
scope
:without_user
,
->
(
user
)
{
where
(
"id NOT IN (:ids)"
,
ids:
user
.
projects
.
map
(
&
:id
)
)
}
scope
:without_user
,
->
(
user
)
{
where
(
"id NOT IN (:ids)"
,
ids:
user
.
authorized_
projects
.
map
(
&
:id
)
)
}
scope
:not_in_group
,
->
(
group
)
{
where
(
"id NOT IN (:ids)"
,
ids:
group
.
project_ids
)
}
scope
:not_in_group
,
->
(
group
)
{
where
(
"id NOT IN (:ids)"
,
ids:
group
.
project_ids
)
}
scope
:in_namespace
,
->
(
namespace
)
{
where
(
namespace_id:
namespace
.
id
)
}
scope
:in_namespace
,
->
(
namespace
)
{
where
(
namespace_id:
namespace
.
id
)
}
scope
:sorted_by_activity
,
->
()
{
order
(
"(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC"
)
}
scope
:sorted_by_activity
,
->
()
{
order
(
"(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC"
)
}
...
...
app/models/user.rb
View file @
d431e433
...
@@ -187,4 +187,9 @@ class User < ActiveRecord::Base
...
@@ -187,4 +187,9 @@ class User < ActiveRecord::Base
(projects.namespace_id IS NULL AND projects.creator_id = :user_id)"
,
(projects.namespace_id IS NULL AND projects.creator_id = :user_id)"
,
namespaces:
namespaces
.
map
(
&
:id
),
user_id:
self
.
id
)
namespaces:
namespaces
.
map
(
&
:id
),
user_id:
self
.
id
)
end
end
# Team membership in personal projects
def
tm_in_personal_projects
personal_projects
.
users_projects
.
where
(
user_id:
self
.
id
)
end
end
end
app/roles/account.rb
View file @
d431e433
...
@@ -69,7 +69,7 @@ module Account
...
@@ -69,7 +69,7 @@ module Account
def
projects_limit_percent
def
projects_limit_percent
return
100
if
projects_limit
.
zero?
return
100
if
projects_limit
.
zero?
(
my_own
_projects
.
count
.
to_f
/
projects_limit
)
*
100
(
personal
_projects
.
count
.
to_f
/
projects_limit
)
*
100
end
end
def
recent_push
project_id
=
nil
def
recent_push
project_id
=
nil
...
...
app/views/admin/projects/index.html.haml
View file @
d431e433
...
@@ -28,7 +28,10 @@
...
@@ -28,7 +28,10 @@
%span
.monospace
=
project
.
path_with_namespace
+
".git"
%span
.monospace
=
project
.
path_with_namespace
+
".git"
%td
=
project
.
users_projects
.
count
%td
=
project
.
users_projects
.
count
%td
%td
=
link_to
project
.
chief
.
name
,
[
:admin
,
project
.
chief
]
-
if
project
.
owner
=
link_to
project
.
owner
.
name
,
[
:admin
,
project
.
owner
]
-
else
(deleted)
%td
=
last_commit
(
project
)
%td
=
last_commit
(
project
)
%td
=
link_to
'Edit'
,
edit_admin_project_path
(
project
),
id:
"edit_
#{
dom_id
(
project
)
}
"
,
class:
"btn small"
%td
=
link_to
'Edit'
,
edit_admin_project_path
(
project
),
id:
"edit_
#{
dom_id
(
project
)
}
"
,
class:
"btn small"
%td
.bgred
=
link_to
'Destroy'
,
[
:admin
,
project
],
confirm:
"REMOVE
#{
project
.
name
}
? Are you sure?"
,
method: :delete
,
class:
"btn small danger"
%td
.bgred
=
link_to
'Destroy'
,
[
:admin
,
project
],
confirm:
"REMOVE
#{
project
.
name
}
? Are you sure?"
,
method: :delete
,
class:
"btn small danger"
...
...
app/views/admin/users/show.html.haml
View file @
d431e433
...
@@ -106,8 +106,8 @@
...
@@ -106,8 +106,8 @@
%td
=
link_to
group
.
name
,
admin_group_path
(
group
)
%td
=
link_to
group
.
name
,
admin_group_path
(
group
)
-
if
@admin_user
.
projects
.
present?
-
if
@admin_user
.
p
ersonal_p
rojects
.
present?
%h5
Projects:
%h5
P
ersonal P
rojects:
%br
%br
%table
.zebra-striped
%table
.zebra-striped
...
@@ -118,7 +118,7 @@
...
@@ -118,7 +118,7 @@
%th
%th
%th
%th
-
@admin_user
.
users
_projects
.
each
do
|
tm
|
-
@admin_user
.
tm_in_personal
_projects
.
each
do
|
tm
|
-
project
=
tm
.
project
-
project
=
tm
.
project
%tr
%tr
%td
=
link_to
project
.
name_with_namespace
,
admin_project_path
(
project
)
%td
=
link_to
project
.
name_with_namespace
,
admin_project_path
(
project
)
...
...
app/views/profiles/show.html.haml
View file @
d431e433
...
@@ -64,7 +64,7 @@
...
@@ -64,7 +64,7 @@
%legend
%legend
Personal projects:
Personal projects:
%small
.right
%small
.right
%span
=
current_user
.
my_own
_projects
.
count
%span
=
current_user
.
personal
_projects
.
count
of
of
%span
=
current_user
.
projects_limit
%span
=
current_user
.
projects_limit
.padded
.padded
...
...
lib/api/projects.rb
View file @
d431e433
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects
# GET /projects
get
do
get
do
@projects
=
paginate
current_user
.
projects
@projects
=
paginate
current_user
.
authorized_
projects
present
@projects
,
with:
Entities
::
Project
present
@projects
,
with:
Entities
::
Project
end
end
...
...
spec/factories.rb
View file @
d431e433
...
@@ -37,7 +37,7 @@ FactoryGirl.define do
...
@@ -37,7 +37,7 @@ FactoryGirl.define do
end
end
factory
:namespace
do
factory
:namespace
do
sequence
(
:name
)
{
|
n
|
"
group
#{
n
}
"
}
sequence
(
:name
)
{
|
n
|
"
namespace
#{
n
}
"
}
path
{
name
.
downcase
.
gsub
(
/\s/
,
'_'
)
}
path
{
name
.
downcase
.
gsub
(
/\s/
,
'_'
)
}
owner
owner
end
end
...
...
spec/requests/api/issues_spec.rb
View file @
d431e433
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:issue
)
{
create
(
:issue
,
author:
user
,
assignee:
user
,
project:
project
)
}
let!
(
:issue
)
{
create
(
:issue
,
author:
user
,
assignee:
user
,
project:
project
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
...
...
spec/requests/api/merge_requests_spec.rb
View file @
d431e433
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
author:
user
,
assignee:
user
,
project:
project
,
title:
"Test"
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
author:
user
,
assignee:
user
,
project:
project
,
title:
"Test"
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
...
...
spec/requests/api/milestones_spec.rb
View file @
d431e433
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
...
...
spec/requests/api/notes_spec.rb
View file @
d431e433
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
...
@@ -4,7 +4,7 @@ describe Gitlab::API do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
user
)
}
let!
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
user
)
}
let!
(
:snippet
)
{
create
(
:snippet
,
project:
project
,
author:
user
)
}
let!
(
:snippet
)
{
create
(
:snippet
,
project:
project
,
author:
user
)
}
let!
(
:issue_note
)
{
create
(
:note
,
noteable:
issue
,
project:
project
,
author:
user
)
}
let!
(
:issue_note
)
{
create
(
:note
,
noteable:
issue
,
project:
project
,
author:
user
)
}
...
...
spec/requests/api/projects_spec.rb
View file @
d431e433
...
@@ -7,7 +7,7 @@ describe Gitlab::API do
...
@@ -7,7 +7,7 @@ describe Gitlab::API do
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let
(
:user3
)
{
create
(
:user
)
}
let
(
:user3
)
{
create
(
:user
)
}
let!
(
:hook
)
{
create
(
:project_hook
,
project:
project
,
url:
"http://example.com"
)
}
let!
(
:hook
)
{
create
(
:project_hook
,
project:
project
,
url:
"http://example.com"
)
}
let!
(
:project
)
{
create
(
:project
,
owner:
user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:snippet
)
{
create
(
:snippet
,
author:
user
,
project:
project
,
title:
'example'
)
}
let!
(
:snippet
)
{
create
(
:snippet
,
author:
user
,
project:
project
,
title:
'example'
)
}
let!
(
:users_project
)
{
create
(
:users_project
,
user:
user
,
project:
project
,
project_access:
UsersProject
::
MASTER
)
}
let!
(
:users_project
)
{
create
(
:users_project
,
user:
user
,
project:
project
,
project_access:
UsersProject
::
MASTER
)
}
let!
(
:users_project2
)
{
create
(
:users_project
,
user:
user3
,
project:
project
,
project_access:
UsersProject
::
DEVELOPER
)
}
let!
(
:users_project2
)
{
create
(
:users_project
,
user:
user3
,
project:
project
,
project_access:
UsersProject
::
DEVELOPER
)
}
...
@@ -79,7 +79,7 @@ describe Gitlab::API do
...
@@ -79,7 +79,7 @@ describe Gitlab::API do
end
end
it
"should return a project by path name"
do
it
"should return a project by path name"
do
get
api
(
"/projects/
#{
project
.
path
}
"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
project
.
name
json_response
[
'name'
].
should
==
project
.
name
end
end
...
@@ -93,7 +93,7 @@ describe Gitlab::API do
...
@@ -93,7 +93,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/repository/branches"
do
describe
"GET /projects/:id/repository/branches"
do
it
"should return an array of project branches"
do
it
"should return an array of project branches"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/branches"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
first
[
'name'
].
should
==
project
.
repo
.
heads
.
sort_by
(
&
:name
).
first
.
name
json_response
.
first
[
'name'
].
should
==
project
.
repo
.
heads
.
sort_by
(
&
:name
).
first
.
name
...
@@ -102,7 +102,7 @@ describe Gitlab::API do
...
@@ -102,7 +102,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/repository/branches/:branch"
do
describe
"GET /projects/:id/repository/branches/:branch"
do
it
"should return the branch information for a single branch"
do
it
"should return the branch information for a single branch"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/branches/new_design"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches/new_design"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'name'
].
should
==
'new_design'
json_response
[
'name'
].
should
==
'new_design'
...
@@ -112,7 +112,7 @@ describe Gitlab::API do
...
@@ -112,7 +112,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/members"
do
describe
"GET /projects/:id/members"
do
it
"should return project team members"
do
it
"should return project team members"
do
get
api
(
"/projects/
#{
project
.
path
}
/members"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
2
json_response
.
count
.
should
==
2
...
@@ -120,7 +120,7 @@ describe Gitlab::API do
...
@@ -120,7 +120,7 @@ describe Gitlab::API do
end
end
it
"finds team members with query string"
do
it
"finds team members with query string"
do
get
api
(
"/projects/
#{
project
.
path
}
/members"
,
user
),
query:
user
.
username
get
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
query:
user
.
username
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
1
json_response
.
count
.
should
==
1
...
@@ -130,7 +130,7 @@ describe Gitlab::API do
...
@@ -130,7 +130,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/members/:user_id"
do
describe
"GET /projects/:id/members/:user_id"
do
it
"should return project team member"
do
it
"should return project team member"
do
get
api
(
"/projects/
#{
project
.
path
}
/members/
#{
user
.
id
}
"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user
.
id
}
"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'email'
].
should
==
user
.
email
json_response
[
'email'
].
should
==
user
.
email
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
...
@@ -140,7 +140,7 @@ describe Gitlab::API do
...
@@ -140,7 +140,7 @@ describe Gitlab::API do
describe
"POST /projects/:id/members"
do
describe
"POST /projects/:id/members"
do
it
"should add user to project team"
do
it
"should add user to project team"
do
expect
{
expect
{
post
api
(
"/projects/
#{
project
.
path
}
/members"
,
user
),
user_id:
user2
.
id
,
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
UsersProject
::
DEVELOPER
access_level:
UsersProject
::
DEVELOPER
}.
to
change
{
UsersProject
.
count
}.
by
(
1
)
}.
to
change
{
UsersProject
.
count
}.
by
(
1
)
...
@@ -152,7 +152,7 @@ describe Gitlab::API do
...
@@ -152,7 +152,7 @@ describe Gitlab::API do
describe
"PUT /projects/:id/members/:user_id"
do
describe
"PUT /projects/:id/members/:user_id"
do
it
"should update project team member"
do
it
"should update project team member"
do
put
api
(
"/projects/
#{
project
.
path
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
UsersProject
::
MASTER
put
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
UsersProject
::
MASTER
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'email'
].
should
==
user3
.
email
json_response
[
'email'
].
should
==
user3
.
email
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
...
@@ -162,14 +162,14 @@ describe Gitlab::API do
...
@@ -162,14 +162,14 @@ describe Gitlab::API do
describe
"DELETE /projects/:id/members/:user_id"
do
describe
"DELETE /projects/:id/members/:user_id"
do
it
"should remove user from project team"
do
it
"should remove user from project team"
do
expect
{
expect
{
delete
api
(
"/projects/
#{
project
.
path
}
/members/
#{
user3
.
id
}
"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
)
}.
to
change
{
UsersProject
.
count
}.
by
(
-
1
)
}.
to
change
{
UsersProject
.
count
}.
by
(
-
1
)
end
end
end
end
describe
"GET /projects/:id/hooks"
do
describe
"GET /projects/:id/hooks"
do
it
"should return project hooks"
do
it
"should return project hooks"
do
get
api
(
"/projects/
#{
project
.
path
}
/hooks"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
...
@@ -181,7 +181,7 @@ describe Gitlab::API do
...
@@ -181,7 +181,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/hooks/:hook_id"
do
describe
"GET /projects/:id/hooks/:hook_id"
do
it
"should return a project hook"
do
it
"should return a project hook"
do
get
api
(
"/projects/
#{
project
.
path
}
/hooks/
#{
hook
.
id
}
"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'url'
].
should
==
hook
.
url
json_response
[
'url'
].
should
==
hook
.
url
end
end
...
@@ -190,7 +190,7 @@ describe Gitlab::API do
...
@@ -190,7 +190,7 @@ describe Gitlab::API do
describe
"POST /projects/:id/hooks"
do
describe
"POST /projects/:id/hooks"
do
it
"should add hook to project"
do
it
"should add hook to project"
do
expect
{
expect
{
post
api
(
"/projects/
#{
project
.
path
}
/hooks"
,
user
),
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
"url"
=>
"http://example.com"
"url"
=>
"http://example.com"
}.
to
change
{
project
.
hooks
.
count
}.
by
(
1
)
}.
to
change
{
project
.
hooks
.
count
}.
by
(
1
)
end
end
...
@@ -198,7 +198,7 @@ describe Gitlab::API do
...
@@ -198,7 +198,7 @@ describe Gitlab::API do
describe
"PUT /projects/:id/hooks/:hook_id"
do
describe
"PUT /projects/:id/hooks/:hook_id"
do
it
"should update an existing project hook"
do
it
"should update an existing project hook"
do
put
api
(
"/projects/
#{
project
.
path
}
/hooks/
#{
hook
.
id
}
"
,
user
),
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
),
url:
'http://example.org'
url:
'http://example.org'
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'url'
].
should
==
'http://example.org'
json_response
[
'url'
].
should
==
'http://example.org'
...
@@ -209,7 +209,7 @@ describe Gitlab::API do
...
@@ -209,7 +209,7 @@ describe Gitlab::API do
describe
"DELETE /projects/:id/hooks"
do
describe
"DELETE /projects/:id/hooks"
do
it
"should delete hook from project"
do
it
"should delete hook from project"
do
expect
{
expect
{
delete
api
(
"/projects/
#{
project
.
path
}
/hooks"
,
user
),
delete
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
hook_id:
hook
.
id
hook_id:
hook
.
id
}.
to
change
{
project
.
hooks
.
count
}.
by
(
-
1
)
}.
to
change
{
project
.
hooks
.
count
}.
by
(
-
1
)
end
end
...
@@ -217,7 +217,7 @@ describe Gitlab::API do
...
@@ -217,7 +217,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/repository/tags"
do
describe
"GET /projects/:id/repository/tags"
do
it
"should return an array of project tags"
do
it
"should return an array of project tags"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/tags"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
first
[
'name'
].
should
==
project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
.
first
.
name
json_response
.
first
[
'name'
].
should
==
project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
.
first
.
name
...
@@ -229,7 +229,7 @@ describe Gitlab::API do
...
@@ -229,7 +229,7 @@ describe Gitlab::API do
before
{
project
.
add_access
(
user2
,
:read
)
}
before
{
project
.
add_access
(
user2
,
:read
)
}
it
"should return project commits"
do
it
"should return project commits"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/commits"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
...
@@ -239,7 +239,7 @@ describe Gitlab::API do
...
@@ -239,7 +239,7 @@ describe Gitlab::API do
context
"unauthorized user"
do
context
"unauthorized user"
do
it
"should not return project commits"
do
it
"should not return project commits"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/commits"
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits"
)
response
.
status
.
should
==
401
response
.
status
.
should
==
401
end
end
end
end
...
@@ -247,7 +247,7 @@ describe Gitlab::API do
...
@@ -247,7 +247,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/snippets"
do
describe
"GET /projects/:id/snippets"
do
it
"should return an array of project snippets"
do
it
"should return an array of project snippets"
do
get
api
(
"/projects/
#{
project
.
path
}
/snippets"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/snippets"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
snippet
.
title
json_response
.
first
[
'title'
].
should
==
snippet
.
title
...
@@ -256,7 +256,7 @@ describe Gitlab::API do
...
@@ -256,7 +256,7 @@ describe Gitlab::API do
describe
"GET /projects/:id/snippets/:snippet_id"
do
describe
"GET /projects/:id/snippets/:snippet_id"
do
it
"should return a project snippet"
do
it
"should return a project snippet"
do
get
api
(
"/projects/
#{
project
.
path
}
/snippets/
#{
snippet
.
id
}
"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
snippet
.
title
json_response
[
'title'
].
should
==
snippet
.
title
end
end
...
@@ -264,7 +264,7 @@ describe Gitlab::API do
...
@@ -264,7 +264,7 @@ describe Gitlab::API do
describe
"POST /projects/:id/snippets"
do
describe
"POST /projects/:id/snippets"
do
it
"should create a new project snippet"
do
it
"should create a new project snippet"
do
post
api
(
"/projects/
#{
project
.
path
}
/snippets"
,
user
),
post
api
(
"/projects/
#{
project
.
id
}
/snippets"
,
user
),
title:
'api test'
,
file_name:
'sample.rb'
,
code:
'test'
title:
'api test'
,
file_name:
'sample.rb'
,
code:
'test'
response
.
status
.
should
==
201
response
.
status
.
should
==
201
json_response
[
'title'
].
should
==
'api test'
json_response
[
'title'
].
should
==
'api test'
...
@@ -273,7 +273,7 @@ describe Gitlab::API do
...
@@ -273,7 +273,7 @@ describe Gitlab::API do
describe
"PUT /projects/:id/snippets/:shippet_id"
do
describe
"PUT /projects/:id/snippets/:shippet_id"
do
it
"should update an existing project snippet"
do
it
"should update an existing project snippet"
do
put
api
(
"/projects/
#{
project
.
path
}
/snippets/
#{
snippet
.
id
}
"
,
user
),
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
),
code:
'updated code'
code:
'updated code'
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
'example'
json_response
[
'title'
].
should
==
'example'
...
@@ -284,31 +284,31 @@ describe Gitlab::API do
...
@@ -284,31 +284,31 @@ describe Gitlab::API do
describe
"DELETE /projects/:id/snippets/:snippet_id"
do
describe
"DELETE /projects/:id/snippets/:snippet_id"
do
it
"should delete existing project snippet"
do
it
"should delete existing project snippet"
do
expect
{
expect
{
delete
api
(
"/projects/
#{
project
.
path
}
/snippets/
#{
snippet
.
id
}
"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
)
}.
to
change
{
Snippet
.
count
}.
by
(
-
1
)
}.
to
change
{
Snippet
.
count
}.
by
(
-
1
)
end
end
end
end
describe
"GET /projects/:id/snippets/:snippet_id/raw"
do
describe
"GET /projects/:id/snippets/:snippet_id/raw"
do
it
"should get a raw project snippet"
do
it
"should get a raw project snippet"
do
get
api
(
"/projects/
#{
project
.
path
}
/snippets/
#{
snippet
.
id
}
/raw"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/raw"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
end
end
end
end
describe
"GET /projects/:id/:sha/blob"
do
describe
"GET /projects/:id/:sha/blob"
do
it
"should get the raw file contents"
do
it
"should get the raw file contents"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/commits/master/blob?filepath=README.md"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/master/blob?filepath=README.md"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
end
end
it
"should return 404 for invalid branch_name"
do
it
"should return 404 for invalid branch_name"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/commits/invalid_branch_name/blob?filepath=README.md"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/invalid_branch_name/blob?filepath=README.md"
,
user
)
response
.
status
.
should
==
404
response
.
status
.
should
==
404
end
end
it
"should return 404 for invalid file"
do
it
"should return 404 for invalid file"
do
get
api
(
"/projects/
#{
project
.
path
}
/repository/commits/master/blob?filepath=README.invalid"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/master/blob?filepath=README.invalid"
,
user
)
response
.
status
.
should
==
404
response
.
status
.
should
==
404
end
end
end
end
...
...
spec/requests/projects_spec.rb
View file @
d431e433
...
@@ -5,7 +5,7 @@ describe "Projects" do
...
@@ -5,7 +5,7 @@ describe "Projects" do
describe
"GET /projects/show"
do
describe
"GET /projects/show"
do
before
do
before
do
@project
=
create
(
:project
,
owner:
@user
)
@project
=
create
(
:project
,
namespace:
@user
.
namespace
)
@project
.
add_access
(
@user
,
:read
)
@project
.
add_access
(
@user
,
:read
)
visit
project_path
(
@project
)
visit
project_path
(
@project
)
...
@@ -37,7 +37,7 @@ describe "Projects" do
...
@@ -37,7 +37,7 @@ describe "Projects" do
describe
"PUT /projects/:id"
do
describe
"PUT /projects/:id"
do
before
do
before
do
@project
=
create
(
:project
,
owner:
@user
)
@project
=
create
(
:project
,
namespace:
@user
.
namespace
)
@project
.
add_access
(
@user
,
:admin
,
:read
)
@project
.
add_access
(
@user
,
:admin
,
:read
)
visit
edit_project_path
(
@project
)
visit
edit_project_path
(
@project
)
...
@@ -58,7 +58,7 @@ describe "Projects" do
...
@@ -58,7 +58,7 @@ describe "Projects" do
describe
"DELETE /projects/:id"
do
describe
"DELETE /projects/:id"
do
before
do
before
do
@project
=
create
(
:project
,
owner:
@user
)
@project
=
create
(
:project
,
namespace:
@user
.
namespace
)
@project
.
add_access
(
@user
,
:read
,
:admin
)
@project
.
add_access
(
@user
,
:read
,
:admin
)
visit
edit_project_path
(
@project
)
visit
edit_project_path
(
@project
)
end
end
...
...
spec/spec_helper.rb
View file @
d431e433
...
@@ -38,7 +38,7 @@ RSpec.configure do |config|
...
@@ -38,7 +38,7 @@ RSpec.configure do |config|
stub_gitolite!
stub_gitolite!
# !!! Observers disabled by default in tests
# !!! Observers disabled by default in tests
ActiveRecord
::
Base
.
observers
.
disable
(
:all
)
#
ActiveRecord::Base.observers.disable(:all)
# ActiveRecord::Base.observers.enable(:all)
# ActiveRecord::Base.observers.enable(:all)
# Use tmp dir for FS manipulations
# Use tmp dir for FS manipulations
...
...
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