Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
2468798f0306
Commit
05bbad58
authored
May 11, 2016
by
Robert Speicher
Browse files
Clean up EventsHelper spec
parent
86b6bf265062
Changes
1
Hide whitespace changes
Inline
Side-by-side
spec/helpers/events_helper_spec.rb
View file @
2468798f
require
'spec_helper'
describe
EventsHelper
do
include
ApplicationHelper
include
GitlabMarkdownHelper
describe
'#event_note'
do
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
double
)
end
let
(
:current_user
)
{
create
(
:user
,
email:
"current@email.com"
)
}
it
'should display one line of plain text without alteration'
do
input
=
'A short, plain note'
expect
(
helper
.
event_note
(
input
)).
to
match
(
input
)
expect
(
helper
.
event_note
(
input
)).
not_to
match
(
/\.\.\.\z/
)
end
it
'should display one line of plain text without alteration'
do
input
=
'A short, plain note'
expect
(
event_note
(
input
)).
to
match
(
input
)
expect
(
event_note
(
input
)).
not_to
match
(
/\.\.\.\z/
)
end
it
'should display inline code'
do
input
=
'A note with `inline code`'
expected
=
'A note with <code>inline code</code>'
it
'should display inline code'
do
input
=
'A note with `inline code`'
expected
=
'A note with <code>inline code</code>'
expect
(
helper
.
event_note
(
input
)).
to
match
(
expected
)
end
expect
(
event_note
(
input
)).
to
match
(
expected
)
end
it
'should truncate a note with multiple paragraphs'
do
input
=
"Paragraph 1
\n\n
Paragraph 2"
expected
=
'Paragraph 1...'
it
'should truncate a note with multiple paragraphs'
do
input
=
"Paragraph 1
\n\n
Paragraph 2"
expected
=
'Paragraph 1...'
expect
(
helper
.
event_note
(
input
)).
to
match
(
expected
)
end
expect
(
event_note
(
input
)).
to
match
(
expected
)
end
it
'should display the first line of a code block'
do
input
=
"```
\n
Code block
\n
with two lines
\n
```"
expected
=
%r{<pre.+><code>Code block
\.\.\.
</code></pre>}
it
'should display the first line of a code block'
do
input
=
"```
\n
Code block
\n
with two lines
\n
```"
expected
=
%r{<pre.+><code>Code block
\.\.\.
</code></pre>}
expect
(
helper
.
event_note
(
input
)).
to
match
(
expected
)
end
expect
(
event_note
(
input
)).
to
match
(
expected
)
end
it
'should truncate a single long line of text'
do
text
=
'The quick brown fox jumped over the lazy dog twice'
# 50 chars
input
=
text
*
4
expected
=
(
text
*
2
).
sub
(
/.{3}/
,
'...'
)
it
'should truncate a single long line of text'
do
text
=
'The quick brown fox jumped over the lazy dog twice'
# 50 chars
input
=
"
#{
text
}#{
text
}#{
text
}#{
text
}
"
# 200 chars
expected
=
"
#{
text
}#{
text
}
"
.
sub
(
/.{3}/
,
'...'
)
expect
(
helper
.
event_note
(
input
)).
to
match
(
expected
)
end
expect
(
event_note
(
input
)).
to
match
(
expected
)
end
it
'should preserve a link href when link text is truncated'
do
text
=
'The quick brown fox jumped over the lazy dog'
# 44 chars
input
=
"
#{
text
}#{
text
}#{
text
}
"
# 133 chars
link_url
=
'http://example.com/foo/bar/baz'
# 30 chars
input
<<
link_url
expected_link_text
=
'http://example...</a>'
it
'should preserve a link href when link text is truncated'
do
text
=
'The quick brown fox jumped over the lazy dog'
# 44 chars
input
=
"
#{
text
}#{
text
}#{
text
}
"
# 133 chars
link_url
=
'http://example.com/foo/bar/baz'
# 30 chars
input
<<
link_url
expected_link_text
=
'http://example...</a>'
expect
(
event_note
(
input
)).
to
match
(
link_url
)
expect
(
event_note
(
input
)).
to
match
(
expected_link_text
)
end
expect
(
helper
.
event_note
(
input
)).
to
match
(
link_url
)
expect
(
helper
.
event_note
(
input
)).
to
match
(
expected_link_text
)
end
it
'should preserve code color scheme'
do
input
=
"```ruby
\n
def test
\n
'hello world'
\n
end
\n
```"
expected
=
'<pre class="code highlight js-syntax-highlight ruby">'
\
"<code><span class=
\"
k
\"
>def</span> <span class=
\"
nf
\"
>test</span>
\n
"
\
" <span class=
\"
s1
\"
>
\'
hello world
\'
</span>
\n
"
\
"<span class=
\"
k
\"
>end</span>"
\
'</code></pre>'
expect
(
event_note
(
input
)).
to
eq
(
expected
)
it
'should preserve code color scheme'
do
input
=
"```ruby
\n
def test
\n
'hello world'
\n
end
\n
```"
expected
=
'<pre class="code highlight js-syntax-highlight ruby">'
\
"<code><span class=
\"
k
\"
>def</span> <span class=
\"
nf
\"
>test</span>
\n
"
\
" <span class=
\"
s1
\"
>
\'
hello world
\'
</span>
\n
"
\
"<span class=
\"
k
\"
>end</span>"
\
'</code></pre>'
expect
(
helper
.
event_note
(
input
)).
to
eq
(
expected
)
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