reaction_validator_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ReactionValidator do
  4. let(:announcement) { Fabricate(:announcement) }
  5. describe '#validate' do
  6. it 'adds error when not a valid unicode emoji' do
  7. reaction = announcement.announcement_reactions.build(name: 'F')
  8. subject.validate(reaction)
  9. expect(reaction.errors).to_not be_empty
  10. end
  11. it 'does not add error when non-unicode emoji is a custom emoji' do
  12. custom_emoji = Fabricate(:custom_emoji)
  13. reaction = announcement.announcement_reactions.build(name: custom_emoji.shortcode, custom_emoji_id: custom_emoji.id)
  14. subject.validate(reaction)
  15. expect(reaction.errors).to be_empty
  16. end
  17. it 'adds error when reaction limit count has already been reached' do
  18. stub_const 'ReactionValidator::LIMIT', 2
  19. %w(🐘 ❤️).each do |name|
  20. announcement.announcement_reactions.create!(name: name, account: Fabricate(:account))
  21. end
  22. reaction = announcement.announcement_reactions.build(name: '😘')
  23. subject.validate(reaction)
  24. expect(reaction.errors).to_not be_empty
  25. end
  26. it 'does not add error when new reaction is part of the existing ones' do
  27. %w(🐘 ❤️ 🙉 😍 😋 😂 😞 👍).each do |name|
  28. announcement.announcement_reactions.create!(name: name, account: Fabricate(:account))
  29. end
  30. reaction = announcement.announcement_reactions.build(name: '😋')
  31. subject.validate(reaction)
  32. expect(reaction.errors).to be_empty
  33. end
  34. end
  35. end