summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/search/query_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/search/query_spec.rb')
-rw-r--r--spec/lib/gitlab/search/query_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/search/query_spec.rb b/spec/lib/gitlab/search/query_spec.rb
new file mode 100644
index 00000000000..2d00428fffa
--- /dev/null
+++ b/spec/lib/gitlab/search/query_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe Gitlab::Search::Query do
+ let(:query) { 'base filter:wow anotherfilter:noway name:maybe other:mmm leftover' }
+ let(:subject) do
+ described_class.new(query) do
+ filter :filter
+ filter :name, parser: :upcase.to_proc
+ filter :other
+ end
+ end
+
+ it { expect(described_class).to be < SimpleDelegator }
+
+ it 'leaves undefined filters in the main query' do
+ expect(subject.term).to eq('base anotherfilter:noway leftover')
+ end
+
+ it 'parses filters' do
+ expect(subject.filters.count).to eq(3)
+ expect(subject.filters.map { |f| f[:value] }).to match_array(%w[wow MAYBE mmm])
+ end
+
+ context 'with an empty filter' do
+ let(:query) { 'some bar name: baz' }
+
+ it 'ignores empty filters' do
+ expect(subject.term).to eq('some bar name: baz')
+ end
+ end
+
+ context 'with a pipe' do
+ let(:query) { 'base | nofilter' }
+
+ it 'does not escape the pipe' do
+ expect(subject.term).to eq(query)
+ end
+ end
+end