0
0
Fork 0

Add in:library syntax to search (#26760)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Eugen Rochko 2023-09-04 17:20:35 +02:00 committed by GitHub
parent ac3f310f4b
commit ece1ff77d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 98 additions and 60 deletions

View file

@ -3,17 +3,18 @@
require 'rails_helper'
describe SearchQueryTransformer do
subject { described_class.new.apply(parser, current_account: nil) }
subject { described_class.new.apply(parser, current_account: account) }
let(:account) { Fabricate(:account) }
let(:parser) { SearchQueryParser.new.parse(query) }
context 'with "hello world"' do
let(:query) { 'hello world' }
it 'transforms clauses' do
expect(subject.must_clauses.map(&:term)).to match_array %w(hello world)
expect(subject.must_not_clauses).to be_empty
expect(subject.filter_clauses).to be_empty
expect(subject.send(:must_clauses).map(&:term)).to match_array %w(hello world)
expect(subject.send(:must_not_clauses)).to be_empty
expect(subject.send(:filter_clauses)).to be_empty
end
end
@ -21,9 +22,9 @@ describe SearchQueryTransformer do
let(:query) { 'hello -world' }
it 'transforms clauses' do
expect(subject.must_clauses.map(&:term)).to match_array %w(hello)
expect(subject.must_not_clauses.map(&:term)).to match_array %w(world)
expect(subject.filter_clauses).to be_empty
expect(subject.send(:must_clauses).map(&:term)).to match_array %w(hello)
expect(subject.send(:must_not_clauses).map(&:term)).to match_array %w(world)
expect(subject.send(:filter_clauses)).to be_empty
end
end
@ -31,9 +32,9 @@ describe SearchQueryTransformer do
let(:query) { 'hello is:reply' }
it 'transforms clauses' do
expect(subject.must_clauses.map(&:term)).to match_array %w(hello)
expect(subject.must_not_clauses).to be_empty
expect(subject.filter_clauses.map(&:term)).to match_array %w(reply)
expect(subject.send(:must_clauses).map(&:term)).to match_array %w(hello)
expect(subject.send(:must_not_clauses)).to be_empty
expect(subject.send(:filter_clauses).map(&:term)).to match_array %w(reply)
end
end
@ -41,9 +42,9 @@ describe SearchQueryTransformer do
let(:query) { 'foo: bar' }
it 'transforms clauses' do
expect(subject.must_clauses.map(&:term)).to match_array %w(foo bar)
expect(subject.must_not_clauses).to be_empty
expect(subject.filter_clauses).to be_empty
expect(subject.send(:must_clauses).map(&:term)).to match_array %w(foo bar)
expect(subject.send(:must_not_clauses)).to be_empty
expect(subject.send(:filter_clauses)).to be_empty
end
end
@ -51,9 +52,9 @@ describe SearchQueryTransformer do
let(:query) { 'foo:bar' }
it 'transforms clauses' do
expect(subject.must_clauses.map(&:term)).to contain_exactly('foo bar')
expect(subject.must_not_clauses).to be_empty
expect(subject.filter_clauses).to be_empty
expect(subject.send(:must_clauses).map(&:term)).to contain_exactly('foo bar')
expect(subject.send(:must_not_clauses)).to be_empty
expect(subject.send(:filter_clauses)).to be_empty
end
end
end