Commit 12633b46 authored by Hiroyuki Sato's avatar Hiroyuki Sato

Refactor

parent 87b51c59
...@@ -7,17 +7,13 @@ module Gitlab ...@@ -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
......
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment