Skip to content

Commit

Permalink
Merge pull request #16 from GeorgeZhukov/fix/non-case-sensitive-subdo…
Browse files Browse the repository at this point in the history
…main

added subdomain non-case-sensitive fix
  • Loading branch information
sleekybadger authored Sep 9, 2016
2 parents 56a1c38 + bd5e555 commit a24a71d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/detectify/query_builder/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Base
attr_reader :domain, :subdomain

def initialize(domain, subdomain)
@domain = domain
@subdomain = subdomain
@domain = domain.downcase if domain.is_a?(String)
@subdomain = subdomain.downcase if subdomain.is_a?(String)
end

def build
Expand Down
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
17 changes: 17 additions & 0 deletions spec/detectify/query_builder/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe Detectify::QueryBuilder::Base do
let(:domain) { 'DOMAIN' }
let(:subdomain) { 'SUBDOMAIN' }
subject { Detectify::QueryBuilder::Base.new(domain, subdomain) }

describe '#initialize' do
it 'sets domain in downcase' do
expect(subject.domain).to eq(domain.downcase)
end

it 'sets subdomain in downcase' do
expect(subject.subdomain).to eq(subdomain.downcase)
end
end
end
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 a24a71d

Please sign in to comment.