diff --git a/app/serializers/emoji_serializer.rb b/app/serializers/emoji_serializer.rb index d0d440e24dc..f5ed3946c22 100644 --- a/app/serializers/emoji_serializer.rb +++ b/app/serializers/emoji_serializer.rb @@ -2,4 +2,8 @@ class EmojiSerializer < ApplicationSerializer attributes :name, :url, :group + + def url + Discourse.store.cdn_url(object.url) + end end diff --git a/spec/serializers/emoji_serializer_spec.rb b/spec/serializers/emoji_serializer_spec.rb new file mode 100644 index 00000000000..434ee17f35f --- /dev/null +++ b/spec/serializers/emoji_serializer_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe EmojiSerializer do + fab!(:emoji) do + CustomEmoji.create!(name: 'trout', upload: Fabricate(:upload)) + Emoji.load_custom.first + end + + subject { described_class.new(emoji, root: false) } + + describe '#url' do + it 'returns a valid URL' do + expect(subject.url).to start_with('/uploads/') + end + + it 'works with a CDN' do + set_cdn_url('https://cdn.com') + expect(subject.url).to start_with('https://cdn.com') + end + end +end