From 53c86b29f05049d77d17a35a0ca6287174431783 Mon Sep 17 00:00:00 2001 From: David Yip Date: Sun, 3 Dec 2017 21:49:55 -0600 Subject: Glitch::FilterHelper -> Glitch::KeywordMuteHelper. #234. The class helps out with keyword mutes, not just some general concept of "filtering". --- spec/models/glitch/keyword_mute_helper_spec.rb | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/models/glitch/keyword_mute_helper_spec.rb (limited to 'spec/models/glitch/keyword_mute_helper_spec.rb') diff --git a/spec/models/glitch/keyword_mute_helper_spec.rb b/spec/models/glitch/keyword_mute_helper_spec.rb new file mode 100644 index 000000000..9d09e58da --- /dev/null +++ b/spec/models/glitch/keyword_mute_helper_spec.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +RSpec.describe Glitch::KeywordMuteHelper do + describe '#matches?' do + let(:alice) { Fabricate(:account, username: 'alice').tap(&:save!) } + let(:helper) { Glitch::KeywordMuteHelper.new(alice) } + + it 'ignores names of HTML tags in status text' do + status = Fabricate(:status, text: 'uh example') + Glitch::KeywordMute.create!(account: alice, keyword: 'addr') + + expect(helper.matches?(status)).to be false + end + + it 'ignores properties of HTML tags in status text' do + status = Fabricate(:status, text: 'uh example') + Glitch::KeywordMute.create!(account: alice, keyword: 'href') + + expect(helper.matches?(status)).to be false + end + + it 'matches text inside HTML tags' do + status = Fabricate(:status, text: '

HEY THIS IS SOMETHING ANNOYING

') + Glitch::KeywordMute.create!(account: alice, keyword: 'annoying') + + expect(helper.matches?(status)).to be true + end + + it 'matches < in HTML-stripped text' do + status = Fabricate(:status, text: '

I <3 oats

') + Glitch::KeywordMute.create!(account: alice, keyword: '<3') + + expect(helper.matches?(status)).to be true + end + + it 'matches < in HTML text' do + status = Fabricate(:status, text: '

I <3 oats

') + Glitch::KeywordMute.create!(account: alice, keyword: '<3') + + expect(helper.matches?(status)).to be true + end + end +end -- cgit