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
Boxiang Sun
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
Show 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
...
@@ -4,46 +4,75 @@ describe Commits::UpdateService do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:commit
)
{
create
(
:commit
,
project:
project
)
}
let
(
:commit
)
{
project
.
commit
}
before
do
before
do
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
end
end
describe
'execute'
do
describe
'
#
execute'
do
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
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
context
'valid params'
do
let
(
:opts
)
do
let
(
:opts
)
do
{
{
tag_name:
'1.2.3'
,
tag_name:
'
v
1.2.3'
,
tag_message:
'Release'
tag_message:
'Release'
}
}
end
end
it
'tags a commit'
do
def
find_notes
(
action
)
tag_double
=
double
(
name:
opts
[
:tag_name
])
commit
tag_stub
=
instance_double
(
Tags
::
CreateService
)
.
notes
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
.
joins
(
:system_note_metadata
)
allow
(
tag_stub
).
to
receive
(
:execute
)
.
where
(
system_note_metadata:
{
action:
action
})
.
with
(
opts
[
:tag_name
],
commit
.
sha
,
opts
[
:tag_message
],
nil
)
end
.
and_return
({
status: :success
,
tag:
tag_double
})
context
'when tagging succeeds'
do
it
'returns the commit'
do
tagged_commit
=
service
.
execute
(
commit
)
expect
(
SystemNoteService
).
to
receive
(
:tag_commit
).
with
(
commit
,
project
,
user
,
opts
[
:tag_name
])
expect
(
tagged_commit
).
to
eq
(
commit
)
end
it
'adds a system note'
do
service
.
execute
(
commit
)
service
.
execute
(
commit
)
description_notes
=
find_notes
(
'tag'
)
expect
(
description_notes
.
length
).
to
eq
(
1
)
end
end
end
it
'fails to tag the commit'
do
context
'when tagging fails'
do
before
do
tag_stub
=
instance_double
(
Tags
::
CreateService
)
tag_stub
=
instance_double
(
Tags
::
CreateService
)
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
allow
(
tag_stub
).
to
receive
(
:execute
)
allow
(
tag_stub
).
to
receive
(
:execute
).
and_return
({
status: :error
})
.
with
(
opts
[
:tag_name
],
commit
.
sha
,
opts
[
:tag_message
],
nil
)
end
.
and_return
({
status: :error
})
expect
(
SystemNoteService
).
not_to
receive
(
:tag_commit
)
service
.
execute
(
commit
)
include_examples
'tagging fails'
end
end
end
end
...
@@ -52,12 +81,7 @@ describe Commits::UpdateService do
...
@@ -52,12 +81,7 @@ describe Commits::UpdateService do
{}
{}
end
end
it
'does not call the tag create service'
do
include_examples
'tagging fails'
expect
(
Tags
::
CreateService
).
not_to
receive
(
:new
)
expect
(
SystemNoteService
).
not_to
receive
(
:tag_commit
)
service
.
execute
(
commit
)
end
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