Skip to content

Commit

Permalink
Add lower function to sql query
Browse files Browse the repository at this point in the history
  • Loading branch information
sleekybadger committed Sep 9, 2016
1 parent 3241a9e commit bd5e555
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/detectify/query_builder/sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/detectify/query_builder/sql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }
Expand All @@ -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 }
Expand Down

0 comments on commit bd5e555

Please sign in to comment.