|
|
@ -93,4 +93,65 @@ RSpec.describe Glitch::KeywordMute, type: :model do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|
|
|
|