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
5f04d84b
Commit
5f04d84b
authored
Mar 11, 2021
by
Rajendra Kadam
Committed by
Peter Leitzen
Mar 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move common specs to shared examples
Use be_empty wherever equated with 0
parent
79e19c5e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
60 deletions
+54
-60
spec/lib/banzai/filter/custom_emoji_filter_spec.rb
spec/lib/banzai/filter/custom_emoji_filter_spec.rb
+4
-31
spec/lib/banzai/filter/emoji_filter_spec.rb
spec/lib/banzai/filter/emoji_filter_spec.rb
+4
-29
spec/support/shared_examples/banzai/filters/emoji_shared_examples.rb
...t/shared_examples/banzai/filters/emoji_shared_examples.rb
+46
-0
No files found.
spec/lib/banzai/filter/custom_emoji_filter_spec.rb
View file @
5f04d84b
...
@@ -10,6 +10,10 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
...
@@ -10,6 +10,10 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
let_it_be
(
:custom_emoji
)
{
create
(
:custom_emoji
,
name:
'tanuki'
,
group:
group
)
}
let_it_be
(
:custom_emoji
)
{
create
(
:custom_emoji
,
name:
'tanuki'
,
group:
group
)
}
let_it_be
(
:custom_emoji2
)
{
create
(
:custom_emoji
,
name:
'happy_tanuki'
,
group:
group
,
file:
'https://foo.bar/happy.png'
)
}
let_it_be
(
:custom_emoji2
)
{
create
(
:custom_emoji
,
name:
'happy_tanuki'
,
group:
group
,
file:
'https://foo.bar/happy.png'
)
}
it_behaves_like
'emoji filter'
do
let
(
:emoji_name
)
{
':tanuki:'
}
end
it
'replaces supported name custom emoji'
do
it
'replaces supported name custom emoji'
do
doc
=
filter
(
'<p>:tanuki:</p>'
,
project:
project
)
doc
=
filter
(
'<p>:tanuki:</p>'
,
project:
project
)
...
@@ -17,25 +21,12 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
...
@@ -17,25 +21,12 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
expect
(
doc
.
css
(
'gl-emoji img'
).
size
).
to
eq
1
expect
(
doc
.
css
(
'gl-emoji img'
).
size
).
to
eq
1
end
end
it
'ignores non existent custom emoji'
do
exp
=
'<p>:foo:</p>'
doc
=
filter
(
exp
)
expect
(
doc
.
to_html
).
to
eq
(
exp
)
end
it
'correctly uses the custom emoji URL'
do
it
'correctly uses the custom emoji URL'
do
doc
=
filter
(
'<p>:tanuki:</p>'
)
doc
=
filter
(
'<p>:tanuki:</p>'
)
expect
(
doc
.
css
(
'img'
).
first
.
attributes
[
'src'
].
value
).
to
eq
(
custom_emoji
.
file
)
expect
(
doc
.
css
(
'img'
).
first
.
attributes
[
'src'
].
value
).
to
eq
(
custom_emoji
.
file
)
end
end
it
'matches with adjacent text'
do
doc
=
filter
(
'tanuki (:tanuki:)'
)
expect
(
doc
.
css
(
'img'
).
size
).
to
eq
1
end
it
'matches multiple same custom emoji'
do
it
'matches multiple same custom emoji'
do
doc
=
filter
(
':tanuki: :tanuki:'
)
doc
=
filter
(
':tanuki: :tanuki:'
)
...
@@ -54,18 +45,6 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
...
@@ -54,18 +45,6 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
expect
(
doc
.
css
(
'img'
).
size
).
to
be
0
expect
(
doc
.
css
(
'img'
).
size
).
to
be
0
end
end
it
'keeps whitespace intact'
do
doc
=
filter
(
'This deserves a :tanuki:, big time.'
)
expect
(
doc
.
to_html
).
to
match
(
/^This deserves a <gl-emoji.+>, big time\.\z/
)
end
it
'does not match emoji in a string'
do
doc
=
filter
(
"'2a00:tanuki:100::1'"
)
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
0
end
it
'does not do N+1 query'
do
it
'does not do N+1 query'
do
create
(
:custom_emoji
,
name:
'party-parrot'
,
group:
group
)
create
(
:custom_emoji
,
name:
'party-parrot'
,
group:
group
)
...
@@ -77,10 +56,4 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
...
@@ -77,10 +56,4 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
filter
(
'<p>:tanuki: :party-parrot:</p>'
)
filter
(
'<p>:tanuki: :party-parrot:</p>'
)
end
.
not_to
exceed_all_query_limit
(
control_count
.
count
)
end
.
not_to
exceed_all_query_limit
(
control_count
.
count
)
end
end
context
'ancestor tags'
do
let
(
:emoji_name
)
{
':tanuki:'
}
it_behaves_like
'ignored ancestor tags'
end
end
end
spec/lib/banzai/filter/emoji_filter_spec.rb
View file @
5f04d84b
...
@@ -5,6 +5,10 @@ require 'spec_helper'
...
@@ -5,6 +5,10 @@ require 'spec_helper'
RSpec
.
describe
Banzai
::
Filter
::
EmojiFilter
do
RSpec
.
describe
Banzai
::
Filter
::
EmojiFilter
do
include
FilterSpecHelper
include
FilterSpecHelper
it_behaves_like
'emoji filter'
do
let
(
:emoji_name
)
{
':+1:'
}
end
it
'replaces supported name emoji'
do
it
'replaces supported name emoji'
do
doc
=
filter
(
'<p>:heart:</p>'
)
doc
=
filter
(
'<p>:heart:</p>'
)
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
text
).
to
eq
'❤'
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
text
).
to
eq
'❤'
...
@@ -15,12 +19,6 @@ RSpec.describe Banzai::Filter::EmojiFilter do
...
@@ -15,12 +19,6 @@ RSpec.describe Banzai::Filter::EmojiFilter do
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
text
).
to
eq
'❤'
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
text
).
to
eq
'❤'
end
end
it
'ignores unsupported emoji'
do
exp
=
act
=
'<p>:foo:</p>'
doc
=
filter
(
act
)
expect
(
doc
.
to_html
).
to
match
Regexp
.
escape
(
exp
)
end
it
'ignores unicode versions of trademark, copyright, and registered trademark'
do
it
'ignores unicode versions of trademark, copyright, and registered trademark'
do
exp
=
act
=
'<p>™ © ®</p>'
exp
=
act
=
'<p>™ © ®</p>'
doc
=
filter
(
act
)
doc
=
filter
(
act
)
...
@@ -65,11 +63,6 @@ RSpec.describe Banzai::Filter::EmojiFilter do
...
@@ -65,11 +63,6 @@ RSpec.describe Banzai::Filter::EmojiFilter do
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
1
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
1
end
end
it
'matches with adjacent text'
do
doc
=
filter
(
'+1 (:+1:)'
)
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
1
end
it
'unicode matches with adjacent text'
do
it
'unicode matches with adjacent text'
do
doc
=
filter
(
'+1 (👍)'
)
doc
=
filter
(
'+1 (👍)'
)
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
1
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
1
...
@@ -90,12 +83,6 @@ RSpec.describe Banzai::Filter::EmojiFilter do
...
@@ -90,12 +83,6 @@ RSpec.describe Banzai::Filter::EmojiFilter do
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
6
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
6
end
end
it
'does not match emoji in a string'
do
doc
=
filter
(
"'2a00:a4c0:100::1'"
)
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
0
end
it
'has a data-name attribute'
do
it
'has a data-name attribute'
do
doc
=
filter
(
':-1:'
)
doc
=
filter
(
':-1:'
)
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
attr
(
'data-name'
)).
to
eq
'thumbsdown'
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
attr
(
'data-name'
)).
to
eq
'thumbsdown'
...
@@ -106,21 +93,9 @@ RSpec.describe Banzai::Filter::EmojiFilter do
...
@@ -106,21 +93,9 @@ RSpec.describe Banzai::Filter::EmojiFilter do
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
attr
(
'data-unicode-version'
)).
to
eq
'6.0'
expect
(
doc
.
css
(
'gl-emoji'
).
first
.
attr
(
'data-unicode-version'
)).
to
eq
'6.0'
end
end
it
'keeps whitespace intact'
do
doc
=
filter
(
'This deserves a :+1:, big time.'
)
expect
(
doc
.
to_html
).
to
match
(
/^This deserves a <gl-emoji.+>, big time\.\z/
)
end
it
'unicode keeps whitespace intact'
do
it
'unicode keeps whitespace intact'
do
doc
=
filter
(
'This deserves a 🎱, big time.'
)
doc
=
filter
(
'This deserves a 🎱, big time.'
)
expect
(
doc
.
to_html
).
to
match
(
/^This deserves a <gl-emoji.+>, big time\.\z/
)
expect
(
doc
.
to_html
).
to
match
(
/^This deserves a <gl-emoji.+>, big time\.\z/
)
end
end
context
'ancestor tags'
do
let
(
:emoji_name
)
{
':see_no_evil:'
}
it_behaves_like
'ignored ancestor tags'
end
end
end
spec/support/shared_examples/banzai/filters/
ignored_tags_
emoji_shared_examples.rb
→
spec/support/shared_examples/banzai/filters/emoji_shared_examples.rb
View file @
5f04d84b
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'ignored ancestor tags'
do
RSpec
.
shared_examples
'emoji filter'
do
it
'keeps whitespace intact'
do
doc
=
filter
(
"This deserves a
#{
emoji_name
}
, big time."
)
expect
(
doc
.
to_html
).
to
match
(
/^This deserves a <gl-emoji.+>, big time\.\z/
)
end
it
'does not match emoji in a string'
do
doc
=
filter
(
"'2a00:a4c0
#{
emoji_name
}
:1'"
)
expect
(
doc
.
css
(
'gl-emoji'
)).
to
be_empty
end
it
'ignores non existent/unsupported emoji'
do
exp
=
'<p>:foo:</p>'
doc
=
filter
(
exp
)
expect
(
doc
.
to_html
).
to
eq
(
exp
)
end
it
'matches with adjacent text'
do
doc
=
filter
(
"
#{
emoji_name
.
delete
(
':'
)
}
(
#{
emoji_name
}
)"
)
expect
(
doc
.
css
(
'gl-emoji'
).
size
).
to
eq
1
end
it
'does not match emoji in a pre tag'
do
it
'does not match emoji in a pre tag'
do
doc
=
filter
(
"<p><pre>
#{
emoji_name
}
</pre></p>"
)
doc
=
filter
(
"<p><pre>
#{
emoji_name
}
</pre></p>"
)
expect
(
doc
.
css
(
'img'
)
.
size
).
to
eq
0
expect
(
doc
.
css
(
'img'
)
).
to
be_empty
end
end
it
'does not match emoji in code tag'
do
it
'does not match emoji in code tag'
do
doc
=
filter
(
"<p><code>
#{
emoji_name
}
wow</code></p>"
)
doc
=
filter
(
"<p><code>
#{
emoji_name
}
wow</code></p>"
)
expect
(
doc
.
css
(
'img'
)
.
size
).
to
eq
0
expect
(
doc
.
css
(
'img'
)
).
to
be_empty
end
end
it
'does not match emoji in tt tag'
do
it
'does not match emoji in tt tag'
do
doc
=
filter
(
"<p><tt>
#{
emoji_name
}
yes!</tt></p>"
)
doc
=
filter
(
"<p><tt>
#{
emoji_name
}
yes!</tt></p>"
)
expect
(
doc
.
css
(
'img'
)
.
size
).
to
eq
0
expect
(
doc
.
css
(
'img'
)
).
to
be_empty
end
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