Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/sql/pattern_spec.rb')
-rw-r--r--spec/lib/gitlab/sql/pattern_spec.rb45
1 files changed, 30 insertions, 15 deletions
diff --git a/spec/lib/gitlab/sql/pattern_spec.rb b/spec/lib/gitlab/sql/pattern_spec.rb
index 9bf6f0b82bc..60bb006673f 100644
--- a/spec/lib/gitlab/sql/pattern_spec.rb
+++ b/spec/lib/gitlab/sql/pattern_spec.rb
@@ -29,6 +29,9 @@ RSpec.describe Gitlab::SQL::Pattern do
'AH' | %i[title description] | %i[issue3]
'oh' | %i[title] | %i[issue3]
'ah' | %i[description] | %i[issue3]
+
+ '' | %i[title] | %i[issue1 issue2 issue3]
+ %w[a b] | %i[title] | %i[issue1 issue2 issue3]
end
with_them do
@@ -104,14 +107,14 @@ RSpec.describe Gitlab::SQL::Pattern do
end
end
- describe '.select_fuzzy_words' do
- subject(:select_fuzzy_words) { Issue.select_fuzzy_words(query) }
+ describe '.select_fuzzy_terms' do
+ subject(:select_fuzzy_terms) { Issue.select_fuzzy_terms(query) }
context 'with a word equal to 3 chars' do
let(:query) { 'foo' }
- it 'returns array cotaining a word' do
- expect(select_fuzzy_words).to match_array(['foo'])
+ it 'returns array containing a word' do
+ expect(select_fuzzy_terms).to match_array(['foo'])
end
end
@@ -119,7 +122,7 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { 'fo' }
it 'returns empty array' do
- expect(select_fuzzy_words).to match_array([])
+ expect(select_fuzzy_terms).to match_array([])
end
end
@@ -127,7 +130,7 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { 'foo baz' }
it 'returns array containing two words' do
- expect(select_fuzzy_words).to match_array(%w[foo baz])
+ expect(select_fuzzy_terms).to match_array(%w[foo baz])
end
end
@@ -135,7 +138,7 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { 'foo baz' }
it 'returns array containing two words' do
- expect(select_fuzzy_words).to match_array(%w[foo baz])
+ expect(select_fuzzy_terms).to match_array(%w[foo baz])
end
end
@@ -143,7 +146,19 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { 'foo ba' }
it 'returns array containing a word' do
- expect(select_fuzzy_words).to match_array(['foo'])
+ expect(select_fuzzy_terms).to match_array(['foo'])
+ end
+ end
+ end
+
+ describe '.split_query_to_search_terms' do
+ subject(:split_query_to_search_terms) { described_class.split_query_to_search_terms(query) }
+
+ context 'with words separated by spaces' do
+ let(:query) { 'really bar baz' }
+
+ it 'returns array containing individual words' do
+ expect(split_query_to_search_terms).to match_array(%w[really bar baz])
end
end
@@ -151,15 +166,15 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { '"really bar"' }
it 'returns array containing a multi-word' do
- expect(select_fuzzy_words).to match_array(['really bar'])
+ expect(split_query_to_search_terms).to match_array(['really bar'])
end
end
context 'with a multi-word surrounded by double quote and two words' do
let(:query) { 'foo "really bar" baz' }
- it 'returns array containing a multi-word and tow words' do
- expect(select_fuzzy_words).to match_array(['foo', 'really bar', 'baz'])
+ it 'returns array containing a multi-word and two words' do
+ expect(split_query_to_search_terms).to match_array(['foo', 'really bar', 'baz'])
end
end
@@ -167,7 +182,7 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { 'foo"really bar"' }
it 'returns array containing two words with double quote' do
- expect(select_fuzzy_words).to match_array(['foo"really', 'bar"'])
+ expect(split_query_to_search_terms).to match_array(['foo"really', 'bar"'])
end
end
@@ -175,15 +190,15 @@ RSpec.describe Gitlab::SQL::Pattern do
let(:query) { '"really bar"baz' }
it 'returns array containing two words with double quote' do
- expect(select_fuzzy_words).to match_array(['"really', 'bar"baz'])
+ expect(split_query_to_search_terms).to match_array(['"really', 'bar"baz'])
end
end
context 'with two multi-word surrounded by double quote and two words' do
let(:query) { 'foo "really bar" baz "awesome feature"' }
- it 'returns array containing two multi-words and tow words' do
- expect(select_fuzzy_words).to match_array(['foo', 'really bar', 'baz', 'awesome feature'])
+ it 'returns array containing two multi-words and two words' do
+ expect(split_query_to_search_terms).to match_array(['foo', 'really bar', 'baz', 'awesome feature'])
end
end
end