0
0
Fork 0

Add CustomFilterKeyword#to_regex method (#28893)

This commit is contained in:
Matt Jankowski 2024-01-25 08:00:34 -05:00 committed by GitHub
parent a69506a434
commit 6b6586f5d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 10 deletions

View file

@ -0,0 +1,35 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CustomFilterKeyword do
describe '#to_regex' do
context 'when whole_word is true' do
it 'builds a regex with boundaries and the keyword' do
keyword = described_class.new(whole_word: true, keyword: 'test')
expect(keyword.to_regex).to eq(/(?mix:\b#{Regexp.escape(keyword.keyword)}\b)/)
end
it 'builds a regex with starting boundary and the keyword when end with non-word' do
keyword = described_class.new(whole_word: true, keyword: 'test#')
expect(keyword.to_regex).to eq(/(?mix:\btest\#)/)
end
it 'builds a regex with end boundary and the keyword when start with non-word' do
keyword = described_class.new(whole_word: true, keyword: '#test')
expect(keyword.to_regex).to eq(/(?mix:\#test\b)/)
end
end
context 'when whole_word is false' do
it 'builds a regex with the keyword' do
keyword = described_class.new(whole_word: false, keyword: 'test')
expect(keyword.to_regex).to eq(/test/i)
end
end
end
end