rails-contact 0.1.19 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f986b7426ce2b99924283ea2343ef48ed1f6f4c50c6e2763ba50f03be99b9a93
4
- data.tar.gz: 8f04a3f04fdb7d9bb6921efa14df565be9b82029c03c522da8ac6b111e70e3f9
3
+ metadata.gz: 7db41d62f84bab3daa7116637e110537293232619c6568f0b55bc4d3aba89419
4
+ data.tar.gz: 05cf0def4af33f2be02b0ea14cd6a41a151bc115d8a7f5908e08b67ade7273cd
5
5
  SHA512:
6
- metadata.gz: 7426fa7a4faf079dba58377b115f5b612463f55c7ab66aef7f4eec65fbb8b258c84dc91c148d63bd9b76e59bc08387b8df34052f4226ee066cde9eeba1eec916
7
- data.tar.gz: 916da6b6432f11a44c8b260964f81feaa5092b2da83d4a5c9433d25c786d4e57d19d1b6f402a1c2ddaf043a8a8dbb69ea0da7308d82016323393d398e0a7b072
6
+ metadata.gz: 51a23f400c382b01beaf54bb862e53cbd6b3a353379adb2752ddb520dfcb1e8323bdb4b40462bbbf5c22cefa97cce5d0a909bf600897433b2f2cb28df02179df
7
+ data.tar.gz: 51012c9824d63061668b251c5bf6df60999b182e32107a164e2f5f309a7bb50891ac7690fb039489ac95abc926eb16dc864056920bb50cad823eefaca051a55c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.20
4
+
5
+ - **A phone typed without its country code is found again.** Since search
6
+ became prefix-only, "9812345670" no longer matched "+919812345670": the
7
+ stored number starts with the country code, so no prefix of the typed
8
+ digits can reach it. A query of seven or more digits and nothing else now
9
+ matches anywhere in the stored number. Only that case scans the phones
10
+ table; names, emails, labels and shorter digit runs stay index-served
11
+ prefix matches.
12
+
3
13
  ## 0.1.19
4
14
 
5
15
  - **Result counts are exact again, and bounded.** 0.1.17 replaced large exact
@@ -50,6 +50,10 @@ module Rails
50
50
  # still matches.
51
51
  def apply_query(scoped, query)
52
52
  prefix = "#{query.downcase}%"
53
+ # A long run of digits is a phone typed without its country code
54
+ # ("9812345670" for "+919812345670"), which no prefix can find. Only
55
+ # that case scans the phones table; every other arm stays a prefix.
56
+ phone = query.match?(/\A\d{7,}\z/) ? "%#{query}%" : "#{query}%"
53
57
  scoped.where(
54
58
  "rails_contact_contacts.id IN (" \
55
59
  "SELECT c.id FROM rails_contact_contacts c WHERE LOWER(c.given_name) LIKE :q " \
@@ -62,7 +66,7 @@ module Rails
62
66
  "JOIN rails_contact_labels l ON l.id = cl.label_id WHERE LOWER(l.name) LIKE :q" \
63
67
  ")",
64
68
  q: prefix,
65
- raw: "#{query}%",
69
+ raw: phone,
66
70
  plus_raw: "+#{query}%"
67
71
  )
68
72
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Contact
3
- VERSION = "0.1.19"
3
+ VERSION = "0.1.20"
4
4
  end
5
5
  end
@@ -104,6 +104,14 @@ RSpec.describe Rails::Contact::Search::Backends::Database do
104
104
  expect(search_for("91981")).to include(dave)
105
105
  end
106
106
 
107
+ it "matches a phone typed without its country code" do
108
+ expect(search_for("9812345670")).to include(dave)
109
+ end
110
+
111
+ it "keeps short digit runs a prefix match" do
112
+ expect(search_for("98123")).not_to include(dave)
113
+ end
114
+
107
115
  it "matches the full plus-form phone prefix" do
108
116
  expect(search_for("+91981")).to include(dave)
109
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-contact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kshitiz Sinha