OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
chore[Op#40437]: store emoji in uncode format backed by string enum
Kabiru Mwenja994be6811ac4
diff --git a/app/models/emoji_reaction.rb b/app/models/emoji_reaction.rbindex 15c8468f37d..da8b3344326 100644--- a/app/models/emoji_reaction.rb+++ b/app/models/emoji_reaction.rb@@ -27,15 +27,16 @@#++class EmojiReaction < ApplicationRecord+ # See: https://unicode.org/Public/emoji/latest/emoji-test.txtEMOJI_MAP = {- thumbs_up: "👍",- thumbs_down: "👎",- grinning_face_with_smiling_eyes: "😄",- confused_face: "😕",- heart: "❤",- party_popper: "🎉",- rocket: "🚀",- eyes: "👀"+ thumbs_up: "\u{1F44D}",+ thumbs_down: "\u{1F44E}",+ grinning_face_with_smiling_eyes: "\u{1F604}",+ confused_face: "\u{1F615}",+ heart: "\u{2764}",+ party_popper: "\u{1F389}",+ rocket: "\u{1F680}",+ eyes: "\u{1F440}"}.freezeAVAILABLE_EMOJIS = EMOJI_MAP.values.freeze@@ -43,9 +44,11 @@ class EmojiReaction < ApplicationRecordbelongs_to :userbelongs_to :reactable, polymorphic: true- validates :emoji, presence: true, inclusion: { in: AVAILABLE_EMOJIS }+ validates :emoji, presence: truevalidates :user_id, uniqueness: { scope: %i[reactable_type reactable_id emoji] }+ enum :emoji, EMOJI_MAP+def self.available_emojisAVAILABLE_EMOJISenddiff --git a/spec/models/emoji_reaction_spec.rb b/spec/models/emoji_reaction_spec.rbindex a2a50e896a9..035de1ba51b 100644--- a/spec/models/emoji_reaction_spec.rb+++ b/spec/models/emoji_reaction_spec.rb@@ -34,9 +34,25 @@ RSpec.describe EmojiReaction doit { is_expected.to belong_to(:reactable) }end+ describe "Enums" do+ it do+ expect(subject).to define_enum_for(:emoji)+ .with_values(+ thumbs_up: "\u{1F44D}",+ thumbs_down: "\u{1F44E}",+ grinning_face_with_smiling_eyes: "\u{1F604}",+ confused_face: "\u{1F615}",+ heart: "\u{2764}",+ party_popper: "\u{1F389}",+ rocket: "\u{1F680}",+ eyes: "\u{1F440}"+ )+ .backed_by_column_of_type(:string)+ end+ end+describe "Validations" doit { is_expected.to validate_presence_of(:emoji) }- it { is_expected.to validate_inclusion_of(:emoji).in_array(EmojiReaction::AVAILABLE_EMOJIS) }it doemoji_reaction = create(:emoji_reaction)@@ -46,18 +62,19 @@ RSpec.describe EmojiReaction dodescribe ".available_emojis" doit "returns the available emojis as HTML codes" do- expect(described_class.available_emojis).to eq(["👍", "👎", "😄", "😕", "❤",- "🎉", "🚀", "👀"])+ expect(described_class.available_emojis).to eq(["👍", "👎", "😄", "😕", "❤", "🎉", "🚀", "👀"])endend- describe ".shortcode" do- it "returns the emoji shortcode for a given HTML code" do- expect(described_class.shortcode("👍")).to eq(":thumbs_up:")+ describe ".emoji_name" do+ it "returns the emoji name for a given unicode", :aggregate_failures do+ expect(described_class.emoji_name("\u{1F44D}")).to eq("thumbs up")+ expect(described_class.emoji_name("😄")).to eq("grinning face with smiling eyes")end- it "returns the HTML code if no shortcode is found" do- expect(described_class.shortcode("💩")).to eq("💩")+ it "returns nil if no emoji exists with given unicode" do+ expect(described_class.emoji_name("\u{1F607}")).to be_nil+ expect(described_class.emoji_name("🤗")).to be_nilendendend