phony_rails 0.14.9 → 0.14.10
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 +4 -4
- data/CHANGELOG.md +35 -1
- data/lib/phony_rails.rb +6 -1
- data/lib/phony_rails/version.rb +1 -1
- data/spec/lib/phony_rails_spec.rb +27 -1
- data/spec/lib/validators/phony_validator_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 383011d77dc615fbacdbf4ebe23f4c89db28122b
|
4
|
+
data.tar.gz: a123f3f39a984f21216f7f72b5031dda84b84c8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a2c46b310e1b4af1d3a41cc5ababd92d7226dfac7c7f9509f9356774c9e81e8e455213f5d23c9ab91434c9d3143f0916ed90d59e21065040613396583ae163
|
7
|
+
data.tar.gz: e31193d4001b20da3d9ab6c737754b896d1a3ae8bdc8aa942c2b7766ba17439a2c751891bfb85bdbdfe484e823898ff9b8bef6e7c97d2cc59fe6e01519976fa1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.14.10](https://github.com/joost/phony_rails/tree/v0.14.10) (2018-10-11)
|
4
|
+
[Full Changelog](https://github.com/joost/phony_rails/compare/v0.14.9...v0.14.10)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- PhonyRails.default\_country\_code too intrusive in plausible\_number? method [\#179](https://github.com/joost/phony_rails/issues/179)
|
9
|
+
- default\_country\_code overrides 00-prefix country code [\#175](https://github.com/joost/phony_rails/issues/175)
|
10
|
+
- Valid 260 area code number is reported as invalid [\#168](https://github.com/joost/phony_rails/issues/168)
|
11
|
+
- Croatian number not validating as plausible. [\#165](https://github.com/joost/phony_rails/issues/165)
|
12
|
+
- phony\_formatted not returning original String for non-digit only strings [\#163](https://github.com/joost/phony_rails/issues/163)
|
13
|
+
- should all normalized numbers be valid? [\#162](https://github.com/joost/phony_rails/issues/162)
|
14
|
+
- Extensions not working out of the box for validator [\#160](https://github.com/joost/phony_rails/issues/160)
|
15
|
+
|
16
|
+
**Merged pull requests:**
|
17
|
+
|
18
|
+
- Remove errant `puts` [\#188](https://github.com/joost/phony_rails/pull/188) ([stevenharman](https://github.com/stevenharman))
|
19
|
+
- Close issues [\#185](https://github.com/joost/phony_rails/pull/185) ([joost](https://github.com/joost))
|
20
|
+
- Better PhonyRails.plausible\_number? method. Closes \#179. [\#184](https://github.com/joost/phony_rails/pull/184) ([joost](https://github.com/joost))
|
21
|
+
- Allow numbers starting with 00 country codes. Closes \#175. [\#183](https://github.com/joost/phony_rails/pull/183) ([joost](https://github.com/joost))
|
22
|
+
|
23
|
+
## [v0.14.9](https://github.com/joost/phony_rails/tree/v0.14.9) (2018-09-05)
|
24
|
+
[Full Changelog](https://github.com/joost/phony_rails/compare/v0.14.7...v0.14.9)
|
25
|
+
|
26
|
+
**Closed issues:**
|
27
|
+
|
28
|
+
- Cut new release 0.14.7 to include new extension removal logic [\#177](https://github.com/joost/phony_rails/issues/177)
|
29
|
+
- default\_country\_code based on relation [\#174](https://github.com/joost/phony_rails/issues/174)
|
30
|
+
|
31
|
+
**Merged pull requests:**
|
32
|
+
|
33
|
+
- Allow brackets. Closes \#170. [\#182](https://github.com/joost/phony_rails/pull/182) ([joost](https://github.com/joost))
|
34
|
+
- add lambda support for default country code [\#181](https://github.com/joost/phony_rails/pull/181) ([kimyu92](https://github.com/kimyu92))
|
35
|
+
- Add Spanish translation for validation error [\#178](https://github.com/joost/phony_rails/pull/178) ([r-sierra](https://github.com/r-sierra))
|
36
|
+
|
3
37
|
## [v0.14.7](https://github.com/joost/phony_rails/tree/v0.14.7) (2018-05-25)
|
4
38
|
[Full Changelog](https://github.com/joost/phony_rails/compare/v0.14.6...v0.14.7)
|
5
39
|
|
@@ -127,7 +161,7 @@
|
|
127
161
|
**Merged pull requests:**
|
128
162
|
|
129
163
|
- Update readme [\#117](https://github.com/joost/phony_rails/pull/117) ([toydestroyer](https://github.com/toydestroyer))
|
130
|
-
- Add uk, ru error message translations [\#114](https://github.com/joost/phony_rails/pull/114) ([
|
164
|
+
- Add uk, ru error message translations [\#114](https://github.com/joost/phony_rails/pull/114) ([sanavy](https://github.com/sanavy))
|
131
165
|
- Update phony\_rails.gemspec [\#112](https://github.com/joost/phony_rails/pull/112) ([Agsiegert](https://github.com/Agsiegert))
|
132
166
|
- Don't re-parse country codes YAML file every time it's needed. [\#111](https://github.com/joost/phony_rails/pull/111) ([jcoleman](https://github.com/jcoleman))
|
133
167
|
- Replace countries dependency with YAML file [\#109](https://github.com/joost/phony_rails/pull/109) ([monfresh](https://github.com/monfresh))
|
data/lib/phony_rails.rb
CHANGED
@@ -76,7 +76,7 @@ module PhonyRails
|
|
76
76
|
def self.normalize_number_default_country(number, default_country_number)
|
77
77
|
# We try to add the default country number and see if it is a
|
78
78
|
# correct phone number. See https://github.com/joost/phony_rails/issues/87#issuecomment-89324426
|
79
|
-
unless number =~ /\A\(
|
79
|
+
unless number =~ /\A\(?(\+|00)/ # if we don't have a + or 00
|
80
80
|
return "#{default_country_number}#{number}" if Phony.plausible?("#{default_country_number}#{number}") || !Phony.plausible?(number) || country_code_from_number(number).nil?
|
81
81
|
# If the number starts with ONE zero (two might indicate a country code)
|
82
82
|
# and this is a plausible number for the default_country
|
@@ -97,11 +97,14 @@ module PhonyRails
|
|
97
97
|
options[:default_country_number] || country_number_for(country_code) || default_country_number
|
98
98
|
end
|
99
99
|
|
100
|
+
# Returns the country dail code (eg. '31') for a number (eg. +31612341234).
|
101
|
+
# Should probably be named 'country_number_from_number'.
|
100
102
|
def self.country_code_from_number(number)
|
101
103
|
return nil unless Phony.plausible?(number)
|
102
104
|
Phony.split(Phony.normalize(number)).first
|
103
105
|
end
|
104
106
|
|
107
|
+
# Returns the country (eg. 'NL') for a number (eg. +31612341234).
|
105
108
|
def self.country_from_number(number)
|
106
109
|
return nil unless Phony.plausible?(number)
|
107
110
|
country_codes_hash.select { |_country, hash| hash['country_code'] == country_code_from_number(number) }.keys[0]
|
@@ -109,11 +112,13 @@ module PhonyRails
|
|
109
112
|
|
110
113
|
# Wrapper for Phony.plausible?. Takes the same options as #normalize_number.
|
111
114
|
# NB: This method calls #normalize_number and passes _options_ directly to that method.
|
115
|
+
# It uses the 'cc' option for Phony. This was a required param before?
|
112
116
|
def self.plausible_number?(number, options = {})
|
113
117
|
return false if number.blank?
|
114
118
|
number = extract_extension(number).first
|
115
119
|
number = normalize_number(number, options)
|
116
120
|
country_number = options[:country_number] || country_number_for(options[:country_code]) ||
|
121
|
+
country_code_from_number(number) ||
|
117
122
|
options[:default_country_number] || country_number_for(options[:default_country_code]) ||
|
118
123
|
default_country_number
|
119
124
|
Phony.plausible? number, cc: country_number
|
data/lib/phony_rails/version.rb
CHANGED
@@ -224,6 +224,18 @@ describe PhonyRails do
|
|
224
224
|
phone = PhonyRails.normalize_number(phone, default_country_code: 'DE')
|
225
225
|
expect(phone).to eq('+491751234567')
|
226
226
|
end
|
227
|
+
|
228
|
+
it 'should pass Github issue #175' do
|
229
|
+
phone = '0041 23456789'
|
230
|
+
phone = PhonyRails.normalize_number(phone, default_country_code: 'DE')
|
231
|
+
expect(phone).to eq('+4123456789')
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should pass Github issue #175' do
|
235
|
+
phone = '+1 260-437-9123'
|
236
|
+
phone = PhonyRails.normalize_number(phone, default_country_code: 'DE')
|
237
|
+
expect(phone).to eq('+12604379123')
|
238
|
+
end
|
227
239
|
end
|
228
240
|
|
229
241
|
it 'should not change original String' do
|
@@ -409,6 +421,7 @@ describe PhonyRails do
|
|
409
421
|
subject { described_class }
|
410
422
|
let(:valid_number) { '1 555 555 5555' }
|
411
423
|
let(:invalid_number) { '123456789 123456789 123456789 123456789' }
|
424
|
+
let(:another_invalid_number) { '441212' }
|
412
425
|
let(:normalizable_number) { '555 555 5555' }
|
413
426
|
let(:formatted_french_number_with_country_code) { '+33 627899541' }
|
414
427
|
let(:empty_number) { '' }
|
@@ -418,8 +431,11 @@ describe PhonyRails do
|
|
418
431
|
is_expected.to be_plausible_number valid_number, country_code: 'US'
|
419
432
|
end
|
420
433
|
|
421
|
-
it 'returns false for an invalid
|
434
|
+
it 'returns false for an invalid numbers' do
|
435
|
+
is_expected.not_to be_plausible_number invalid_number
|
422
436
|
is_expected.not_to be_plausible_number invalid_number, country_code: 'US'
|
437
|
+
is_expected.not_to be_plausible_number another_invalid_number
|
438
|
+
is_expected.not_to be_plausible_number another_invalid_number, country_code: 'US'
|
423
439
|
end
|
424
440
|
|
425
441
|
it 'returns true for a normalizable number' do
|
@@ -451,6 +467,10 @@ describe PhonyRails do
|
|
451
467
|
is_expected.not_to be_plausible_number normalizable_number, country_code: 'US'
|
452
468
|
end
|
453
469
|
|
470
|
+
it 'should pass Github issue #95' do
|
471
|
+
is_expected.to be_plausible_number '+358414955444', default_country_code: :de
|
472
|
+
end
|
473
|
+
|
454
474
|
context 'with default_country_code set' do
|
455
475
|
before { PhonyRails.default_country_code = 'FR' }
|
456
476
|
after { PhonyRails.default_country_code = nil }
|
@@ -501,6 +521,12 @@ describe PhonyRails do
|
|
501
521
|
end
|
502
522
|
end
|
503
523
|
|
524
|
+
describe 'PhonyRails.country_code_from_number' do
|
525
|
+
it 'returns the code of the plausible phone number' do
|
526
|
+
expect(PhonyRails.country_code_from_number('+32475000000')).to eq '32'
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
504
530
|
describe 'PhonyRails.country_from_number' do
|
505
531
|
it 'returns the country of the plausible phone number' do
|
506
532
|
expect(PhonyRails.country_from_number('+32475000000')).to eq 'BE'
|
@@ -180,6 +180,7 @@ POLISH_NUMBER_WITH_COUNTRY_CODE = '48600600600'
|
|
180
180
|
FORMATTED_AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '+61 390133997'
|
181
181
|
FRENCH_NUMBER_WITH_COUNTRY_CODE = '33627899541'
|
182
182
|
FORMATTED_FRENCH_NUMBER_WITH_COUNTRY_CODE = '+33 627899541'
|
183
|
+
CROATIA_NUMBER_WITH_COUNTRY_CODE = '385 98 352 085'
|
183
184
|
INVALID_NUMBER = '123456789 123456789 123456789 123456789'
|
184
185
|
NOT_A_NUMBER = 'HAHA'
|
185
186
|
JAPAN_COUNTRY = 'jp'
|
@@ -593,6 +594,12 @@ describe ActiveModel::Validations::HelperMethods do
|
|
593
594
|
expect(@home).to_not be_valid
|
594
595
|
expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
|
595
596
|
end
|
597
|
+
|
598
|
+
it 'should pass Gitlab issue #165' do
|
599
|
+
@home.phone_number = CROATIA_NUMBER_WITH_COUNTRY_CODE
|
600
|
+
@home.phone_number_country_code = 'HR'
|
601
|
+
expect(@home).to be_valid
|
602
|
+
end
|
596
603
|
end
|
597
604
|
|
598
605
|
#--------------------
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joost Hietbrink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|