From 154c8c3fefc63ec19978d76c0b8d398ba65f217e Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Mon, 7 Dec 2020 13:36:08 +0200 Subject: [PATCH] FIX: Use CDN for custom emojis (#11401) --- app/serializers/emoji_serializer.rb | 4 ++++ spec/serializers/emoji_serializer_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/serializers/emoji_serializer_spec.rb 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