Fix: #442 カスタム絵文字のaliasesにnullが入る場合がある (#443)

* Fix: #442 カスタム絵文字のaliasesにnullが入る場合がある

* Fix test

* WebのほうにもNULLチェックを追加

* ローカルのエイリアス名を編集するところもついでにスリムに
This commit is contained in:
KMY(雪あすか) 2024-01-10 09:43:56 +09:00 committed by GitHub
parent 650d40cb24
commit dc73c30d2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 111 additions and 12 deletions

View file

@ -49,6 +49,52 @@ RSpec.describe CustomEmoji do
end
end
describe '#copy!' do
subject do
custom_emoji.copy!
described_class.where.not(id: custom_emoji.id).find_by(domain: nil, shortcode: custom_emoji.shortcode)
end
context 'when a simple case' do
let(:custom_emoji) { Fabricate(:custom_emoji, license: 'Ohagi', aliases: %w(aaa bbb), domain: 'example.com', uri: 'https://example.com/emoji') }
it 'makes a copy ot the emoji' do
emoji = subject
expect(emoji).to_not be_nil
expect(emoji.license).to eq 'Ohagi'
expect(emoji.aliases).to eq %w(aaa bbb)
end
end
context 'when local has already same emoji' do
let(:custom_emoji) { Fabricate(:custom_emoji, domain: nil) }
it 'does not make a copy of the emoji' do
expect(subject).to be_nil
end
end
context 'when aliases is null' do
let(:custom_emoji) { Fabricate(:custom_emoji, aliases: nil, domain: 'example.com', uri: 'https://example.com/emoji') }
it 'makes a copy of the emoji but aliases property is normalized' do
emoji = subject
expect(emoji).to_not be_nil
expect(emoji.aliases).to eq []
end
end
context 'when aliases contains null' do
let(:custom_emoji) { Fabricate(:custom_emoji, aliases: [nil], domain: 'example.com', uri: 'https://example.com/emoji') }
it 'makes a copy of the emoji but aliases property is normalized' do
emoji = subject
expect(emoji).to_not be_nil
expect(emoji.aliases).to eq []
end
end
end
describe '#object_type' do
it 'returns :emoji' do
custom_emoji = Fabricate(:custom_emoji)