Skip to content

Commit a24a71d

Browse files
authored
Merge pull request #16 from GeorgeZhukov/fix/non-case-sensitive-subdomain
added subdomain non-case-sensitive fix
2 parents 56a1c38 + bd5e555 commit a24a71d

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

lib/detectify/query_builder/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class Base
44
attr_reader :domain, :subdomain
55

66
def initialize(domain, subdomain)
7-
@domain = domain
8-
@subdomain = subdomain
7+
@domain = domain.downcase if domain.is_a?(String)
8+
@subdomain = subdomain.downcase if subdomain.is_a?(String)
99
end
1010

1111
def build

lib/detectify/query_builder/sql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def build
1313
private
1414

1515
def domain_clause
16-
"#{Detectify.config.domain_column} = ?" if need_domain_clause?
16+
"LOWER(#{Detectify.config.domain_column}) = ?" if need_domain_clause?
1717
end
1818

1919
def subdomain_clause
20-
"#{Detectify.config.subdomain_column} = ?" if need_subdomain_clause?
20+
"LOWER(#{Detectify.config.subdomain_column}) = ?" if need_subdomain_clause?
2121
end
2222

2323
def or_operator
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe Detectify::QueryBuilder::Base do
4+
let(:domain) { 'DOMAIN' }
5+
let(:subdomain) { 'SUBDOMAIN' }
6+
subject { Detectify::QueryBuilder::Base.new(domain, subdomain) }
7+
8+
describe '#initialize' do
9+
it 'sets domain in downcase' do
10+
expect(subject.domain).to eq(domain.downcase)
11+
end
12+
13+
it 'sets subdomain in downcase' do
14+
expect(subject.subdomain).to eq(subdomain.downcase)
15+
end
16+
end
17+
end

spec/detectify/query_builder/sql_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
let(:domain) { 'example.com' }
1010
let(:subdomain) { nil }
1111

12-
it { is_expected.to eq(['domain = ?', 'example.com']) }
12+
it { is_expected.to eq(['LOWER(domain) = ?', 'example.com']) }
1313
end
1414

1515
context 'with only subdomain' do
1616
let(:domain) { nil }
1717
let(:subdomain) { 'example' }
1818

19-
it { is_expected.to eq(['subdomain = ?', 'example']) }
19+
it { is_expected.to eq(['LOWER(subdomain) = ?', 'example']) }
2020
end
2121

2222
context 'with domain and subdomain' do
@@ -25,7 +25,7 @@
2525

2626
it do
2727
is_expected.to eq([
28-
'domain = ? OR subdomain = ?', 'example.com', 'example'
28+
'LOWER(domain) = ? OR LOWER(subdomain) = ?', 'example.com', 'example'
2929
])
3030
end
3131
end
@@ -38,7 +38,7 @@
3838
let(:domain) { 'example.com' }
3939
let(:subdomain) { nil }
4040

41-
it { is_expected.to eq(['domain = ?', 'example.com']) }
41+
it { is_expected.to eq(['LOWER(domain) = ?', 'example.com']) }
4242
end
4343

4444
context 'with only subdomain' do
@@ -52,7 +52,7 @@
5252
let(:domain) { 'example.com' }
5353
let(:subdomain) { 'example' }
5454

55-
it { is_expected.to eq(['domain = ?', 'example.com']) }
55+
it { is_expected.to eq(['LOWER(domain) = ?', 'example.com']) }
5656
end
5757

5858
after { Detectify.reset_config }
@@ -72,14 +72,14 @@
7272
let(:domain) { nil }
7373
let(:subdomain) { 'example' }
7474

75-
it { is_expected.to eq(['subdomain = ?', 'example']) }
75+
it { is_expected.to eq(['LOWER(subdomain) = ?', 'example']) }
7676
end
7777

7878
context 'with domain and subdomain' do
7979
let(:domain) { 'example.com' }
8080
let(:subdomain) { 'example' }
8181

82-
it { is_expected.to eq(['subdomain = ?', 'example']) }
82+
it { is_expected.to eq(['LOWER(subdomain) = ?', 'example']) }
8383
end
8484

8585
after { Detectify.reset_config }

0 commit comments

Comments
 (0)