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
009659f9
Commit
009659f9
authored
Sep 24, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve snippet presenter spec with repo data
parent
aa840cc8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
39 deletions
+53
-39
spec/presenters/snippet_blob_presenter_spec.rb
spec/presenters/snippet_blob_presenter_spec.rb
+53
-39
No files found.
spec/presenters/snippet_blob_presenter_spec.rb
View file @
009659f9
...
...
@@ -3,70 +3,75 @@
require
'spec_helper'
RSpec
.
describe
SnippetBlobPresenter
do
let_it_be
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
)
}
let
(
:branch
)
{
snippet
.
default_branch
}
let
(
:blob
)
{
snippet
.
blobs
.
first
}
describe
'#rich_data'
do
let
(
:data_endpoint_url
)
{
"/-/snippets/
#{
snippet
.
id
}
/raw/
#{
branch
}
/
#{
file
}
"
}
before
do
allow_next_instance_of
(
described_class
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:current_user
).
and_return
(
nil
)
end
blob
.
name
=
File
.
basename
(
file
)
blob
.
path
=
file
end
subject
{
described_class
.
new
(
snippet
.
blob
).
rich_data
}
subject
{
described_class
.
new
(
blob
).
rich_data
}
context
'with PersonalSnippet'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
)
}
context
'when blob is binary'
do
it
'returns the HTML associated with the binary'
do
allow
(
snippet
).
to
receive
(
:blob
).
and_return
(
snippet
.
repository
.
blob_at
(
'master'
,
'files/images/logo-black.png'
))
let
(
:file
)
{
'files/images/logo-black.png'
}
let
(
:blob
)
{
blob_at
(
file
)
}
it
'returns the HTML associated with the binary'
do
expect
(
subject
).
to
include
(
'file-content image_file'
)
end
end
context
'with markdown format'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
file_name:
'test.md'
,
content:
'*foo*'
)
}
let
(
:file
)
{
'README.md'
}
let
(
:blob
)
{
blob_at
(
file
)
}
it
'returns rich markdown content'
do
expected
=
<<~
HTML
<div class="file-content md">
<p data-sourcepos="1:1-1:5" dir="auto"><em>foo</em></p>
</div>
HTML
expect
(
subject
).
to
eq
(
expected
)
expect
(
subject
).
to
include
(
'file-content md'
)
end
end
context
'with notebook format'
do
let
(
:
snippet
)
{
create
(
:personal_snippet
,
file_name:
'test.ipynb'
)
}
let
(
:
file
)
{
'test.ipynb'
}
it
'returns rich notebook content'
do
expect
(
subject
.
strip
).
to
eq
%Q(<div class="file-content" data-endpoint="
/-/snippets/
#{
snippet
.
id
}
/raw
" id="js-notebook-viewer"></div>)
expect
(
subject
.
strip
).
to
eq
%Q(<div class="file-content" data-endpoint="
#{
data_endpoint_url
}
" id="js-notebook-viewer"></div>)
end
end
context
'with openapi format'
do
let
(
:
snippet
)
{
create
(
:personal_snippet
,
file_name:
'openapi.yml'
)
}
let
(
:
file
)
{
'openapi.yml'
}
it
'returns rich openapi content'
do
expect
(
subject
).
to
eq
%Q(<div class="file-content" data-endpoint="
/-/snippets/
#{
snippet
.
id
}
/raw
" id="js-openapi-viewer"></div>
\n
)
expect
(
subject
).
to
eq
%Q(<div class="file-content" data-endpoint="
#{
data_endpoint_url
}
" id="js-openapi-viewer"></div>
\n
)
end
end
context
'with svg format'
do
let
(
:snippet
)
{
create
(
:personal_snippet
,
file_name:
'test.svg'
)
}
let
(
:file
)
{
'files/images/wm.svg'
}
let
(
:blob
)
{
blob_at
(
file
)
}
it
'returns rich svg content'
do
result
=
Nokogiri
::
HTML
::
DocumentFragment
.
parse
(
subject
)
image_tag
=
result
.
search
(
'img'
).
first
expect
(
image_tag
.
attr
(
'src'
)).
to
include
(
"data:
#{
snippet
.
blob
.
mime_type
}
;base64"
)
expect
(
image_tag
.
attr
(
'alt'
)).
to
eq
(
'test.svg'
)
expect
(
image_tag
.
attr
(
'src'
)).
to
include
(
"data:
#{
blob
.
mime_type
}
;base64"
)
expect
(
image_tag
.
attr
(
'alt'
)).
to
eq
(
File
.
basename
(
file
)
)
end
end
context
'with other format'
do
let
(
:
snippet
)
{
create
(
:personal_snippet
,
file_name:
'test'
)
}
let
(
:
file
)
{
'test'
}
it
'does not return no rich content'
do
expect
(
subject
).
to
be_nil
...
...
@@ -76,36 +81,41 @@ RSpec.describe SnippetBlobPresenter do
end
describe
'#plain_data'
do
let
(
:
snippet
)
{
build
(
:personal_snippet
)
}
let
(
:
blob
)
{
blob_at
(
file
)
}
subject
{
described_class
.
new
(
snippet
.
blob
).
plain_data
}
subject
{
described_class
.
new
(
blob
).
plain_data
}
it
'returns nil when the snippet
blob is binary'
do
allow
(
snippet
.
blob
).
to
receive
(
:binary?
).
and_return
(
true
)
context
'when
blob is binary'
do
let
(
:file
)
{
'files/images/logo-black.png'
}
it
'returns nil'
do
expect
(
subject
).
to
be_nil
end
end
it
'returns plain content when snippet file is markup'
do
snippet
.
file_name
=
'test.md'
snippet
.
content
=
'*foo*'
context
'when blob is markup'
do
let
(
:file
)
{
'README.md'
}
expect
(
subject
).
to
eq
'<span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span>'
it
'returns plain content'
do
expect
(
subject
).
to
include
(
'<span id="LC1" class="line" lang="markdown">'
)
end
end
it
'returns highlighted syntax content'
do
snippet
.
file_name
=
'test.rb'
snippet
.
content
=
'class Foo;end'
context
'when blob has syntax'
do
let
(
:file
)
{
'files/ruby/regex.rb'
}
it
'returns highlighted syntax content'
do
expect
(
subject
)
.
to
eq
'<span id="LC1" class="line" lang="ruby"><span class="k">class</span> <span class="nc">Foo</span><span class="p">;</span><span class="k">end</span></span>'
.
to
include
'<span id="LC1" class="line" lang="ruby"><span class="k">module</span> <span class="nn">Gitlab</span>'
end
end
it
'returns plain text highlighted content'
do
snippet
.
file_name
=
'test'
snippet
.
content
=
'foo'
context
'when blob has plain data'
do
let
(
:file
)
{
'LICENSE'
}
expect
(
subject
).
to
eq
'<span id="LC1" class="line" lang="plaintext">foo</span>'
it
'returns plain text highlighted content'
do
expect
(
subject
).
to
include
(
'<span id="LC1" class="line" lang="plaintext">The MIT License (MIT)</span>'
)
end
end
end
...
...
@@ -179,4 +189,8 @@ RSpec.describe SnippetBlobPresenter do
end
end
end
def
blob_at
(
path
)
snippet
.
repository
.
blob_at
(
branch
,
path
)
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