2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-19 10:42:40 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-07-09 02:01:08 +10:00
|
|
|
RSpec.describe CustomEmoji, :attachment_processing do
|
2018-04-10 23:46:27 +10:00
|
|
|
describe '#search' do
|
2018-10-04 20:36:53 +10:00
|
|
|
subject { described_class.search(search_term) }
|
2018-04-10 23:46:27 +10:00
|
|
|
|
2023-02-20 15:24:14 +11:00
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when shortcode is exact' do
|
2018-04-10 23:46:27 +10:00
|
|
|
let(:shortcode) { 'blobpats' }
|
|
|
|
let(:search_term) { 'blobpats' }
|
|
|
|
|
|
|
|
it 'finds emoji' do
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to include(custom_emoji)
|
2018-04-10 23:46:27 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when shortcode is partial' do
|
2018-04-10 23:46:27 +10:00
|
|
|
let(:shortcode) { 'blobpats' }
|
|
|
|
let(:search_term) { 'blob' }
|
|
|
|
|
|
|
|
it 'finds emoji' do
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to include(custom_emoji)
|
2018-04-10 23:46:27 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-08 17:28:17 +11:00
|
|
|
describe '#local?' do
|
|
|
|
subject { custom_emoji.local? }
|
|
|
|
|
2023-02-20 15:24:14 +11:00
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when domain is nil' do
|
2017-11-08 17:28:17 +11:00
|
|
|
let(:domain) { nil }
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to be true
|
2017-11-08 17:28:17 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when domain is present' do
|
2017-11-08 17:28:17 +11:00
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
it 'returns false' do
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to be false
|
2017-11-08 17:28:17 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#object_type' do
|
|
|
|
it 'returns :emoji' do
|
|
|
|
custom_emoji = Fabricate(:custom_emoji)
|
|
|
|
expect(custom_emoji.object_type).to be :emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-19 10:42:40 +10:00
|
|
|
describe '.from_text' do
|
|
|
|
subject { described_class.from_text(text, nil) }
|
|
|
|
|
2023-12-14 21:29:10 +11:00
|
|
|
let!(:emojo) { Fabricate(:custom_emoji, shortcode: 'coolcat') }
|
2023-02-20 15:24:14 +11:00
|
|
|
|
2017-09-19 10:42:40 +10:00
|
|
|
context 'with plain text' do
|
|
|
|
let(:text) { 'Hello :coolcat:' }
|
|
|
|
|
|
|
|
it 'returns records used via shortcodes in text' do
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to include(emojo)
|
2017-09-19 10:42:40 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with html' do
|
|
|
|
let(:text) { '<p>Hello :coolcat:</p>' }
|
|
|
|
|
|
|
|
it 'returns records used via shortcodes in text' do
|
2023-02-20 15:00:48 +11:00
|
|
|
expect(subject).to include(emojo)
|
2017-09-19 10:42:40 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-11 15:30:57 +11:00
|
|
|
|
2024-01-08 22:20:59 +11:00
|
|
|
describe 'Normalizations' do
|
2024-09-04 15:12:40 +10:00
|
|
|
describe 'domain' do
|
|
|
|
it { is_expected.to normalize(:domain).from('wWw.MaStOdOn.CoM').to('www.mastodon.com') }
|
|
|
|
it { is_expected.to normalize(:domain).from(nil).to(nil) }
|
2018-12-11 15:30:57 +11:00
|
|
|
end
|
|
|
|
end
|
2024-09-16 17:53:03 +10:00
|
|
|
|
|
|
|
describe 'Validations' do
|
|
|
|
subject { Fabricate.build :custom_emoji }
|
|
|
|
|
|
|
|
it { is_expected.to validate_uniqueness_of(:shortcode).scoped_to(:domain) }
|
|
|
|
it { is_expected.to validate_length_of(:shortcode).is_at_least(described_class::MINIMUM_SHORTCODE_SIZE) }
|
|
|
|
it { is_expected.to allow_values('cats').for(:shortcode) }
|
|
|
|
it { is_expected.to_not allow_values('@#$@#$', 'X').for(:shortcode) }
|
|
|
|
end
|
2017-09-19 10:42:40 +10:00
|
|
|
end
|