custom_emoji_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe CustomEmoji do
  4. describe '#search' do
  5. subject { described_class.search(search_term) }
  6. let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
  7. context 'when shortcode is exact' do
  8. let(:shortcode) { 'blobpats' }
  9. let(:search_term) { 'blobpats' }
  10. it 'finds emoji' do
  11. expect(subject).to include(custom_emoji)
  12. end
  13. end
  14. context 'when shortcode is partial' do
  15. let(:shortcode) { 'blobpats' }
  16. let(:search_term) { 'blob' }
  17. it 'finds emoji' do
  18. expect(subject).to include(custom_emoji)
  19. end
  20. end
  21. end
  22. describe '#local?' do
  23. subject { custom_emoji.local? }
  24. let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
  25. context 'when domain is nil' do
  26. let(:domain) { nil }
  27. it 'returns true' do
  28. expect(subject).to be true
  29. end
  30. end
  31. context 'when domain is present' do
  32. let(:domain) { 'example.com' }
  33. it 'returns false' do
  34. expect(subject).to be false
  35. end
  36. end
  37. end
  38. describe '#object_type' do
  39. it 'returns :emoji' do
  40. custom_emoji = Fabricate(:custom_emoji)
  41. expect(custom_emoji.object_type).to be :emoji
  42. end
  43. end
  44. describe '.from_text' do
  45. subject { described_class.from_text(text, nil) }
  46. let!(:emojo) { Fabricate(:custom_emoji) }
  47. context 'with plain text' do
  48. let(:text) { 'Hello :coolcat:' }
  49. it 'returns records used via shortcodes in text' do
  50. expect(subject).to include(emojo)
  51. end
  52. end
  53. context 'with html' do
  54. let(:text) { '<p>Hello :coolcat:</p>' }
  55. it 'returns records used via shortcodes in text' do
  56. expect(subject).to include(emojo)
  57. end
  58. end
  59. end
  60. describe 'pre_validation' do
  61. let(:custom_emoji) { Fabricate(:custom_emoji, domain: 'wWw.MaStOdOn.CoM') }
  62. it 'downcases' do
  63. custom_emoji.valid?
  64. expect(custom_emoji.domain).to eq('www.mastodon.com')
  65. end
  66. end
  67. end