From c2a92dffc920cda6985dce0a0f77ae25b85659aa Mon Sep 17 00:00:00 2001 From: David Yip Date: Wed, 15 Nov 2017 23:31:49 -0600 Subject: [PATCH] Add some examples for Glitch::KeywordMute::TagMatcher. #208. --- spec/models/glitch/keyword_mute_spec.rb | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/spec/models/glitch/keyword_mute_spec.rb b/spec/models/glitch/keyword_mute_spec.rb index bab276c267..0ffc7b18f2 100644 --- a/spec/models/glitch/keyword_mute_spec.rb +++ b/spec/models/glitch/keyword_mute_spec.rb @@ -93,4 +93,65 @@ RSpec.describe Glitch::KeywordMute, type: :model do end end end + + describe '.tag_matcher_for' do + let(:matcher) { Glitch::KeywordMute.tag_matcher_for(alice.id) } + let(:status) { Fabricate(:status) } + + describe 'with no mutes' do + before do + Glitch::KeywordMute.delete_all + end + + it 'does not match' do + status.tags << Fabricate(:tag, name: 'xyzzy') + + expect(matcher.matches?(status.tags)).to be false + end + end + + describe 'with mutes' do + it 'does not match keywords set by a different account' do + status.tags << Fabricate(:tag, name: 'xyzzy') + Glitch::KeywordMute.create!(account: bob, keyword: 'take') + + expect(matcher.matches?(status.tags)).to be false + end + + it 'matches #xyzzy when given the mute "#xyzzy"' do + status.tags << Fabricate(:tag, name: 'xyzzy') + Glitch::KeywordMute.create!(account: alice, keyword: '#xyzzy') + + expect(matcher.matches?(status.tags)).to be true + end + + it 'matches #thingiverse when given the non-whole-word mute "#thing"' do + status.tags << Fabricate(:tag, name: 'thingiverse') + Glitch::KeywordMute.create!(account: alice, keyword: '#thing', whole_word: false) + + expect(matcher.matches?(status.tags)).to be true + end + + it 'matches #hashtag when given the mute "##hashtag""' do + status.tags << Fabricate(:tag, name: 'hashtag') + Glitch::KeywordMute.create!(account: alice, keyword: '##hashtag') + + expect(matcher.matches?(status.tags)).to be true + end + + it 'matches #oatmeal when given the non-whole-word mute "oat"' do + status.tags << Fabricate(:tag, name: 'oatmeal') + Glitch::KeywordMute.create!(account: alice, keyword: 'oat', whole_word: false) + + expect(matcher.matches?(status.tags)).to be true + end + + it 'does not match #oatmeal when given the mute "#oat"' do + status.tags << Fabricate(:tag, name: 'oatmeal') + Glitch::KeywordMute.create!(account: alice, keyword: 'oat') + + expect(matcher.matches?(status.tags)).to be false + end + end + end end