This commit is contained in:
Hiroyuki Sato 2017-08-29 18:00:03 +09:00
parent 87b51c5981
commit 12633b46b6
2 changed files with 4 additions and 8 deletions

View file

@ -7,17 +7,13 @@ module Gitlab
class_methods do
def to_pattern(query)
if exact_matching?(query)
sanitize_sql_like(query)
else
if partial_matching?(query)
"%#{sanitize_sql_like(query)}%"
else
sanitize_sql_like(query)
end
end
def exact_matching?(query)
query.length < MIN_CHARS_FOR_PARTIAL_MATCHING
end
def partial_matching?(query)
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe Gitlab::SQL::Pattern do
describe '#to_pattern' do
describe '.to_pattern' do
subject(:to_pattern) { User.to_pattern(query) }
context 'when a query is shorter than 3 chars' do