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
2ea026bd
Commit
2ea026bd
authored
Sep 16, 2021
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Emoji methods to rely on TanukiEmoji and removed unused ones
parent
52be0404
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
86 deletions
+27
-86
app/models/custom_emoji.rb
app/models/custom_emoji.rb
+1
-1
app/services/award_emojis/base_service.rb
app/services/award_emojis/base_service.rb
+1
-1
lib/gitlab/emoji.rb
lib/gitlab/emoji.rb
+0
-28
spec/lib/gitlab/emoji_spec.rb
spec/lib/gitlab/emoji_spec.rb
+0
-56
spec/services/award_emojis/base_service_spec.rb
spec/services/award_emojis/base_service_spec.rb
+25
-0
No files found.
app/models/custom_emoji.rb
View file @
2ea026bd
...
...
@@ -31,7 +31,7 @@ class CustomEmoji < ApplicationRecord
private
def
valid_emoji_name
if
Gitlab
::
Emoji
.
emoji_exists?
(
name
)
if
TanukiEmoji
.
find_by_alpha_code
(
name
)
errors
.
add
(
:name
,
_
(
'%{name} is already being used for another emoji'
)
%
{
name:
self
.
name
})
end
end
...
...
app/services/award_emojis/base_service.rb
View file @
2ea026bd
...
...
@@ -14,7 +14,7 @@ module AwardEmojis
private
def
normalize_name
(
name
)
Gitlab
::
Emoji
.
normalize_emoji_name
(
name
)
TanukiEmoji
.
find_by_alpha_code
(
name
)
&
.
name
||
name
end
# Provide more error state data than what BaseService allows.
...
...
lib/gitlab/emoji.rb
View file @
2ea026bd
...
...
@@ -4,30 +4,6 @@ module Gitlab
module
Emoji
extend
self
def
emojis_by_moji
TanukiEmoji
.
index
.
instance_variable_get
(
:@codepoints_index
)
end
def
emojis_unicodes
emojis_by_moji
.
keys
end
def
emojis_aliases
@emoji_aliases
||=
Gitlab
::
Json
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'fixtures'
,
'emojis'
,
'aliases.json'
)))
end
def
emoji_filename
(
name
)
TanukiEmoji
.
find_by_alpha_code
(
name
).
image_name
end
def
emoji_unicode_filename
(
moji
)
TanukiEmoji
.
find_by_codepoints
(
moji
).
image_name
end
def
normalize_emoji_name
(
name
)
emojis_aliases
[
name
]
||
name
end
def
emoji_image_tag
(
name
,
src
)
image_options
=
{
class:
'emoji'
,
...
...
@@ -42,10 +18,6 @@ module Gitlab
ActionController
::
Base
.
helpers
.
tag
(
:img
,
image_options
)
end
def
emoji_exists?
(
name
)
TanukiEmoji
.
find_by_alpha_code
(
name
)
end
# CSS sprite fallback takes precedence over image fallback
# @param [TanukiEmoji::Character] emoji
# @param [Hash] options
...
...
spec/lib/gitlab/emoji_spec.rb
View file @
2ea026bd
...
...
@@ -3,48 +3,6 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Emoji
do
let_it_be
(
:emojis_by_moji
)
{
TanukiEmoji
.
index
.
all
.
index_by
(
&
:codepoints
)
}
let_it_be
(
:emojis_aliases
)
{
Gitlab
::
Json
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'fixtures'
,
'emojis'
,
'aliases.json'
)))
}
describe
'.emojis_aliases'
do
it
'returns emoji aliases'
do
emoji_aliases
=
described_class
.
emojis_aliases
expect
(
emoji_aliases
).
to
eq
(
emojis_aliases
)
end
end
describe
'.emoji_filename'
do
it
'returns emoji filename'
do
# "100" => {"unicode"=>"1F4AF"...}
emoji_filename
=
described_class
.
emoji_filename
(
'100'
)
expect
(
emoji_filename
).
to
eq
(
"emoji_u
#{
TanukiEmoji
.
find_by_alpha_code
(
'100'
).
hex
}
.png"
)
end
end
describe
'.emoji_unicode_filename'
do
it
'returns emoji unicode filename'
do
emoji_unicode_filename
=
described_class
.
emoji_unicode_filename
(
'💯'
)
expect
(
emoji_unicode_filename
).
to
eq
(
"emoji_u
#{
TanukiEmoji
.
find_by_codepoints
(
'💯'
).
hex
}
.png"
)
end
end
describe
'.normalize_emoji_name'
do
it
'returns same name if not found in aliases'
do
emoji_name
=
described_class
.
normalize_emoji_name
(
'random'
)
expect
(
emoji_name
).
to
eq
(
'random'
)
end
it
'returns name if name found in aliases'
do
emoji_name
=
described_class
.
normalize_emoji_name
(
'small_airplane'
)
expect
(
emoji_name
).
to
eq
(
emojis_aliases
[
'small_airplane'
])
end
end
describe
'.emoji_image_tag'
do
it
'returns emoji image tag'
do
emoji_image
=
described_class
.
emoji_image_tag
(
'emoji_one'
,
'src_url'
)
...
...
@@ -62,20 +20,6 @@ RSpec.describe Gitlab::Emoji do
end
end
describe
'.emoji_exists?'
do
it
'returns true if the name exists'
do
emoji_exists
=
described_class
.
emoji_exists?
(
'100'
)
expect
(
emoji_exists
).
to
be_truthy
end
it
'returns false if the name does not exist'
do
emoji_exists
=
described_class
.
emoji_exists?
(
'random'
)
expect
(
emoji_exists
).
to
be_falsey
end
end
describe
'.gl_emoji_tag'
do
it
'returns gl emoji tag if emoji is found'
do
emoji
=
TanukiEmoji
.
find_by_alpha_code
(
'small_airplane'
)
...
...
spec/services/award_emojis/base_service_spec.rb
0 → 100644
View file @
2ea026bd
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
AwardEmojis
::
BaseService
do
let
(
:awardable
)
{
build
(
:note
)
}
let
(
:current_user
)
{
build
(
:user
)
}
describe
'.initialize'
do
subject
{
described_class
}
it
'uses same emoji name if not an alias'
do
emoji_name
=
'horse'
expect
(
subject
.
new
(
awardable
,
emoji_name
,
current_user
).
name
).
to
eq
(
emoji_name
)
end
it
'uses emoji original name if its an alias'
do
emoji_alias
=
'small_airplane'
emoji_name
=
'airplane_small'
expect
(
subject
.
new
(
awardable
,
emoji_alias
,
current_user
).
name
).
to
eq
(
emoji_name
)
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