Refactor
This commit is contained in:
parent
87b51c5981
commit
12633b46b6
2 changed files with 4 additions and 8 deletions
|
@ -7,17 +7,13 @@ module Gitlab
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
def to_pattern(query)
|
def to_pattern(query)
|
||||||
if exact_matching?(query)
|
if partial_matching?(query)
|
||||||
sanitize_sql_like(query)
|
|
||||||
else
|
|
||||||
"%#{sanitize_sql_like(query)}%"
|
"%#{sanitize_sql_like(query)}%"
|
||||||
|
else
|
||||||
|
sanitize_sql_like(query)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def exact_matching?(query)
|
|
||||||
query.length < MIN_CHARS_FOR_PARTIAL_MATCHING
|
|
||||||
end
|
|
||||||
|
|
||||||
def partial_matching?(query)
|
def partial_matching?(query)
|
||||||
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
|
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Gitlab::SQL::Pattern do
|
describe Gitlab::SQL::Pattern do
|
||||||
describe '#to_pattern' do
|
describe '.to_pattern' do
|
||||||
subject(:to_pattern) { User.to_pattern(query) }
|
subject(:to_pattern) { User.to_pattern(query) }
|
||||||
|
|
||||||
context 'when a query is shorter than 3 chars' do
|
context 'when a query is shorter than 3 chars' do
|
||||||
|
|
Loading…
Reference in a new issue