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
01400a08
Commit
01400a08
authored
May 24, 2018
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse Push factory
parent
c5bcae5d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
40 deletions
+27
-40
qa/qa/factory/repository/push.rb
qa/qa/factory/repository/push.rb
+6
-2
qa/qa/git/repository.rb
qa/qa/git/repository.rb
+3
-3
qa/qa/specs/features/repository/protected_branches_spec.rb
qa/qa/specs/features/repository/protected_branches_spec.rb
+18
-35
No files found.
qa/qa/factory/repository/push.rb
View file @
01400a08
...
@@ -3,7 +3,7 @@ module QA
...
@@ -3,7 +3,7 @@ module QA
module
Repository
module
Repository
class
Push
<
Factory
::
Base
class
Push
<
Factory
::
Base
attr_accessor
:file_name
,
:file_content
,
:commit_message
,
attr_accessor
:file_name
,
:file_content
,
:commit_message
,
:branch_name
,
:new_branch
:branch_name
,
:new_branch
,
:output
attr_writer
:remote_branch
attr_writer
:remote_branch
...
@@ -12,6 +12,10 @@ module QA
...
@@ -12,6 +12,10 @@ module QA
project
.
description
=
'Project with repository'
project
.
description
=
'Project with repository'
end
end
product
:output
do
|
factory
|
factory
.
output
end
def
initialize
def
initialize
@file_name
=
'file.txt'
@file_name
=
'file.txt'
@file_content
=
'# This is test project'
@file_content
=
'# This is test project'
...
@@ -58,7 +62,7 @@ module QA
...
@@ -58,7 +62,7 @@ module QA
end
end
repository
.
commit
(
commit_message
)
repository
.
commit
(
commit_message
)
repository
.
push_changes
(
"
#{
branch_name
}
:
#{
remote_branch
}
"
)
@output
=
repository
.
push_changes
(
"
#{
branch_name
}
:
#{
remote_branch
}
"
)
end
end
end
end
end
end
...
...
qa/qa/git/repository.rb
View file @
01400a08
...
@@ -7,8 +7,6 @@ module QA
...
@@ -7,8 +7,6 @@ module QA
class
Repository
class
Repository
include
Scenario
::
Actable
include
Scenario
::
Actable
attr_reader
:push_output
def
self
.
perform
(
*
args
)
def
self
.
perform
(
*
args
)
Dir
.
mktmpdir
do
|
dir
|
Dir
.
mktmpdir
do
|
dir
|
Dir
.
chdir
(
dir
)
{
super
}
Dir
.
chdir
(
dir
)
{
super
}
...
@@ -71,7 +69,9 @@ module QA
...
@@ -71,7 +69,9 @@ module QA
end
end
def
push_changes
(
branch
=
'master'
)
def
push_changes
(
branch
=
'master'
)
@push_output
,
_
=
run_and_redact_credentials
(
"git push
#{
@uri
}
#{
branch
}
"
)
output
,
_
=
run_and_redact_credentials
(
"git push
#{
@uri
}
#{
branch
}
"
)
output
end
end
def
commits
def
commits
...
...
qa/qa/specs/features/repository/protected_branches_spec.rb
View file @
01400a08
...
@@ -7,12 +7,6 @@ module QA
...
@@ -7,12 +7,6 @@ module QA
resource
.
name
=
'protected-branch-project'
resource
.
name
=
'protected-branch-project'
end
end
end
end
given
(
:location
)
do
Page
::
Project
::
Show
.
act
do
choose_repository_clone_http
repository_location
end
end
before
do
before
do
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
Runtime
::
Browser
.
visit
(
:gitlab
,
Page
::
Main
::
Login
)
...
@@ -27,40 +21,32 @@ module QA
...
@@ -27,40 +21,32 @@ module QA
end
end
context
'when developers and maintainers are allowed to push to a protected branch'
do
context
'when developers and maintainers are allowed to push to a protected branch'
do
let!
(
:protected_branch
)
{
fabricate
_branch
(
allow_to_push:
true
)
}
let!
(
:protected_branch
)
{
create_protected
_branch
(
allow_to_push:
true
)
}
scenario
'user with push rights successfully pushes to the protected branch'
do
scenario
'user with push rights successfully pushes to the protected branch'
do
expect
(
protected_branch
.
name
).
to
have_content
(
branch_name
)
expect
(
protected_branch
.
name
).
to
have_content
(
branch_name
)
expect
(
protected_branch
.
push_allowance
).
to
have_content
(
'Developers + Maintainers'
)
expect
(
protected_branch
.
push_allowance
).
to
have_content
(
'Developers + Maintainers'
)
p
roject
.
visit!
p
ush
=
push_new_file
(
branch_name
)
Git
::
Repository
.
perform
do
|
repository
|
expect
(
push
.
output
).
to
match
(
/remote: To create a merge request for protected-branch, visit/
)
push_output
=
push_to_repository
(
repository
)
expect
(
push_output
).
to
match
(
/remote: To create a merge request for protected-branch, visit/
)
end
end
end
end
end
context
'when developers and maintainers are not allowed to push to a protected branch'
do
context
'when developers and maintainers are not allowed to push to a protected branch'
do
scenario
'user without push rights fails to push to the protected branch'
do
scenario
'user without push rights fails to push to the protected branch'
do
fabricate_branch
(
allow_to_push:
false
)
create_protected_branch
(
allow_to_push:
false
)
project
.
visit!
Git
::
Repository
.
perform
do
|
repository
|
push
=
push_new_file
(
branch_name
)
push_output
=
push_to_repository
(
repository
)
expect
(
push_output
)
expect
(
push
.
output
)
.
to
match
(
/remote\: GitLab\: You are not allowed to push code to protected branches on this project/
)
.
to
match
(
/remote\: GitLab\: You are not allowed to push code to protected branches on this project/
)
expect
(
push_output
)
expect
(
push
.
output
)
.
to
match
(
/\[remote rejected\]
#{
branch_name
}
->
#{
branch_name
}
\(pre-receive hook declined\)/
)
.
to
match
(
/\[remote rejected\]
#{
branch_name
}
->
#{
branch_name
}
\(pre-receive hook declined\)/
)
end
end
end
end
end
def
fabricate
_branch
(
allow_to_push
:)
def
create_protected
_branch
(
allow_to_push
:)
Factory
::
Resource
::
Branch
.
fabricate!
do
|
resource
|
Factory
::
Resource
::
Branch
.
fabricate!
do
|
resource
|
resource
.
branch_name
=
branch_name
resource
.
branch_name
=
branch_name
resource
.
project
=
project
resource
.
project
=
project
...
@@ -69,17 +55,14 @@ module QA
...
@@ -69,17 +55,14 @@ module QA
end
end
end
end
def
push_to_repository
(
repository
)
def
push_new_file
(
branch
)
repository
.
uri
=
location
.
uri
Factory
::
Repository
::
Push
.
fabricate!
do
|
resource
|
repository
.
use_default_credentials
resource
.
project
=
project
resource
.
file_name
=
'new_file.md'
repository
.
act
do
resource
.
file_content
=
'# This is a new file'
clone
resource
.
commit_message
=
'Add new_file.md'
configure_identity
(
'GitLab QA'
,
'root@gitlab.com'
)
resource
.
branch_name
=
branch_name
checkout
(
'protected-branch'
)
resource
.
new_branch
=
false
commit_file
(
'README.md'
,
'readme content'
,
'Add a readme'
)
push_changes
(
'protected-branch'
)
push_output
end
end
end
end
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