FIX: do not include group less emojis in standard list (#18659)

This commit is contained in:
Joffrey JAFFEUX 2022-10-19 09:53:56 +02:00 committed by GitHub
parent 437de6338e
commit a705e4815f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -88,13 +88,14 @@ class Emoji
def self.create_from_db_item(emoji)
name = emoji["name"]
return unless group = groups[name]
filename = emoji['filename'] || name
Emoji.new.tap do |e|
e.name = name
e.tonable = Emoji.tonable_emojis.include?(name)
e.url = Emoji.url_for(filename)
e.group = groups[name] || DEFAULT_GROUP
e.group = group
e.search_aliases = search_aliases[name] || []
end
end
@ -151,7 +152,7 @@ class Emoji
end
def self.load_standard
db['emojis'].map { |e| Emoji.create_from_db_item(e) }
db['emojis'].map { |e| Emoji.create_from_db_item(e) }.compact
end
def self.load_custom

View File

@ -143,15 +143,26 @@ RSpec.describe Emoji do
end
end
describe ".load_standard" do
it "removes nil emojis" do
expect(Emoji.load_standard.any? { |element| element.nil? }).to be false
end
end
describe "#create_from_db_item" do
it "sets the group of the emoji" do
emoji = Emoji.create_from_db_item("name" => "scotland")
expect(emoji.group).to eq("flags")
end
it "sets the search aliases of the emoji" do
emoji = Emoji.create_from_db_item("name" => "sad")
expect(emoji.search_aliases).to contain_exactly("frowning_face", "slightly_frowning_face", "sob", "crying_cat_face", "cry", "face_holding_back_tears")
it "sets the group of the emoji" do
emoji = Emoji.create_from_db_item("name" => "scotland")
expect(emoji.group).to eq("flags")
end
it "doesnt create emoji when group is unknown" do
emoji = Emoji.create_from_db_item("name" => "white_hair")
expect(emoji).to be_nil
end
end
end