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
4abba289
Commit
4abba289
authored
Sep 28, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for extracted git push class
parent
76d9e29a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
2 deletions
+91
-2
lib/gitlab/git/push.rb
lib/gitlab/git/push.rb
+8
-2
spec/lib/gitlab/git/push_spec.rb
spec/lib/gitlab/git/push_spec.rb
+83
-0
No files found.
lib/gitlab/git/push.rb
View file @
4abba289
...
...
@@ -3,6 +3,8 @@
module
Gitlab
module
Git
class
Push
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:oldrev
,
:newrev
def
initialize
(
project
,
oldrev
,
newrev
,
ref
)
...
...
@@ -13,7 +15,9 @@ module Gitlab
end
def
branch_name
@branch_name
||=
Gitlab
::
Git
.
ref_name
(
@ref
)
strong_memoize
(
:branch_name
)
do
Gitlab
::
Git
.
branch_name
(
@ref
)
end
end
def
branch_added?
...
...
@@ -29,7 +33,9 @@ module Gitlab
end
def
branch_push?
Gitlab
::
Git
.
branch_ref?
(
@ref
)
strong_memoize
(
:branch_push
)
do
Gitlab
::
Git
.
branch_ref?
(
@ref
)
end
end
end
end
...
...
spec/lib/gitlab/git/push_spec.rb
0 → 100644
View file @
4abba289
require
'spec_helper'
describe
Gitlab
::
Git
::
Push
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:oldrev
)
{
project
.
commit
(
'HEAD~10'
).
id
}
let
(
:newrev
)
{
project
.
commit
.
id
}
let
(
:ref
)
{
'refs/heads/some-branch'
}
subject
{
described_class
.
new
(
project
,
oldrev
,
newrev
,
ref
)
}
describe
'#branch_name'
do
context
'when it is a branch push'
do
let
(
:ref
)
{
'refs/heads/my-branch'
}
it
'returns branch name'
do
expect
(
subject
.
branch_name
).
to
eq
'my-branch'
end
end
context
'when it is a tag push'
do
let
(
:ref
)
{
'refs/tags/my-branch'
}
it
'returns nil'
do
expect
(
subject
.
branch_name
).
to
be_nil
end
end
end
describe
'#branch_push?'
do
context
'when pushing a branch ref'
do
let
(
:ref
)
{
'refs/heads/my-branch'
}
it
{
is_expected
.
to
be_branch_push
}
end
context
'when it is a tag push'
do
let
(
:ref
)
{
'refs/tags/my-branch'
}
it
{
is_expected
.
not_to
be_branch_push
}
end
end
describe
'#force_push?'
do
context
'when old revision is an ancestor of the new revision'
do
let
(
:oldrev
)
{
'HEAD~3'
}
let
(
:newrev
)
{
'HEAD~1'
}
it
{
is_expected
.
not_to
be_force_push
}
end
context
'when old revision is not an ancestor of the new revision'
do
let
(
:oldrev
)
{
'HEAD~3'
}
let
(
:newrev
)
{
'123456'
}
it
{
is_expected
.
to
be_force_push
}
end
end
describe
'#branch_added?'
do
context
'when old revision is defined'
do
it
{
is_expected
.
not_to
be_branch_added
}
end
context
'when old revision is not defined'
do
let
(
:oldrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
it
{
is_expected
.
to
be_branch_added
}
end
end
describe
'#branch_removed?'
do
context
'when new revision is defined'
do
it
{
is_expected
.
not_to
be_branch_removed
}
end
context
'when new revision is not defined'
do
let
(
:newrev
)
{
Gitlab
::
Git
::
BLANK_SHA
}
it
{
is_expected
.
to
be_branch_removed
}
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