2017-09-19 01:42:40 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe CustomEmoji, type: :model do
|
2018-04-10 14:46:27 +01:00
|
|
|
describe '#search' do
|
2018-10-04 11:36:53 +01:00
|
|
|
subject { described_class.search(search_term) }
|
2018-04-10 14:46:27 +01:00
|
|
|
|
2023-02-20 04:24:14 +00:00
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
|
|
|
|
|
2018-04-10 14:46:27 +01:00
|
|
|
context 'shortcode is exact' do
|
|
|
|
let(:shortcode) { 'blobpats' }
|
|
|
|
let(:search_term) { 'blobpats' }
|
|
|
|
|
|
|
|
it 'finds emoji' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to include(custom_emoji)
|
2018-04-10 14:46:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'shortcode is partial' do
|
|
|
|
let(:shortcode) { 'blobpats' }
|
|
|
|
let(:search_term) { 'blob' }
|
|
|
|
|
|
|
|
it 'finds emoji' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to include(custom_emoji)
|
2018-04-10 14:46:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-08 06:28:17 +00:00
|
|
|
describe '#local?' do
|
|
|
|
subject { custom_emoji.local? }
|
|
|
|
|
2023-02-20 04:24:14 +00:00
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
|
|
|
|
|
2017-11-08 06:28:17 +00:00
|
|
|
context 'domain is nil' do
|
|
|
|
let(:domain) { nil }
|
|
|
|
|
|
|
|
it 'returns true' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to be true
|
2017-11-08 06:28:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'domain is present' do
|
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
it 'returns false' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to be false
|
2017-11-08 06:28:17 +00: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 01:42:40 +01:00
|
|
|
describe '.from_text' do
|
|
|
|
subject { described_class.from_text(text, nil) }
|
|
|
|
|
2023-02-20 04:24:14 +00:00
|
|
|
let!(:emojo) { Fabricate(:custom_emoji) }
|
|
|
|
|
2017-09-19 01:42:40 +01:00
|
|
|
context 'with plain text' do
|
|
|
|
let(:text) { 'Hello :coolcat:' }
|
|
|
|
|
|
|
|
it 'returns records used via shortcodes in text' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to include(emojo)
|
2017-09-19 01:42:40 +01: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 04:00:48 +00:00
|
|
|
expect(subject).to include(emojo)
|
2017-09-19 01:42:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-11 04:30:57 +00:00
|
|
|
|
|
|
|
describe 'pre_validation' do
|
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, domain: 'wWw.MaStOdOn.CoM') }
|
|
|
|
|
2023-02-18 02:26:20 +00:00
|
|
|
it 'downcases' do
|
2018-12-11 04:30:57 +00:00
|
|
|
custom_emoji.valid?
|
|
|
|
expect(custom_emoji.domain).to eq('www.mastodon.com')
|
|
|
|
end
|
|
|
|
end
|
2017-09-19 01:42:40 +01:00
|
|
|
end
|