From bd5e555c341ca055644028c1b1b7f7f6cece2ef2 Mon Sep 17 00:00:00 2001 From: Lukyanov Fedor Date: Fri, 9 Sep 2016 10:45:24 +0300 Subject: [PATCH] Add lower function to sql query --- lib/detectify/query_builder/sql.rb | 4 ++-- spec/detectify/query_builder/sql_spec.rb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/detectify/query_builder/sql.rb b/lib/detectify/query_builder/sql.rb index 92513f4..05441d5 100644 --- a/lib/detectify/query_builder/sql.rb +++ b/lib/detectify/query_builder/sql.rb @@ -13,11 +13,11 @@ def build private def domain_clause - "#{Detectify.config.domain_column} = ?" if need_domain_clause? + "LOWER(#{Detectify.config.domain_column}) = ?" if need_domain_clause? end def subdomain_clause - "#{Detectify.config.subdomain_column} = ?" if need_subdomain_clause? + "LOWER(#{Detectify.config.subdomain_column}) = ?" if need_subdomain_clause? end def or_operator diff --git a/spec/detectify/query_builder/sql_spec.rb b/spec/detectify/query_builder/sql_spec.rb index c469698..6795e17 100644 --- a/spec/detectify/query_builder/sql_spec.rb +++ b/spec/detectify/query_builder/sql_spec.rb @@ -9,14 +9,14 @@ let(:domain) { 'example.com' } let(:subdomain) { nil } - it { is_expected.to eq(['domain = ?', 'example.com']) } + it { is_expected.to eq(['LOWER(domain) = ?', 'example.com']) } end context 'with only subdomain' do let(:domain) { nil } let(:subdomain) { 'example' } - it { is_expected.to eq(['subdomain = ?', 'example']) } + it { is_expected.to eq(['LOWER(subdomain) = ?', 'example']) } end context 'with domain and subdomain' do @@ -25,7 +25,7 @@ it do is_expected.to eq([ - 'domain = ? OR subdomain = ?', 'example.com', 'example' + 'LOWER(domain) = ? OR LOWER(subdomain) = ?', 'example.com', 'example' ]) end end @@ -38,7 +38,7 @@ let(:domain) { 'example.com' } let(:subdomain) { nil } - it { is_expected.to eq(['domain = ?', 'example.com']) } + it { is_expected.to eq(['LOWER(domain) = ?', 'example.com']) } end context 'with only subdomain' do @@ -52,7 +52,7 @@ let(:domain) { 'example.com' } let(:subdomain) { 'example' } - it { is_expected.to eq(['domain = ?', 'example.com']) } + it { is_expected.to eq(['LOWER(domain) = ?', 'example.com']) } end after { Detectify.reset_config } @@ -72,14 +72,14 @@ let(:domain) { nil } let(:subdomain) { 'example' } - it { is_expected.to eq(['subdomain = ?', 'example']) } + it { is_expected.to eq(['LOWER(subdomain) = ?', 'example']) } end context 'with domain and subdomain' do let(:domain) { 'example.com' } let(:subdomain) { 'example' } - it { is_expected.to eq(['subdomain = ?', 'example']) } + it { is_expected.to eq(['LOWER(subdomain) = ?', 'example']) } end after { Detectify.reset_config }