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
18611f0e
Commit
18611f0e
authored
Jul 23, 2018
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor spec for Commits::UpdateService
parent
d331377a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
27 deletions
+51
-27
spec/services/commits/update_service_spec.rb
spec/services/commits/update_service_spec.rb
+51
-27
No files found.
spec/services/commits/update_service_spec.rb
View file @
18611f0e
...
...
@@ -4,46 +4,75 @@ describe Commits::UpdateService do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:commit
)
{
create
(
:commit
,
project:
project
)
}
let
(
:commit
)
{
project
.
commit
}
before
do
project
.
add_maintainer
(
user
)
end
describe
'execute'
do
describe
'
#
execute'
do
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
shared_examples
'tagging fails'
do
it
'returns nil'
do
tagged_commit
=
service
.
execute
(
commit
)
expect
(
tagged_commit
).
to
be_nil
end
it
'does not add a system note'
do
service
.
execute
(
commit
)
description_notes
=
find_notes
(
'tag'
)
expect
(
description_notes
).
to
be_empty
end
end
def
find_notes
(
action
)
commit
.
notes
.
joins
(
:system_note_metadata
)
.
where
(
system_note_metadata:
{
action:
action
})
end
context
'valid params'
do
let
(
:opts
)
do
{
tag_name:
'1.2.3'
,
tag_name:
'
v
1.2.3'
,
tag_message:
'Release'
}
end
it
'tags a commit'
do
tag_double
=
double
(
name:
opts
[
:tag_name
])
tag_stub
=
instance_double
(
Tags
::
CreateService
)
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
allow
(
tag_stub
).
to
receive
(
:execute
)
.
with
(
opts
[
:tag_name
],
commit
.
sha
,
opts
[
:tag_message
],
nil
)
.
and_return
({
status: :success
,
tag:
tag_double
})
def
find_notes
(
action
)
commit
.
notes
.
joins
(
:system_note_metadata
)
.
where
(
system_note_metadata:
{
action:
action
})
end
expect
(
SystemNoteService
).
to
receive
(
:tag_commit
).
with
(
commit
,
project
,
user
,
opts
[
:tag_name
])
context
'when tagging succeeds'
do
it
'returns the commit'
do
tagged_commit
=
service
.
execute
(
commit
)
service
.
execute
(
commit
)
end
expect
(
tagged_commit
).
to
eq
(
commit
)
end
it
'fails to tag the commit'
do
tag_stub
=
instance_double
(
Tags
::
CreateService
)
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
allow
(
tag_stub
).
to
receive
(
:execute
)
.
with
(
opts
[
:tag_name
],
commit
.
sha
,
opts
[
:tag_message
],
nil
)
.
and_return
({
status: :error
})
it
'adds a system note'
do
service
.
execute
(
commit
)
expect
(
SystemNoteService
).
not_to
receive
(
:tag_commit
)
description_notes
=
find_notes
(
'tag'
)
expect
(
description_notes
.
length
).
to
eq
(
1
)
end
end
service
.
execute
(
commit
)
context
'when tagging fails'
do
before
do
tag_stub
=
instance_double
(
Tags
::
CreateService
)
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
allow
(
tag_stub
).
to
receive
(
:execute
).
and_return
({
status: :error
})
end
include_examples
'tagging fails'
end
end
...
...
@@ -52,12 +81,7 @@ describe Commits::UpdateService do
{}
end
it
'does not call the tag create service'
do
expect
(
Tags
::
CreateService
).
not_to
receive
(
:new
)
expect
(
SystemNoteService
).
not_to
receive
(
:tag_commit
)
service
.
execute
(
commit
)
end
include_examples
'tagging fails'
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