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
5dab4ac8
Commit
5dab4ac8
authored
Apr 19, 2021
by
Abhishek Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve test coverage
parent
872b3b61
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
13 deletions
+60
-13
spec/models/context_commits_diff_spec.rb
spec/models/context_commits_diff_spec.rb
+46
-5
spec/serializers/context_commits_diff_entity_spec.rb
spec/serializers/context_commits_diff_entity_spec.rb
+14
-8
No files found.
spec/models/context_commits_diff_spec.rb
View file @
5dab4ac8
...
...
@@ -3,21 +3,62 @@
require
'spec_helper'
RSpec
.
describe
ContextCommitsDiff
do
let
(
:
merge_request_context_commit_diff_file
)
{
create
(
:merge_request_context_commit_diff_file
)
}
let
(
:
merge_request
)
{
merge_request_context_commit_diff_file
.
merge_request_context_commit
.
merge_request
}
let
(
:
context_commits_diff
)
{
merge_request
.
context_commits_diff
}
let
(
:
sha1
)
{
"33f3729a45c02fc67d00adb1b8bca394b0e761d9"
}
let
(
:
sha2
)
{
"ae73cb07c9eeaf35924a10f713b364d32b2dd34f"
}
let
(
:
sha3
)
{
"0b4bc9a49b562e85de7cc9e834518ea6828729b9"
}
subject
{
context_commits_diff
}
let
(
:merge_request
)
do
create
(
:merge_request
)
do
|
merge_request
|
project
=
merge_request
.
project
mrcc1
=
create
(
:merge_request_context_commit
,
sha:
sha1
,
committed_date:
project
.
commit_by
(
oid:
sha1
).
committed_date
)
mrcc2
=
create
(
:merge_request_context_commit
,
sha:
sha2
,
committed_date:
project
.
commit_by
(
oid:
sha2
).
committed_date
)
mrcc3
=
create
(
:merge_request_context_commit
,
sha:
sha3
,
committed_date:
project
.
commit_by
(
oid:
sha3
).
committed_date
)
merge_request
.
merge_request_context_commits
<<
[
mrcc1
,
mrcc2
,
mrcc3
]
end
end
subject
{
merge_request
.
context_commits_diff
}
describe
".empty?"
do
it
'checks if empty'
do
expect
(
subject
.
empty?
).
to
be
(
false
)
end
end
describe
'.commits_count'
do
it
'reports commits count'
do
expect
(
subject
.
commits_count
).
to
be
(
1
)
expect
(
subject
.
commits_count
).
to
be
(
3
)
end
end
describe
'.diffs'
do
it
'returns instance of Gitlab::Diff::FileCollection::Compare'
do
expect
(
subject
.
diffs
).
to
be_a
(
Gitlab
::
Diff
::
FileCollection
::
Compare
)
end
it
'returns all diffs between first and last commits'
do
expect
(
subject
.
diffs
.
diff_files
.
size
).
to
be
(
5
)
end
end
describe
'.raw_diffs'
do
before
do
allow
(
subject
).
to
receive
(
:paths
).
and_return
([
"Gemfile.zip"
,
"files/images/6049019_460s.jpg"
,
"files/ruby/feature.rb"
])
end
it
'returns instance of Gitlab::Git::DiffCollection'
do
expect
(
subject
.
raw_diffs
).
to
be_a
(
Gitlab
::
Git
::
DiffCollection
)
end
it
'returns only diff for files changed in the context commits'
do
expect
(
subject
.
raw_diffs
.
size
).
to
be
(
3
)
end
end
describe
'.diff_refs'
do
it
'returns correct sha'
do
expect
(
subject
.
diff_refs
.
head_sha
).
to
eq
(
sha3
)
expect
(
subject
.
diff_refs
.
base_sha
).
to
eq
(
"913c66a37b4a45b9769037c55c2d238bd0942d2e"
)
end
end
end
spec/serializers/context_commits_diff_entity_spec.rb
View file @
5dab4ac8
...
...
@@ -3,17 +3,23 @@
require
'spec_helper'
RSpec
.
describe
ContextCommitsDiffEntity
do
let
(
:m
erge_request_context_commit_diff_file
)
{
create
(
:merge_request_context_commit_diff_file
)
}
let
(
:m
erge_request
)
{
merge_request_context_commit_diff_file
.
merge_request_context_commit
.
merge_request
}
let
(
:
context_commits_diff
)
{
merge_request
.
context_commits_diff
}
let
(
:m
rcc1
)
{
create
(
:merge_request_context_commit
,
sha:
"cfe32cf61b73a0d5e9f13e774abde7ff789b1660"
)
}
let
(
:m
rcc2
)
{
create
(
:merge_request_context_commit
,
sha:
"ae73cb07c9eeaf35924a10f713b364d32b2dd34f"
)
}
let
(
:
merge_request
)
{
create
(
:merge_request
)
{
|
merge_request
|
merge_request
.
merge_request_context_commits
<<
[
mrcc1
,
mrcc2
]
}
}
context
'as json'
do
describe
'.diff_files'
do
it
'returns diff files metadata'
do
payload
=
ContextCommitsDiffEntity
.
represent
(
context_commits_diff
).
as_json
subject
{
ContextCommitsDiffEntity
.
represent
(
merge_request
.
context_commits_diff
).
as_json
}
expect
(
payload
[
:commits_count
]).
to
eq
(
1
)
end
it
'exposes commits_count'
do
expect
(
subject
[
:commits_count
]).
to
eq
(
2
)
end
it
'exposes showing_context_commits_diff'
do
expect
(
subject
).
to
have_key
(
:showing_context_commits_diff
)
end
it
'exposes diffs_path'
do
expect
(
subject
[
:diffs_path
]).
to
match
(
/\/-\/merge_requests\/\d\/diffs\?only_context_commits=true$/
)
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