2017-09-19 10:42:40 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe CustomEmoji, type: :model do
|
2018-04-10 23:46:27 +10:00
|
|
|
describe '#search' do
|
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
|
|
|
|
|
2018-10-04 20:36:53 +10:00
|
|
|
subject { described_class.search(search_term) }
|
2018-04-10 23:46:27 +10:00
|
|
|
|
|
|
|
context 'shortcode is exact' do
|
|
|
|
let(:shortcode) { 'blobpats' }
|
|
|
|
let(:search_term) { 'blobpats' }
|
|
|
|
|
|
|
|
it 'finds emoji' do
|
|
|
|
is_expected.to include(custom_emoji)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'shortcode is partial' do
|
|
|
|
let(:shortcode) { 'blobpats' }
|
|
|
|
let(:search_term) { 'blob' }
|
|
|
|
|
|
|
|
it 'finds emoji' do
|
|
|
|
is_expected.to include(custom_emoji)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-08 17:28:17 +11:00
|
|
|
describe '#local?' do
|
|
|
|
let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
|
|
|
|
|
|
|
|
subject { custom_emoji.local? }
|
|
|
|
|
|
|
|
context 'domain is nil' do
|
|
|
|
let(:domain) { nil }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
is_expected.to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'domain is present' do
|
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be false
|
|
|
|
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
|
|
|
|
let!(:emojo) { Fabricate(:custom_emoji) }
|
|
|
|
|
|
|
|
subject { described_class.from_text(text, nil) }
|
|
|
|
|
|
|
|
context 'with plain text' do
|
|
|
|
let(:text) { 'Hello :coolcat:' }
|
|
|
|
|
|
|
|
it 'returns records used via shortcodes in text' do
|
|
|
|
is_expected.to include(emojo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with html' do
|
|
|
|
let(:text) { '<p>Hello :coolcat:</p>' }
|
|
|
|
|
|
|
|
it 'returns records used via shortcodes in text' do
|
|
|
|
is_expected.to include(emojo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|