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
c900bbff
Commit
c900bbff
authored
Nov 05, 2021
by
Eduardo Bonet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding tests for ipynb diff transformation
parent
aec2c12e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
spec/lib/gitlab/diff/file_spec.rb
spec/lib/gitlab/diff/file_spec.rb
+28
-0
spec/presenters/blob_presenter_spec.rb
spec/presenters/blob_presenter_spec.rb
+37
-0
No files found.
spec/lib/gitlab/diff/file_spec.rb
View file @
c900bbff
...
...
@@ -51,6 +51,34 @@ RSpec.describe Gitlab::Diff::File do
project
.
commit
(
branch_name
).
diffs
.
diff_files
.
first
end
describe
'initialize'
do
context
'when file is ipynb'
do
let
(
:commit
)
{
project
.
commit
(
"f6b7a707"
)
}
let
(
:diff
)
{
commit
.
raw_diffs
.
first
}
let
(
:diff_file
)
{
described_class
.
new
(
diff
,
diff_refs:
commit
.
diff_refs
,
repository:
project
.
repository
)
}
context
'and :jupyter_clean_diffs is enabled'
do
before
do
stub_feature_flags
(
jupyter_clean_diffs:
true
)
end
it
'recreates the diff by transforming the files'
do
expect
(
diff_file
.
diff
.
diff
).
not_to
include
(
'"| Fake'
)
end
end
context
'but :jupyter_clean_diffs is disabled'
do
before
do
stub_feature_flags
(
jupyter_clean_diffs:
false
)
end
it
'does not recreate the diff'
do
expect
(
diff_file
.
diff
.
diff
).
to
include
(
'"| Fake'
)
end
end
end
end
describe
'#diff_lines'
do
let
(
:diff_lines
)
{
diff_file
.
diff_lines
}
...
...
spec/presenters/blob_presenter_spec.rb
View file @
c900bbff
...
...
@@ -121,6 +121,43 @@ RSpec.describe BlobPresenter do
end
end
describe
'#highlight_transformed'
do
context
'when blob is ipynb'
do
let
(
:blob
)
{
repository
.
blob_at
(
'f6b7a707'
,
'files/ipython/markdown-table.ipynb'
)
}
let
(
:git_blob
)
{
blob
.
__getobj__
}
it
'uses md as the transformed language'
do
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ipython/markdown-table.ipynb'
,
anything
,
plain:
nil
,
language:
'md'
)
presenter
.
highlight_transformed
end
it
'transforms the blob'
do
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ipython/markdown-table.ipynb'
,
include
(
"%%"
),
plain:
nil
,
language:
'md'
)
presenter
.
highlight_transformed
end
end
context
'when blob is other file type'
do
let
(
:git_blob
)
{
blob
.
__getobj__
}
before
do
allow
(
git_blob
)
.
to
receive
(
:data
)
.
and_return
(
"line one
\n
line two
\n
line 3"
)
allow
(
blob
).
to
receive
(
:language_from_gitattributes
).
and_return
(
'ruby'
)
end
it
'does not transform the file'
do
expect
(
Gitlab
::
Highlight
).
to
receive
(
:highlight
).
with
(
'files/ruby/regex.rb'
,
git_blob
.
data
,
plain:
nil
,
language:
'ruby'
)
presenter
.
highlight_transformed
end
end
end
describe
'#raw_plain_data'
do
let
(
:blob
)
{
repository
.
blob_at
(
'HEAD'
,
file
)
}
...
...
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