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
8c5eff29
Commit
8c5eff29
authored
Jun 25, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix branch API can_push attribute and add specs
parent
9490c378
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
lib/api/branches.rb
lib/api/branches.rb
+5
-3
spec/requests/api/branches_spec.rb
spec/requests/api/branches_spec.rb
+35
-0
No files found.
lib/api/branches.rb
View file @
8c5eff29
...
@@ -45,6 +45,7 @@ module API
...
@@ -45,6 +45,7 @@ module API
present
(
present
(
paginate
(
::
Kaminari
.
paginate_array
(
branches
)),
paginate
(
::
Kaminari
.
paginate_array
(
branches
)),
with:
Entities
::
Branch
,
with:
Entities
::
Branch
,
current_user:
current_user
,
project:
user_project
,
project:
user_project
,
merged_branch_names:
merged_branch_names
merged_branch_names:
merged_branch_names
)
)
...
@@ -63,7 +64,7 @@ module API
...
@@ -63,7 +64,7 @@ module API
get
do
get
do
branch
=
find_branch!
(
params
[
:branch
])
branch
=
find_branch!
(
params
[
:branch
])
present
branch
,
with:
Entities
::
Branch
,
project:
user_project
present
branch
,
with:
Entities
::
Branch
,
current_user:
current_user
,
project:
user_project
end
end
end
end
...
@@ -101,7 +102,7 @@ module API
...
@@ -101,7 +102,7 @@ module API
end
end
if
protected_branch
.
valid?
if
protected_branch
.
valid?
present
branch
,
with:
Entities
::
Branch
,
project:
user_project
present
branch
,
with:
Entities
::
Branch
,
current_user:
current_user
,
project:
user_project
else
else
render_api_error!
(
protected_branch
.
errors
.
full_messages
,
422
)
render_api_error!
(
protected_branch
.
errors
.
full_messages
,
422
)
end
end
...
@@ -121,7 +122,7 @@ module API
...
@@ -121,7 +122,7 @@ module API
protected_branch
=
user_project
.
protected_branches
.
find_by
(
name:
branch
.
name
)
protected_branch
=
user_project
.
protected_branches
.
find_by
(
name:
branch
.
name
)
protected_branch
&
.
destroy
protected_branch
&
.
destroy
present
branch
,
with:
Entities
::
Branch
,
project:
user_project
present
branch
,
with:
Entities
::
Branch
,
current_user:
current_user
,
project:
user_project
end
end
desc
'Create branch'
do
desc
'Create branch'
do
...
@@ -140,6 +141,7 @@ module API
...
@@ -140,6 +141,7 @@ module API
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
present
result
[
:branch
],
present
result
[
:branch
],
with:
Entities
::
Branch
,
with:
Entities
::
Branch
,
current_user:
current_user
,
project:
user_project
project:
user_project
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
...
...
spec/requests/api/branches_spec.rb
View file @
8c5eff29
...
@@ -155,6 +155,12 @@ describe API::Branches do
...
@@ -155,6 +155,12 @@ describe API::Branches do
end
end
it_behaves_like
'repository branch'
it_behaves_like
'repository branch'
it
'returns that the current user cannot push'
do
get
api
(
route
,
current_user
)
expect
(
json_response
[
'can_push'
]).
to
eq
(
false
)
end
end
end
context
'when unauthenticated'
,
'and project is private'
do
context
'when unauthenticated'
,
'and project is private'
do
...
@@ -169,6 +175,18 @@ describe API::Branches do
...
@@ -169,6 +175,18 @@ describe API::Branches do
it_behaves_like
'repository branch'
it_behaves_like
'repository branch'
it
'returns that the current user can push'
do
get
api
(
route
,
current_user
)
expect
(
json_response
[
'can_push'
]).
to
eq
(
true
)
end
it
'returns that the current user can push'
do
get
api
(
route
,
current_user
)
expect
(
json_response
[
'can_push'
]).
to
eq
(
true
)
end
context
'when branch contains a dot'
do
context
'when branch contains a dot'
do
let
(
:branch_name
)
{
branch_with_dot
.
name
}
let
(
:branch_name
)
{
branch_with_dot
.
name
}
...
@@ -202,6 +220,23 @@ describe API::Branches do
...
@@ -202,6 +220,23 @@ describe API::Branches do
end
end
end
end
context
'when authenticated'
,
'as a developer and branch is protected'
do
let
(
:current_user
)
{
create
(
:user
)
}
let!
(
:protected_branch
)
{
create
(
:protected_branch
,
project:
project
,
name:
branch_name
)
}
before
do
project
.
add_developer
(
current_user
)
end
it_behaves_like
'repository branch'
it
'returns that the current user cannot push'
do
get
api
(
route
,
current_user
)
expect
(
json_response
[
'can_push'
]).
to
eq
(
false
)
end
end
context
'when authenticated'
,
'as a guest'
do
context
'when authenticated'
,
'as a guest'
do
it_behaves_like
'403 response'
do
it_behaves_like
'403 response'
do
let
(
:request
)
{
get
api
(
route
,
guest
)
}
let
(
:request
)
{
get
api
(
route
,
guest
)
}
...
...
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