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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
870969a1
Commit
870969a1
authored
Apr 21, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More cleanup of gitlab_markdown_helper_spec
parent
f9c0f078
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
98 deletions
+92
-98
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+92
-98
No files found.
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
870969a1
...
@@ -2,12 +2,6 @@ require 'spec_helper'
...
@@ -2,12 +2,6 @@ require 'spec_helper'
describe
GitlabMarkdownHelper
do
describe
GitlabMarkdownHelper
do
include
ApplicationHelper
include
ApplicationHelper
include
IssuesHelper
# TODO: Properly test this
def
can?
(
*
)
true
end
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:project
)
{
create
(
:project
)
}
...
@@ -20,16 +14,9 @@ describe GitlabMarkdownHelper do
...
@@ -20,16 +14,9 @@ describe GitlabMarkdownHelper do
# Helper expects a current_user method.
# Helper expects a current_user method.
let
(
:current_user
)
{
user
}
let
(
:current_user
)
{
user
}
def
url_helper
(
image_name
)
File
.
join
(
root_url
,
'assets'
,
image_name
)
end
before
do
before
do
# Helper expects a @project instance variable
# Helper expects a @project instance variable
@project
=
project
@project
=
project
@ref
=
'markdown'
@repository
=
project
.
repository
@request
.
host
=
Gitlab
.
config
.
gitlab
.
host
end
end
describe
"#gfm"
do
describe
"#gfm"
do
...
@@ -176,6 +163,9 @@ describe GitlabMarkdownHelper do
...
@@ -176,6 +163,9 @@ describe GitlabMarkdownHelper do
actual
=
link_to_gfm
(
"This should finally fix #
#{
issues
[
0
].
iid
}
and #
#{
issues
[
1
].
iid
}
for real"
,
commit_path
)
actual
=
link_to_gfm
(
"This should finally fix #
#{
issues
[
0
].
iid
}
and #
#{
issues
[
1
].
iid
}
for real"
,
commit_path
)
doc
=
Nokogiri
::
HTML
.
parse
(
actual
)
doc
=
Nokogiri
::
HTML
.
parse
(
actual
)
# Make sure we didn't create invalid markup
expect
(
doc
.
errors
).
to
be_empty
# Leading commit link
# Leading commit link
expect
(
doc
.
css
(
'a'
)[
0
].
attr
(
'href'
)).
to
eq
commit_path
expect
(
doc
.
css
(
'a'
)[
0
].
attr
(
'href'
)).
to
eq
commit_path
expect
(
doc
.
css
(
'a'
)[
0
].
text
).
to
eq
'This should finally fix '
expect
(
doc
.
css
(
'a'
)[
0
].
text
).
to
eq
'This should finally fix '
...
@@ -219,17 +209,6 @@ describe GitlabMarkdownHelper do
...
@@ -219,17 +209,6 @@ describe GitlabMarkdownHelper do
describe
"#markdown"
do
describe
"#markdown"
do
# TODO (rspeicher) - This block tests multiple different contexts. Break this up!
# TODO (rspeicher) - This block tests multiple different contexts. Break this up!
# REFERENCES (PART TWO: THE REVENGE) ---------------------------------------
it
"should handle references in headers"
do
actual
=
"
\n
# Working around #
#{
issue
.
iid
}
\n
## Apply !
#{
merge_request
.
iid
}
"
expect
(
markdown
(
actual
,
no_header_anchors:
true
)).
to
match
(
%r{<h1[^<]*>Working around <a.+>#
#{
issue
.
iid
}
</a></h1>}
)
expect
(
markdown
(
actual
,
no_header_anchors:
true
)).
to
match
(
%r{<h2[^<]*>Apply <a.+>!
#{
merge_request
.
iid
}
</a></h2>}
)
end
it
"should add ids and links to headers"
do
it
"should add ids and links to headers"
do
# Test every rule except nested tags.
# Test every rule except nested tags.
text
=
'..Ab_c-d. e..'
text
=
'..Ab_c-d. e..'
...
@@ -245,6 +224,17 @@ describe GitlabMarkdownHelper do
...
@@ -245,6 +224,17 @@ describe GitlabMarkdownHelper do
)
)
end
end
# REFERENCES (PART TWO: THE REVENGE) ---------------------------------------
it
"should handle references in headers"
do
actual
=
"
\n
# Working around #
#{
issue
.
iid
}
\n
## Apply !
#{
merge_request
.
iid
}
"
expect
(
markdown
(
actual
,
no_header_anchors:
true
)).
to
match
(
%r{<h1[^<]*>Working around <a.+>#
#{
issue
.
iid
}
</a></h1>}
)
expect
(
markdown
(
actual
,
no_header_anchors:
true
)).
to
match
(
%r{<h2[^<]*>Apply <a.+>!
#{
merge_request
.
iid
}
</a></h2>}
)
end
it
"should handle references in <em>"
do
it
"should handle references in <em>"
do
actual
=
"Apply _!
#{
merge_request
.
iid
}
_ ASAP"
actual
=
"Apply _!
#{
merge_request
.
iid
}
_ ASAP"
...
@@ -260,16 +250,15 @@ describe GitlabMarkdownHelper do
...
@@ -260,16 +250,15 @@ describe GitlabMarkdownHelper do
target_html
=
"<pre class=
\"
code highlight white plaintext
\"
><code>some code from $
#{
snippet
.
id
}
\n
here too
\n
</code></pre>
\n
"
target_html
=
"<pre class=
\"
code highlight white plaintext
\"
><code>some code from $
#{
snippet
.
id
}
\n
here too
\n
</code></pre>
\n
"
expect
(
helper
.
markdown
(
"
\n
some code from $
#{
snippet
.
id
}
\n
here too
\n
"
)).
expect
(
markdown
(
"
\n
some code from $
#{
snippet
.
id
}
\n
here too
\n
"
)).
to
eq
(
target_html
)
to
eq
(
target_html
)
expect
(
helper
.
markdown
(
"
\n
```
\n
some code from $
#{
snippet
.
id
}
\n
here too
\n
```
\n
"
)).
expect
(
markdown
(
"
\n
```
\n
some code from $
#{
snippet
.
id
}
\n
here too
\n
```
\n
"
)).
to
eq
(
target_html
)
to
eq
(
target_html
)
end
end
it
"should leave inline code untouched"
do
it
"should leave inline code untouched"
do
expect
(
markdown
(
"
\n
Don't use `$
#{
snippet
.
id
}
` here.
\n
"
)).
to
eq
(
expect
(
markdown
(
"Don't use `$
#{
snippet
.
id
}
` here."
)).
"<p>Don't use <code>$
#{
snippet
.
id
}
</code> here.</p>
\n
"
to
eq
"<p>Don't use <code>$
#{
snippet
.
id
}
</code> here.</p>
\n
"
)
end
end
# REF-LIKE AUTOLINKS? -----------------------------------------------------
# REF-LIKE AUTOLINKS? -----------------------------------------------------
...
@@ -287,13 +276,16 @@ describe GitlabMarkdownHelper do
...
@@ -287,13 +276,16 @@ describe GitlabMarkdownHelper do
expect
(
markdown
(
"screen shot: ![some image](http://example.tld/#!
#{
merge_request
.
iid
}
)"
)).
to
eq
(
"<p>screen shot: <img src=
\"
http://example.tld/#!
#{
merge_request
.
iid
}
\"
alt=
\"
some image
\"
></p>
\n
"
)
expect
(
markdown
(
"screen shot: ![some image](http://example.tld/#!
#{
merge_request
.
iid
}
)"
)).
to
eq
(
"<p>screen shot: <img src=
\"
http://example.tld/#!
#{
merge_request
.
iid
}
\"
alt=
\"
some image
\"
></p>
\n
"
)
end
end
it
"should generate absolute urls for refs"
do
expect
(
markdown
(
"#
#{
issue
.
iid
}
"
)).
to
include
(
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
))
end
# RELATIVE URLS -----------------------------------------------------------
# RELATIVE URLS -----------------------------------------------------------
# TODO (rspeicher): These belong in a relative link filter spec
# TODO (rspeicher): These belong in a relative link filter spec
context
'relative links'
do
context
'with a valid repository'
do
before
do
@repository
=
project
.
repository
@ref
=
'markdown'
end
it
"should handle relative urls for a file in master"
do
it
"should handle relative urls for a file in master"
do
actual
=
"[GitLab API doc](doc/api/README.md)
\n
"
actual
=
"[GitLab API doc](doc/api/README.md)
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/blob/
#{
@ref
}
/doc/api/README.md
\"
>GitLab API doc</a></p>
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/blob/
#{
@ref
}
/doc/api/README.md
\"
>GitLab API doc</a></p>
\n
"
...
@@ -346,8 +338,24 @@ describe GitlabMarkdownHelper do
...
@@ -346,8 +338,24 @@ describe GitlabMarkdownHelper do
actual
=
'<dl><dt>Term</dt><dd>Definition</dd></dl>'
actual
=
'<dl><dt>Term</dt><dd>Definition</dd></dl>'
expect
(
markdown
(
actual
)).
to
match
(
actual
)
expect
(
markdown
(
actual
)).
to
match
(
actual
)
end
end
end
context
'with an empty repository'
do
before
do
@project
=
create
(
:empty_project
)
@repository
=
@project
.
repository
end
it
"should not touch relative urls"
do
actual
=
"[GitLab API doc][GitLab readme]
\n
[GitLab readme]: doc/api/README.md
\n
"
expected
=
"<p><a href=
\"
doc/api/README.md
\"
>GitLab API doc</a></p>
\n
"
expect
(
markdown
(
actual
)).
to
match
(
expected
)
end
end
end
# SANITIZATION ------------------------------------------------------------
# SANITIZATION ------------------------------------------------------------
# TODO (rspeicher): These are testing SanitizationFilter, not `markdown`
it
'should sanitize tags that are not whitelisted'
do
it
'should sanitize tags that are not whitelisted'
do
actual
=
'<textarea>no inputs allowed</textarea> <blink>no blinks</blink>'
actual
=
'<textarea>no inputs allowed</textarea> <blink>no blinks</blink>'
...
@@ -375,20 +383,6 @@ describe GitlabMarkdownHelper do
...
@@ -375,20 +383,6 @@ describe GitlabMarkdownHelper do
end
end
end
end
# TODO (rspeicher): This should be a context of relative link specs, not its own thing
describe
'markdown for empty repository'
do
before
do
@project
=
create
(
:empty_project
)
@repository
=
@project
.
repository
end
it
"should not touch relative urls"
do
actual
=
"[GitLab API doc][GitLab readme]
\n
[GitLab readme]: doc/api/README.md
\n
"
expected
=
"<p><a href=
\"
doc/api/README.md
\"
>GitLab API doc</a></p>
\n
"
expect
(
markdown
(
actual
)).
to
match
(
expected
)
end
end
describe
'#render_wiki_content'
do
describe
'#render_wiki_content'
do
before
do
before
do
@wiki
=
double
(
'WikiPage'
)
@wiki
=
double
(
'WikiPage'
)
...
...
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