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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
cec88ba6
Commit
cec88ba6
authored
Mar 31, 2020
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes duplication in specs and removes extra code
parent
0c82bf04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
25 deletions
+14
-25
app/serializers/diffs_entity.rb
app/serializers/diffs_entity.rb
+0
-1
lib/api/entities/commit_with_link.rb
lib/api/entities/commit_with_link.rb
+0
-4
spec/serializers/diffs_entity_spec.rb
spec/serializers/diffs_entity_spec.rb
+14
-20
No files found.
app/serializers/diffs_entity.rb
View file @
cec88ba6
...
...
@@ -3,7 +3,6 @@
class
DiffsEntity
<
Grape
::
Entity
include
DiffHelper
include
RequestAwareEntity
include
Gitlab
::
Utils
::
StrongMemoize
expose
:real_size
expose
:size
...
...
lib/api/entities/commit_with_link.rb
View file @
cec88ba6
...
...
@@ -33,14 +33,10 @@ module API
end
expose
:prev_commit_id
,
if:
{
type: :full
}
do
|
commit
|
next
unless
options
[
:prev_commit_id
]
options
[
:prev_commit_id
]
end
expose
:next_commit_id
,
if:
{
type: :full
}
do
|
commit
|
next
unless
options
[
:next_commit_id
]
options
[
:next_commit_id
]
end
...
...
spec/serializers/diffs_entity_spec.rb
View file @
cec88ba6
...
...
@@ -28,51 +28,45 @@ describe DiffsEntity do
end
context
"when a commit_id is passed"
do
let
(
:commits
)
{
[
nil
]
+
merge_request
.
commits
+
[
nil
]
}
let
(
:commits
)
{
merge_request
.
commits
}
let
(
:entity
)
do
described_class
.
new
(
merge_request_diffs
.
first
.
diffs
,
request:
request
,
merge_request:
merge_request
,
merge_request_diffs:
merge_request_diffs
,
commit:
@
commit
commit:
commit
)
end
subject
{
entity
.
as_json
}
context
"when the passed commit is not the first or last in the group"
do
let
(
:commit
)
{
commits
.
third
}
it
'includes commit references for previous and next'
do
@commit
=
commits
.
third
check_neighbor_commits
(
commits
,
@commit
)
expect
(
subject
[
:commit
][
:prev_commit_id
]).
to
eq
(
commits
.
second
.
id
)
expect
(
subject
[
:commit
][
:next_commit_id
]).
to
eq
(
commits
.
fourth
.
id
)
end
end
context
"when the passed commit is the first in the group"
do
let
(
:commit
)
{
commits
.
first
}
it
'includes commit references for nil and next'
do
@commit
=
commits
.
compact
.
last
check_neighbor_commits
(
commits
,
@commit
)
expect
(
subject
[
:commit
][
:prev_commit_id
]).
to
eq
(
nil
)
expect
(
subject
[
:commit
][
:next_commit_id
]).
to
eq
(
commits
.
second
.
id
)
end
end
context
"when the passed commit is the last in the group"
do
let
(
:commit
)
{
commits
.
last
}
it
'includes commit references for previous and nil'
do
@commit
=
commits
.
compact
.
first
check_neighbor_commits
(
commits
,
@commit
)
expect
(
subject
[
:commit
][
:prev_commit_id
]).
to
eq
(
commits
[
-
2
].
id
)
expect
(
subject
[
:commit
][
:next_commit_id
]).
to
eq
(
nil
)
end
end
end
end
private
def
check_neighbor_commits
(
commits
,
commit
)
index
=
commits
.
index
(
commit
)
prev_commit
=
commits
[
index
-
1
]
&
.
id
next_commit
=
commits
[
index
+
1
]
&
.
id
expect
(
subject
[
:commit
]).
to
include
(
:prev_commit_id
,
:next_commit_id
)
expect
(
subject
[
:commit
][
:prev_commit_id
]).
to
eq
(
prev_commit
)
expect
(
subject
[
:commit
][
:next_commit_id
]).
to
eq
(
next_commit
)
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