custom_emoji_spec.rb 1.9 KB

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