phony_rails 0.14.4 → 0.14.5
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 +5 -13
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/phony_rails.rb +2 -2
- data/lib/phony_rails/version.rb +1 -1
- data/lib/validators/phony_validator.rb +1 -0
- data/spec/lib/validators/phony_validator_spec.rb +13 -0
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OTc5ZGJhMTAyM2ZhNmVmNWZhODJmN2JiZWVjYzViMzNmMWUyY2NmNQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e5820adc5e9ecff0a12904b4b8622784bcc13bf
|
4
|
+
data.tar.gz: 276760afba65090f145ac77fdd6e8bf28a8abf20
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
Y2NjYzQ0MDczZWVjODM0ZDE4MzQ5YjRlNjA5NzIwOTczNWJiOWMxNmE0MTdj
|
11
|
-
Yzg2NjJlMjU5YTJkNDYwMWFlOWFiMDIwMTA3MDFjNWU0Yjk2N2E=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZmMxYmY5NTU0MDcxOWJkN2JiMjY1NWU3MDhiNDA0MmUxMmZmNDc3OGM0YTMy
|
14
|
-
YmQ2M2M4NGRjNzQ1MzE2Yzg2ODk3ZDVlMGFmZjYyYzY5ZjUzNjA3ODIyM2Fm
|
15
|
-
MjM3MDdjZTU1NTc0OTlhNWU4ZTY1ZWZiMGI4MDI1MDJiOGIyNGM=
|
6
|
+
metadata.gz: a80c625610f3956da0b2841d78f6c6faffe5b66f8b1e24e74024a3071a63f450d221b984bf2d5cd80d3d052b409b9cfe2187bb0cb3536d5d5bf2c080eb7dd133
|
7
|
+
data.tar.gz: 048f69f27476c6590f8ebbef288ce38937821a1b06ef7de7b496e372fa086eb81710f3d864ea662e7cde442693af6efa50f17b0edd85a7a06a1a7531aa4b7f1b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -151,6 +151,8 @@ phony_normalize :phone_number, as: :phone_number_normalized, default_country_cod
|
|
151
151
|
validates_plausible_phone :phone_number, normalized_country_code: 'US'
|
152
152
|
```
|
153
153
|
|
154
|
+
Validation supports phone numbers with extension, such as `+18181231234 x1234` or `'+1 (818)151-5483 #4312'` out-of-the-box.
|
155
|
+
|
154
156
|
#### Allowing records country codes to not match phone number country codes
|
155
157
|
|
156
158
|
You may have a record specifying one country (via a `country_code` attribute) but using a phone number from another country. For example, your record may be from Japan but have a phone number from the Philippines. By default, `phony_rails` will consider your record's `country_code` as part of the validation. If that country doesn't match the country code in the phone number, validation will fail.
|
data/lib/phony_rails.rb
CHANGED
@@ -106,7 +106,7 @@ module PhonyRails
|
|
106
106
|
false
|
107
107
|
end
|
108
108
|
|
109
|
-
COMMON_EXTENSIONS = /[ ]*(ext|ex|x|xt|#|:)+[^0-9]*\(
|
109
|
+
COMMON_EXTENSIONS = /[ ]*(ext|ex|x|xt|#|:)+[^0-9]*\(?([-0-9]{1,})\)?#?$/i
|
110
110
|
|
111
111
|
def self.extract_extension(number_and_ext)
|
112
112
|
return [nil, nil] if number_and_ext.nil?
|
@@ -199,7 +199,7 @@ end
|
|
199
199
|
# check whether it is ActiveRecord or Mongoid being used
|
200
200
|
ActiveRecord::Base.send :include, PhonyRails::Extension if defined?(ActiveRecord)
|
201
201
|
|
202
|
-
ActiveModel::Model.send :include, PhonyRails::Extension if defined?(ActiveModel)
|
202
|
+
ActiveModel::Model.send :include, PhonyRails::Extension if defined?(ActiveModel::Model)
|
203
203
|
|
204
204
|
if defined?(Mongoid)
|
205
205
|
module Mongoid::Phony
|
data/lib/phony_rails/version.rb
CHANGED
@@ -10,6 +10,7 @@ class PhonyPlausibleValidator < ActiveModel::EachValidator
|
|
10
10
|
|
11
11
|
@record = record
|
12
12
|
value = PhonyRails.normalize_number(value.dup, default_country_code: normalized_country_code) if normalized_country_code
|
13
|
+
value = PhonyRails.extract_extension(value).first
|
13
14
|
@record.errors.add(attribute, error_message) unless Phony.plausible?(value, cc: country_number)
|
14
15
|
end
|
15
16
|
|
@@ -172,6 +172,8 @@ end
|
|
172
172
|
|
173
173
|
I18n.locale = :en
|
174
174
|
VALID_NUMBER = '1 555 555 5555'.freeze
|
175
|
+
VALID_NUMBER_WITH_EXTENSION = '1 555 555 5555 x123'.freeze
|
176
|
+
VALID_NUMBER_WITH_INVALID_EXTENSION = '1 555 555 5555 x1a'.freeze
|
175
177
|
NORMALIZABLE_NUMBER = '555 555 5555'.freeze
|
176
178
|
AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '61390133997'.freeze
|
177
179
|
POLISH_NUMBER_WITH_COUNTRY_CODE = '48600600600'.freeze
|
@@ -199,12 +201,23 @@ describe PhonyPlausibleValidator do
|
|
199
201
|
expect(@home).to be_valid
|
200
202
|
end
|
201
203
|
|
204
|
+
it 'should validate a valid number with extension' do
|
205
|
+
@home.phone_number = VALID_NUMBER_WITH_EXTENSION
|
206
|
+
expect(@home).to be_valid
|
207
|
+
end
|
208
|
+
|
202
209
|
it 'should invalidate an invalid number' do
|
203
210
|
@home.phone_number = INVALID_NUMBER
|
204
211
|
expect(@home).to_not be_valid
|
205
212
|
expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
|
206
213
|
end
|
207
214
|
|
215
|
+
it 'should invalidate an valid number with invalid extension' do
|
216
|
+
@home.phone_number = VALID_NUMBER_WITH_INVALID_EXTENSION
|
217
|
+
expect(@home).to_not be_valid
|
218
|
+
expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
|
219
|
+
end
|
220
|
+
|
208
221
|
it 'should invalidate not a number' do
|
209
222
|
@home.phone_number = NOT_A_NUMBER
|
210
223
|
expect(@home).to_not be_valid
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joost Hietbrink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phony
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.15'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.15'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mongoid
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
69
|
description: This Gem adds useful methods to your Rails app to validate, display and
|
@@ -74,11 +74,11 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
- .gitignore
|
78
|
-
- .rspec
|
79
|
-
- .rubocop.yml
|
80
|
-
- .rubocop_todo.yml
|
81
|
-
- .travis.yml
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".rubocop_todo.yml"
|
81
|
+
- ".travis.yml"
|
82
82
|
- CHANGELOG.md
|
83
83
|
- Gemfile
|
84
84
|
- Gemfile.lock
|
@@ -117,17 +117,17 @@ require_paths:
|
|
117
117
|
- lib
|
118
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- -
|
120
|
+
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
124
|
requirements:
|
125
|
-
- -
|
125
|
+
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.5.1
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: This Gem adds useful methods to your Rails app to validate, display and save
|