diff options
author | ThibG <thib@sitedethib.com> | 2020-01-25 19:07:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-25 19:07:32 +0100 |
commit | 5bd752081fd72c9899780eaa4b8ce2bd277b1ff0 (patch) | |
tree | e70256fe3b1c89a88222ff91ae88e12248b4a207 /spec | |
parent | 340cb4a04c94f9403673d59e552be909fce25ece (diff) | |
parent | 6ce72f1fee6ca0752467e4f42ca1bd2dd84b3502 (diff) |
Merge pull request #1267 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/validators/reaction_validator_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/validators/reaction_validator_spec.rb b/spec/validators/reaction_validator_spec.rb new file mode 100644 index 000000000..d73104cb6 --- /dev/null +++ b/spec/validators/reaction_validator_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ReactionValidator do + let(:announcement) { Fabricate(:announcement) } + + describe '#validate' do + it 'adds error when not a valid unicode emoji' do + reaction = announcement.announcement_reactions.build(name: 'F') + subject.validate(reaction) + expect(reaction.errors).to_not be_empty + end + + it 'does not add error when non-unicode emoji is a custom emoji' do + custom_emoji = Fabricate(:custom_emoji) + reaction = announcement.announcement_reactions.build(name: custom_emoji.shortcode, custom_emoji_id: custom_emoji.id) + subject.validate(reaction) + expect(reaction.errors).to be_empty + end + + it 'adds error when 8 reactions already exist' do + %w(🐘 ❤️ 🙉 😍 😋 😂 😞 👍).each do |name| + announcement.announcement_reactions.create!(name: name, account: Fabricate(:account)) + end + + reaction = announcement.announcement_reactions.build(name: '😘') + subject.validate(reaction) + expect(reaction.errors).to_not be_empty + end + + it 'does not add error when new reaction is part of the existing ones' do + %w(🐘 ❤️ 🙉 😍 😋 😂 😞 👍).each do |name| + announcement.announcement_reactions.create!(name: name, account: Fabricate(:account)) + end + + reaction = announcement.announcement_reactions.build(name: '😋') + subject.validate(reaction) + expect(reaction.errors).to be_empty + end + end +end |