FIX: CustomEmoji may contain an invalid upload_id.

https://meta.discourse.org/t/white-screen-after-deleting-custom-emoji/61608
This commit is contained in:
Guo Xiang Tan 2017-05-05 14:53:38 +08:00
parent 2b21e5ea7e
commit e61959e6a8
2 changed files with 14 additions and 1 deletions

View File

@ -95,7 +95,7 @@ class Emoji
CustomEmoji.order(:name).all.each do |emoji|
result << Emoji.new.tap do |e|
e.name = emoji.name
e.url = emoji.upload.url
e.url = emoji.upload&.url
end
end

View File

@ -15,4 +15,17 @@ describe Emoji do
expect(Emoji.replacement_code('robin')).to be_nil
end
describe '.load_custom' do
describe 'when a custom emoji has an invalid upload_id' do
it 'should return the custom emoji without a URL' do
CustomEmoji.create!(name: 'test', upload_id: -1)
emoji = Emoji.load_custom.first
expect(emoji.name).to eq('test')
expect(emoji.url).to eq(nil)
end
end
end
end