phony_rails 0.12.10 → 0.12.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -37
- data/README.md +85 -49
- data/lib/phony_rails.rb +7 -1
- data/lib/phony_rails/locales/ru.yml +4 -0
- data/lib/phony_rails/locales/uk.yml +4 -0
- data/lib/phony_rails/string_extensions.rb +1 -0
- data/lib/phony_rails/version.rb +1 -1
- data/phony_rails.gemspec +1 -1
- data/spec/lib/phony_rails_spec.rb +132 -94
- data/spec/lib/validators/phony_validator_spec.rb +43 -27
- data/spec/spec_helper.rb +9 -9
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcd21433ed37b73d7a13e4a968426fe495824be7
|
4
|
+
data.tar.gz: c6906d6e411bbae10ecdacbe4ba6f571f0a11dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67e23bae153edccc3e21d6392a0d9d38394646ba3008701db2565d6c77842a0ad5156802a173b9d34eeb5a4408d5f7c220ff0c0ecb54f3516cf94f4b685ae2c9
|
7
|
+
data.tar.gz: bdb52a58cf910d0918f5b088178fea408fe8915affe747cbdc67e5fa3045082162c6e4df409f8b9d55fd5693b4061d166fcfb5ab375dc8ca44f9e022d45719f6
|
data/Gemfile.lock
CHANGED
@@ -8,33 +8,33 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (4.2.
|
12
|
-
activesupport (= 4.2.
|
11
|
+
activemodel (4.2.5)
|
12
|
+
activesupport (= 4.2.5)
|
13
13
|
builder (~> 3.1)
|
14
|
-
activerecord (4.2.
|
15
|
-
activemodel (= 4.2.
|
16
|
-
activesupport (= 4.2.
|
14
|
+
activerecord (4.2.5)
|
15
|
+
activemodel (= 4.2.5)
|
16
|
+
activesupport (= 4.2.5)
|
17
17
|
arel (~> 6.0)
|
18
|
-
activesupport (4.2.
|
18
|
+
activesupport (4.2.5)
|
19
19
|
i18n (~> 0.7)
|
20
20
|
json (~> 1.7, >= 1.7.7)
|
21
21
|
minitest (~> 5.1)
|
22
22
|
thread_safe (~> 0.3, >= 0.3.4)
|
23
23
|
tzinfo (~> 1.1)
|
24
24
|
arel (6.0.3)
|
25
|
-
bson (3.2.
|
25
|
+
bson (3.2.6)
|
26
26
|
builder (3.2.2)
|
27
27
|
coderay (1.1.0)
|
28
|
-
|
29
|
-
coveralls (0.8.2)
|
28
|
+
coveralls (0.8.8)
|
30
29
|
json (~> 1.8)
|
31
30
|
rest-client (>= 1.6.8, < 2)
|
32
31
|
simplecov (~> 0.10.0)
|
33
32
|
term-ansicolor (~> 1.3)
|
34
33
|
thor (~> 0.19.1)
|
34
|
+
tins (~> 1.6.0)
|
35
35
|
diff-lcs (1.2.5)
|
36
36
|
docile (1.1.5)
|
37
|
-
domain_name (0.5.
|
37
|
+
domain_name (0.5.25)
|
38
38
|
unf (>= 0.0.5, < 1.0.0)
|
39
39
|
ffi (1.9.10)
|
40
40
|
formatador (0.2.5)
|
@@ -60,55 +60,52 @@ GEM
|
|
60
60
|
domain_name (~> 0.5)
|
61
61
|
i18n (0.7.0)
|
62
62
|
json (1.8.3)
|
63
|
-
listen (3.0.
|
63
|
+
listen (3.0.4)
|
64
64
|
rb-fsevent (>= 0.9.3)
|
65
65
|
rb-inotify (>= 0.9)
|
66
66
|
lumberjack (1.0.9)
|
67
67
|
method_source (0.8.2)
|
68
|
-
mime-types (2.6.
|
69
|
-
minitest (5.8.
|
70
|
-
|
68
|
+
mime-types (2.6.2)
|
69
|
+
minitest (5.8.2)
|
70
|
+
mongo (2.1.2)
|
71
|
+
bson (~> 3.0)
|
72
|
+
mongoid (5.0.1)
|
71
73
|
activemodel (~> 4.0)
|
72
|
-
|
74
|
+
mongo (~> 2.1)
|
73
75
|
origin (~> 2.1)
|
74
76
|
tzinfo (>= 0.3.37)
|
75
|
-
moped (2.0.7)
|
76
|
-
bson (~> 3.0)
|
77
|
-
connection_pool (~> 2.0)
|
78
|
-
optionable (~> 0.2.0)
|
79
77
|
nenv (0.2.0)
|
80
|
-
netrc (0.
|
81
|
-
notiffany (0.0.
|
78
|
+
netrc (0.11.0)
|
79
|
+
notiffany (0.0.8)
|
82
80
|
nenv (~> 0.1)
|
83
81
|
shellany (~> 0.0)
|
84
|
-
optionable (0.2.0)
|
85
82
|
origin (2.1.1)
|
86
|
-
phony (2.
|
87
|
-
pry (0.10.
|
83
|
+
phony (2.15.8)
|
84
|
+
pry (0.10.3)
|
88
85
|
coderay (~> 1.1.0)
|
89
86
|
method_source (~> 0.8.1)
|
90
87
|
slop (~> 3.4)
|
91
88
|
rake (10.4.2)
|
92
|
-
rb-fsevent (0.9.
|
89
|
+
rb-fsevent (0.9.6)
|
93
90
|
rb-inotify (0.9.5)
|
94
91
|
ffi (>= 0.5.0)
|
95
92
|
rest-client (1.8.0)
|
96
93
|
http-cookie (>= 1.0.2, < 2.0)
|
97
94
|
mime-types (>= 1.16, < 3.0)
|
98
95
|
netrc (~> 0.7)
|
99
|
-
rspec (3.
|
100
|
-
rspec-core (~> 3.
|
101
|
-
rspec-expectations (~> 3.
|
102
|
-
rspec-mocks (~> 3.
|
103
|
-
rspec-core (3.
|
104
|
-
rspec-support (~> 3.
|
105
|
-
rspec-expectations (3.
|
96
|
+
rspec (3.4.0)
|
97
|
+
rspec-core (~> 3.4.0)
|
98
|
+
rspec-expectations (~> 3.4.0)
|
99
|
+
rspec-mocks (~> 3.4.0)
|
100
|
+
rspec-core (3.4.0)
|
101
|
+
rspec-support (~> 3.4.0)
|
102
|
+
rspec-expectations (3.4.0)
|
106
103
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
-
rspec-support (~> 3.
|
108
|
-
rspec-mocks (3.
|
104
|
+
rspec-support (~> 3.4.0)
|
105
|
+
rspec-mocks (3.4.0)
|
109
106
|
diff-lcs (>= 1.2.0, < 2.0)
|
110
|
-
rspec-support (~> 3.
|
111
|
-
rspec-support (3.
|
107
|
+
rspec-support (~> 3.4.0)
|
108
|
+
rspec-support (3.4.0)
|
112
109
|
shellany (0.0.1)
|
113
110
|
simplecov (0.10.0)
|
114
111
|
docile (~> 1.1.0)
|
@@ -116,7 +113,7 @@ GEM
|
|
116
113
|
simplecov-html (~> 0.10.0)
|
117
114
|
simplecov-html (0.10.0)
|
118
115
|
slop (3.6.0)
|
119
|
-
sqlite3 (1.3.
|
116
|
+
sqlite3 (1.3.11)
|
120
117
|
term-ansicolor (1.3.2)
|
121
118
|
tins (~> 1.0)
|
122
119
|
thor (0.19.1)
|
data/README.md
CHANGED
@@ -9,15 +9,21 @@ Find version information in the [CHANGELOG](CHANGELOG.md).
|
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'phony_rails' # Include phony_rails after mongoid (if you use mongoid, see issue #66 on github).
|
14
|
+
```
|
13
15
|
|
14
16
|
And then execute:
|
15
17
|
|
16
|
-
|
18
|
+
```
|
19
|
+
$ bundle
|
20
|
+
```
|
17
21
|
|
18
22
|
Or install it yourself as:
|
19
23
|
|
20
|
-
|
24
|
+
```
|
25
|
+
$ gem install phony_rails
|
26
|
+
```
|
21
27
|
|
22
28
|
## Usage
|
23
29
|
|
@@ -27,28 +33,31 @@ Or install it yourself as:
|
|
27
33
|
|
28
34
|
For **ActiveRecord**, in your model add:
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
```ruby
|
37
|
+
class SomeModel < ActiveRecord::Base
|
38
|
+
# Normalizes the attribute itself before validation
|
39
|
+
phony_normalize :phone_number, default_country_code: 'US'
|
33
40
|
|
34
|
-
|
35
|
-
|
41
|
+
# Normalizes attribute before validation and saves into other attribute
|
42
|
+
phony_normalize :phone_number, as: :phone_number_normalized_version, default_country_code: 'US'
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
# Creates method normalized_fax_number that returns the normalized version of fax_number
|
45
|
+
phony_normalized_method :fax_number
|
46
|
+
end
|
47
|
+
```
|
40
48
|
|
41
49
|
#### Mongoid
|
42
50
|
|
43
51
|
For **Mongoid**, in keeping with Mongoid plug-in conventions you must include the `Mongoid::Phony` module:
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# methods are same as ActiveRecord usage
|
50
|
-
end
|
53
|
+
```ruby
|
54
|
+
class SomeModel
|
55
|
+
include Mongoid::Document
|
56
|
+
include Mongoid::Phony
|
51
57
|
|
58
|
+
# methods are same as ActiveRecord usage
|
59
|
+
end
|
60
|
+
```
|
52
61
|
#### General info
|
53
62
|
|
54
63
|
The `:default_country_code` options is used to specify a country_code when normalizing.
|
@@ -57,14 +66,16 @@ PhonyRails will also check your model for a country_code method to use when norm
|
|
57
66
|
|
58
67
|
You can also do-it-yourself and call:
|
59
68
|
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
```ruby
|
70
|
+
# Options:
|
71
|
+
# :country_code => The country code we should use (forced).
|
72
|
+
# :default_country_code => Some fallback code (eg. 'NL') that can be used as default (comes from phony_normalize_numbers method).
|
63
73
|
|
64
|
-
|
74
|
+
PhonyRails.normalize_number('some number', country_code: 'NL')
|
65
75
|
|
66
|
-
|
67
|
-
|
76
|
+
PhonyRails.normalize_number('+4790909090', country_code: 'SE') # => '+464790909090' (forced to +46)
|
77
|
+
PhonyRails.normalize_number('+4790909090', default_country_code: 'SE') # => '+4790909090' (still +47 so not changed)
|
78
|
+
```
|
68
79
|
|
69
80
|
The country_code should always be a ISO 3166-1 alpha-2 (http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
|
70
81
|
|
@@ -72,11 +83,14 @@ The country_code should always be a ISO 3166-1 alpha-2 (http://en.wikipedia.org/
|
|
72
83
|
|
73
84
|
In your model use the Phony.plausible method to validate an attribute:
|
74
85
|
|
75
|
-
|
76
|
-
|
86
|
+
```ruby
|
87
|
+
validates :phone_number, phony_plausible: true
|
88
|
+
```
|
77
89
|
or the helper method:
|
78
90
|
|
79
|
-
|
91
|
+
```ruby
|
92
|
+
validates_plausible_phone :phone_number
|
93
|
+
```
|
80
94
|
|
81
95
|
this method use other validators under the hood to provide:
|
82
96
|
* presence validation using `ActiveModel::Validations::PresenceValidator`
|
@@ -84,35 +98,45 @@ this method use other validators under the hood to provide:
|
|
84
98
|
|
85
99
|
so we can use:
|
86
100
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
101
|
+
```ruby
|
102
|
+
validates_plausible_phone :phone_number, presence: true
|
103
|
+
validates_plausible_phone :phone_number, with: /^\+\d+/
|
104
|
+
validates_plausible_phone :phone_number, without: /^\+\d+/
|
105
|
+
validates_plausible_phone :phone_number, presence: true, with: /^\+\d+/
|
106
|
+
```
|
91
107
|
|
92
|
-
the i18n key is `:improbable_phone`. Languages supported by default: de, en, fr, it, ja, kh and
|
108
|
+
the i18n key is `:improbable_phone`. Languages supported by default: de, en, fr, it, ja, kh, tr, ua and ru.
|
93
109
|
|
94
110
|
You can also validate if a number has the correct country number:
|
95
111
|
|
96
|
-
|
112
|
+
```ruby
|
113
|
+
validates_plausible_phone :phone_number, country_number: '61'
|
114
|
+
```
|
97
115
|
|
98
116
|
or correct country code:
|
99
117
|
|
100
|
-
|
118
|
+
```ruby
|
119
|
+
validates_plausible_phone :phone_number, country_code: 'AU'
|
120
|
+
```
|
101
121
|
|
102
122
|
You can validate against the normalized input as opposed to the raw input:
|
103
123
|
|
104
|
-
|
105
|
-
|
124
|
+
```ruby
|
125
|
+
phony_normalize :phone_number, as: :phone_number_normalized, default_country_code: 'US'
|
126
|
+
validates_plausible_phone :phone_number, normalized_country_code: 'US'
|
127
|
+
```
|
106
128
|
|
107
129
|
#### Allowing records country codes to not match phone number country codes
|
108
130
|
|
109
131
|
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.
|
110
132
|
|
111
|
-
Additionally, `phony_normalize` will always add the records country code as the country number (eg. the user enters '+81xxx' for Japan and the records `country_code` is 'DE' then `phony_normalize` will change the number to '+4981'). You can turn this off by adding
|
133
|
+
Additionally, `phony_normalize` will always add the records country code as the country number (eg. the user enters '+81xxx' for Japan and the records `country_code` is 'DE' then `phony_normalize` will change the number to '+4981'). You can turn this off by adding `enforce_record_country: false` to the validation options. The country_code will then only be added if no country code is specified.
|
112
134
|
|
113
135
|
If you want to allow records from one country to have phone numbers from a different one, there are a couple of options you can use: `ignore_record_country_number` and `ignore_record_country_code`. Use them like so:
|
114
136
|
|
115
|
-
|
137
|
+
```ruby
|
138
|
+
validates :phone_number, phony_plausible: { ignore_record_country_code: true, ignore_record_country_number: true }
|
139
|
+
```
|
116
140
|
|
117
141
|
Obviously, you don't have to use both, and you may not need or want to set either.
|
118
142
|
|
@@ -120,35 +144,47 @@ Obviously, you don't have to use both, and you may not need or want to set eithe
|
|
120
144
|
|
121
145
|
In your views use:
|
122
146
|
|
123
|
-
|
124
|
-
|
125
|
-
|
147
|
+
```erb
|
148
|
+
<%= "311012341234".phony_formatted(format: :international, spaces: '-') %>
|
149
|
+
<%= "+31-10-12341234".phony_formatted(format: :international, spaces: '-') %>
|
150
|
+
<%= "+31(0)1012341234".phony_formatted(format: :international, spaces: '-') %>
|
151
|
+
```
|
126
152
|
|
127
153
|
To first normalize the String to a certain country use:
|
128
154
|
|
129
|
-
|
155
|
+
```erb
|
156
|
+
<%= "010-12341234".phony_formatted(normalize: :NL, format: :international, spaces: '-') %>
|
157
|
+
```
|
130
158
|
|
131
159
|
To return nil when a number is not valid:
|
132
160
|
|
133
|
-
|
161
|
+
```ruby
|
162
|
+
"123".phony_formatted(strict: true) # => nil
|
163
|
+
```
|
134
164
|
|
135
165
|
You can also use the bang method (phony_formatted!):
|
136
166
|
|
137
|
-
|
138
|
-
|
139
|
-
|
167
|
+
```ruby
|
168
|
+
number = "010-12341234"
|
169
|
+
number.phony_formatted!(normalize: :NL, format: :international)
|
170
|
+
number # => "+31 10 123 41234"
|
171
|
+
```
|
140
172
|
|
141
173
|
You can also easily normalize a phone number String:
|
142
174
|
|
143
|
-
|
144
|
-
|
145
|
-
|
175
|
+
```ruby
|
176
|
+
"+31 (0)30 1234 123".phony_normalized # => '31301234123'
|
177
|
+
"(0)30 1234 123".phony_normalized # => '301234123'
|
178
|
+
"(0)30 1234 123".phony_normalized(country_code: 'NL') # => '301234123'
|
179
|
+
```
|
146
180
|
|
147
181
|
### Find by normalized number
|
148
182
|
|
149
183
|
Say you want to find a record by a phone number. Best is to normalize user input and compare to an attribute stored in the db.
|
150
184
|
|
151
|
-
|
185
|
+
```ruby
|
186
|
+
Home.find_by_normalized_phone_number(PhonyRails.normalize_number(params[:phone_number]))
|
187
|
+
```
|
152
188
|
|
153
189
|
## Contributing
|
154
190
|
|
data/lib/phony_rails.rb
CHANGED
@@ -27,6 +27,7 @@ module PhonyRails
|
|
27
27
|
# http://www.redguava.com.au/2011/06/rails-convert-phone-numbers-to-international-format-for-sms/
|
28
28
|
def self.normalize_number(number, options = {})
|
29
29
|
return if number.nil?
|
30
|
+
original_number = number
|
30
31
|
number = number.clone # Just to be sure, we don't want to change the original.
|
31
32
|
number.gsub!(/[^\(\)\d\+]/, '') # Strips weird stuff from the number
|
32
33
|
return if number.blank?
|
@@ -44,6 +45,11 @@ module PhonyRails
|
|
44
45
|
if not (number =~ /\A\+/) # if we don't have a +
|
45
46
|
if Phony.plausible?("#{_default_country_number}#{number}") || !Phony.plausible?(number) || country_code_from_number(number).nil?
|
46
47
|
number = "#{_default_country_number}#{number}"
|
48
|
+
elsif (number =~ /^0[^0]/) && Phony.plausible?("#{_default_country_number}#{number.gsub(/^0/, '')}")
|
49
|
+
# If the number starts with ONE zero (two might indicate a country code)
|
50
|
+
# and this is a plausible number for the default_country
|
51
|
+
# we prefer that one.
|
52
|
+
number = "#{_default_country_number}#{number.gsub(/^0/, '')}"
|
47
53
|
end
|
48
54
|
end
|
49
55
|
# number = "#{_default_country_number}#{number}" unless Phony.plausible?(number)
|
@@ -52,7 +58,7 @@ module PhonyRails
|
|
52
58
|
options[:add_plus] = true if options[:add_plus].nil? && Phony.plausible?(normalized_number)
|
53
59
|
options[:add_plus] ? "+#{normalized_number}" : normalized_number
|
54
60
|
rescue
|
55
|
-
|
61
|
+
original_number # If all goes wrong .. we still return the original input.
|
56
62
|
end
|
57
63
|
|
58
64
|
def self.country_code_from_number(number)
|
data/lib/phony_rails/version.rb
CHANGED
data/phony_rails.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.version = PhonyRails::VERSION
|
18
18
|
|
19
19
|
gem.post_install_message = "PhonyRails v0.10.0 changes the way numbers are stored!"
|
20
|
-
gem.post_install_message = "It now
|
20
|
+
gem.post_install_message = "It now adds a '+' to the normalized number when it starts with a country number!"
|
21
21
|
|
22
22
|
gem.add_dependency "phony", '~> 2.12'
|
23
23
|
gem.add_dependency "activesupport", ">= 3.0"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
describe PhonyRails do
|
3
2
|
|
3
|
+
describe PhonyRails do
|
4
4
|
it "should not pollute the global namespace with a Country class" do
|
5
5
|
should_not be_const_defined "Country"
|
6
6
|
end
|
@@ -10,16 +10,16 @@ describe PhonyRails do
|
|
10
10
|
describe 'the phony_formatted method' do
|
11
11
|
|
12
12
|
it 'should not modify the original options Hash' do
|
13
|
-
options = {:
|
13
|
+
options = {normalize: :NL, format: :international}
|
14
14
|
"0101234123".phony_formatted(options)
|
15
|
-
expect(options).to eql({:
|
15
|
+
expect(options).to eql({normalize: :NL, format: :international})
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'with the bang!' do
|
19
19
|
|
20
20
|
it "should change the String using the bang method" do
|
21
21
|
s = "0101234123"
|
22
|
-
expect(s.phony_formatted!(:
|
22
|
+
expect(s.phony_formatted!(normalize: :NL, format: :international)).to eql('+31 10 123 4123')
|
23
23
|
expect(s).to eql("+31 10 123 4123")
|
24
24
|
end
|
25
25
|
|
@@ -30,13 +30,13 @@ describe PhonyRails do
|
|
30
30
|
it "should return nil with non plausible number" do
|
31
31
|
number = '+319090' # not valid
|
32
32
|
expect(Phony.plausible?(number)).to be false
|
33
|
-
expect(number.phony_formatted(:
|
33
|
+
expect(number.phony_formatted(strict: true)).to eql(nil)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should not return nil with plausible number" do
|
37
37
|
number = '+31101234123' # valid
|
38
38
|
expect(Phony.plausible?(number)).to be true
|
39
|
-
expect(number.phony_formatted(:
|
39
|
+
expect(number.phony_formatted(strict: true)).to_not eql(nil)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -44,30 +44,30 @@ describe PhonyRails do
|
|
44
44
|
describe 'with normalize option' do
|
45
45
|
|
46
46
|
it "should phony_format" do
|
47
|
-
expect("101234123".phony_formatted(:
|
48
|
-
expect("101234123".phony_formatted(:
|
47
|
+
expect("101234123".phony_formatted(normalize: :NL)).to eql('010 123 4123')
|
48
|
+
expect("101234123".phony_formatted(normalize: :NL, format: :international)).to eql('+31 10 123 4123')
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not change original String" do
|
52
52
|
s = "0101234123"
|
53
|
-
expect(s.phony_formatted(:
|
53
|
+
expect(s.phony_formatted(normalize: :NL)).to eql('010 123 4123')
|
54
54
|
expect(s).to eql("0101234123")
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should phony_format String with country code" do
|
58
|
-
expect("31101234123".phony_formatted(:
|
58
|
+
expect("31101234123".phony_formatted(normalize: :NL)).to eql('010 123 4123')
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should phony_format String with country code" do
|
62
|
-
expect("31101234123".phony_formatted(:
|
62
|
+
expect("31101234123".phony_formatted(normalize: :NL)).to eql('010 123 4123')
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should accept strings with non-digits in it" do
|
66
|
-
expect("+31-10-1234123".phony_formatted(:
|
66
|
+
expect("+31-10-1234123".phony_formatted(normalize: :NL, format: :international, spaces: '-')).to eql('+31-10-123-4123')
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should phony_format String with country code different than normalized value" do
|
70
|
-
expect("+4790909090".phony_formatted(:
|
70
|
+
expect("+4790909090".phony_formatted(normalize: :SE, format: :international)).to eql('+47 909 09 090')
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -105,14 +105,16 @@ describe PhonyRails do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should pass Github issue #85" do
|
108
|
-
expect(PhonyRails.normalize_number("47386160",
|
109
|
-
expect(PhonyRails.normalize_number("47386160",
|
108
|
+
expect(PhonyRails.normalize_number("47386160", default_country_code: 'NO')).to eq('+4747386160')
|
109
|
+
expect(PhonyRails.normalize_number("47386160", country_number: '47')).to eq('+4747386160')
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should pass Github issue #87" do
|
113
113
|
expect(PhonyRails.normalize_number('2318725305', country_code: 'US')).to eq('+12318725305')
|
114
114
|
expect(PhonyRails.normalize_number('2318725305', default_country_code: 'US')).to eq('+12318725305')
|
115
115
|
expect(PhonyRails.normalize_number('+2318725305', default_country_code: 'US')).to eq('+2318725305')
|
116
|
+
# expect(Phony.plausible?("#{PhonyRails.country_number_for('US')}02318725305")).to be_truthy
|
117
|
+
expect(PhonyRails.normalize_number('02318725305', default_country_code: 'US')).to eq('+12318725305')
|
116
118
|
end
|
117
119
|
|
118
120
|
it "should pass Github issue #89" do
|
@@ -126,20 +128,50 @@ describe PhonyRails do
|
|
126
128
|
expect(number.phony_normalized(country_code: 'NL')).to eq('+31301234123')
|
127
129
|
end
|
128
130
|
|
131
|
+
it "should pass Github issue #107" do
|
132
|
+
number = '04575700834'
|
133
|
+
expect(number.phony_normalized(country_code: 'FI')).to eq('+3584575700834')
|
134
|
+
# Seems this number can be interpreted as from multiple countries, following fails:
|
135
|
+
# expect(number.phony_normalized(default_country_code: 'FI')).to eq('+3584575700834')
|
136
|
+
# expect("04575700834".phony_formatted(normalize: 'FI', format: :international)).to eql('+358 45 757 00 834')
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should pass Github issue #113" do
|
140
|
+
number = "(951) 703-593"
|
141
|
+
expect(lambda {
|
142
|
+
number.phony_formatted!(normalize: 'US', spaces: '-', strict: true)
|
143
|
+
}).to raise_error(ArgumentError)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should pass Github issue #95" do
|
147
|
+
number = '02031234567'
|
148
|
+
expect(number.phony_normalized(default_country_code: 'GB')).to eq('+442031234567')
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should pass Github issue #121' do
|
152
|
+
number = '06-87-73-83-58'
|
153
|
+
expect(number.phony_normalized(default_country_code: 'FR')).to eq('+33687738358')
|
154
|
+
end
|
155
|
+
|
156
|
+
it "returns the original input if all goes wrong" do
|
157
|
+
expect(Phony).to receive(:plausible?).and_raise("unexpected error")
|
158
|
+
number = '(0)30 1234 123'
|
159
|
+
expect(number.phony_normalized(country_code: 'NL')).to eq number
|
160
|
+
end
|
129
161
|
end
|
130
162
|
|
131
163
|
it "should not change original String" do
|
132
164
|
s = '0101234123'
|
133
|
-
expect(s.phony_formatted(:
|
165
|
+
expect(s.phony_formatted(normalize: :NL)).to eql('010 123 4123')
|
134
166
|
expect(s).to eql('0101234123')
|
135
167
|
end
|
136
168
|
|
137
169
|
it "should phony_format a digits string with spaces String" do
|
138
|
-
expect("31 10 1234123".phony_formatted(:
|
170
|
+
expect("31 10 1234123".phony_formatted(format: :international, spaces: '-')).to eql('+31-10-123-4123')
|
139
171
|
end
|
140
172
|
|
141
173
|
it "should phony_format a digits String" do
|
142
|
-
expect("31101234123".phony_formatted(:
|
174
|
+
expect("31101234123".phony_formatted(format: :international, spaces: '-')).to eql('+31-10-123-4123')
|
143
175
|
end
|
144
176
|
|
145
177
|
it "returns nil if implausible phone" do
|
@@ -159,14 +191,14 @@ describe PhonyRails do
|
|
159
191
|
end
|
160
192
|
|
161
193
|
it 'should not modify the original options Hash' do
|
162
|
-
options = {:
|
194
|
+
options = {normalize: :NL, format: :international}
|
163
195
|
"0101234123".phony_normalized(options)
|
164
|
-
expect(options).to eql({:
|
196
|
+
expect(options).to eql({normalize: :NL, format: :international})
|
165
197
|
end
|
166
198
|
|
167
199
|
context "when String misses a country_code" do
|
168
200
|
it "should normalize with :country_code option" do
|
169
|
-
expect("010 1231234".phony_normalized(:
|
201
|
+
expect("010 1231234".phony_normalized(country_code: :NL)).to eql("+31101231234")
|
170
202
|
end
|
171
203
|
|
172
204
|
it "should normalize without :country_code option" do
|
@@ -174,13 +206,13 @@ describe PhonyRails do
|
|
174
206
|
end
|
175
207
|
|
176
208
|
it "should normalize with :add_plus option" do
|
177
|
-
expect("010 1231234".phony_normalized(:
|
209
|
+
expect("010 1231234".phony_normalized(country_code: :NL, add_plus: false)).to eql("31101231234")
|
178
210
|
end
|
179
211
|
|
180
212
|
end
|
181
213
|
|
182
214
|
it "should normalize with :add_plus option" do
|
183
|
-
expect("+31 (0)10 1231234".phony_normalized(:
|
215
|
+
expect("+31 (0)10 1231234".phony_normalized(add_plus: false)).to eql("31101231234")
|
184
216
|
end
|
185
217
|
|
186
218
|
it "should normalize a String" do
|
@@ -195,19 +227,19 @@ describe PhonyRails do
|
|
195
227
|
context 'number with a country code' do
|
196
228
|
|
197
229
|
it "should not add default_country_code" do
|
198
|
-
expect(PhonyRails.normalize_number('+4790909090', :
|
199
|
-
expect(PhonyRails.normalize_number('004790909090', :
|
200
|
-
expect(PhonyRails.normalize_number('4790909090', :
|
230
|
+
expect(PhonyRails.normalize_number('+4790909090', default_country_code: 'SE')).to eql('+4790909090') # SE = +46
|
231
|
+
expect(PhonyRails.normalize_number('004790909090', default_country_code: 'SE')).to eql('+4790909090')
|
232
|
+
expect(PhonyRails.normalize_number('4790909090', default_country_code: 'NO')).to eql('+4790909090') # NO = +47
|
201
233
|
end
|
202
234
|
|
203
235
|
it "should force add country_code" do
|
204
|
-
expect(PhonyRails.normalize_number('+4790909090', :
|
205
|
-
expect(PhonyRails.normalize_number('004790909090', :
|
206
|
-
expect(PhonyRails.normalize_number('4790909090', :
|
236
|
+
expect(PhonyRails.normalize_number('+4790909090', country_code: 'SE')).to eql('+464790909090')
|
237
|
+
expect(PhonyRails.normalize_number('004790909090', country_code: 'SE')).to eql('+4604790909090') # FIXME: differs due to Phony.normalize in v2.7.1?!
|
238
|
+
expect(PhonyRails.normalize_number('4790909090', country_code: 'SE')).to eql('+464790909090')
|
207
239
|
end
|
208
240
|
|
209
241
|
it "should recognize lowercase country codes" do
|
210
|
-
expect(PhonyRails.normalize_number('4790909090', :
|
242
|
+
expect(PhonyRails.normalize_number('4790909090', country_code: 'se')).to eql('+464790909090')
|
211
243
|
end
|
212
244
|
|
213
245
|
end
|
@@ -215,47 +247,47 @@ describe PhonyRails do
|
|
215
247
|
context 'number without a country code' do
|
216
248
|
|
217
249
|
it "should normalize with a default_country_code" do
|
218
|
-
expect(PhonyRails.normalize_number('010-1234123', :
|
250
|
+
expect(PhonyRails.normalize_number('010-1234123', default_country_code: 'NL')).to eql('+31101234123')
|
219
251
|
end
|
220
252
|
|
221
253
|
it "should normalize with a country_code" do
|
222
|
-
expect(PhonyRails.normalize_number('010-1234123', :
|
223
|
-
expect(PhonyRails.normalize_number('010-1234123', :
|
254
|
+
expect(PhonyRails.normalize_number('010-1234123', country_code: 'NL', default_country_code: 'DE')).to eql('+31101234123')
|
255
|
+
expect(PhonyRails.normalize_number('010-1234123', country_code: 'NL')).to eql('+31101234123')
|
224
256
|
end
|
225
257
|
|
226
258
|
it "should handle different countries" do
|
227
|
-
expect(PhonyRails.normalize_number('(030) 8 61 29 06', :
|
228
|
-
expect(PhonyRails.normalize_number('0203 330 8897', :
|
259
|
+
expect(PhonyRails.normalize_number('(030) 8 61 29 06', country_code: 'DE')).to eql('+49308612906')
|
260
|
+
expect(PhonyRails.normalize_number('0203 330 8897', country_code: 'GB')).to eql('+442033308897')
|
229
261
|
end
|
230
262
|
|
231
263
|
it "should prefer country_code over default_country_code" do
|
232
|
-
expect(PhonyRails.normalize_number('(030) 8 61 29 06', :
|
264
|
+
expect(PhonyRails.normalize_number('(030) 8 61 29 06', country_code: 'DE', default_country_code: 'NL')).to eql('+49308612906')
|
233
265
|
end
|
234
266
|
|
235
267
|
it "should recognize lowercase country codes" do
|
236
|
-
expect(PhonyRails.normalize_number('010-1234123', :
|
268
|
+
expect(PhonyRails.normalize_number('010-1234123', country_code: 'nl')).to eql('+31101234123')
|
237
269
|
end
|
238
270
|
|
239
271
|
end
|
240
272
|
|
241
273
|
it "should handle some edge cases (with country_code)" do
|
242
|
-
expect(PhonyRails.normalize_number('some nasty stuff in this +31 number 10-1234123 string', :
|
243
|
-
expect(PhonyRails.normalize_number('070-4157134', :
|
244
|
-
expect(PhonyRails.normalize_number('0031-70-4157134', :
|
245
|
-
expect(PhonyRails.normalize_number('+31-70-4157134', :
|
246
|
-
expect(PhonyRails.normalize_number('0322-69497', :
|
247
|
-
expect(PhonyRails.normalize_number('+32 3 226 94 97', :
|
248
|
-
expect(PhonyRails.normalize_number('0450 764 000', :
|
274
|
+
expect(PhonyRails.normalize_number('some nasty stuff in this +31 number 10-1234123 string', country_code: 'NL')).to eql('+31101234123')
|
275
|
+
expect(PhonyRails.normalize_number('070-4157134', country_code: 'NL')).to eql('+31704157134')
|
276
|
+
expect(PhonyRails.normalize_number('0031-70-4157134', country_code: 'NL')).to eql('+31704157134')
|
277
|
+
expect(PhonyRails.normalize_number('+31-70-4157134', country_code: 'NL')).to eql('+31704157134')
|
278
|
+
expect(PhonyRails.normalize_number('0322-69497', country_code: 'BE')).to eql('+3232269497')
|
279
|
+
expect(PhonyRails.normalize_number('+32 3 226 94 97', country_code: 'BE')).to eql('+3232269497')
|
280
|
+
expect(PhonyRails.normalize_number('0450 764 000', country_code: 'AU')).to eql('+61450764000')
|
249
281
|
end
|
250
282
|
|
251
283
|
it "should handle some edge cases (with default_country_code)" do
|
252
|
-
expect(PhonyRails.normalize_number('some nasty stuff in this +31 number 10-1234123 string', :
|
253
|
-
expect(PhonyRails.normalize_number('070-4157134', :
|
254
|
-
expect(PhonyRails.normalize_number('0031-70-4157134', :
|
255
|
-
expect(PhonyRails.normalize_number('+31-70-4157134', :
|
256
|
-
expect(PhonyRails.normalize_number('0322-69497', :
|
257
|
-
expect(PhonyRails.normalize_number('+32 3 226 94 97', :
|
258
|
-
expect(PhonyRails.normalize_number('0450 764 000', :
|
284
|
+
expect(PhonyRails.normalize_number('some nasty stuff in this +31 number 10-1234123 string', country_code: 'NL')).to eql('+31101234123')
|
285
|
+
expect(PhonyRails.normalize_number('070-4157134', default_country_code: 'NL')).to eql('+31704157134')
|
286
|
+
expect(PhonyRails.normalize_number('0031-70-4157134', default_country_code: 'NL')).to eql('+31704157134')
|
287
|
+
expect(PhonyRails.normalize_number('+31-70-4157134', default_country_code: 'NL')).to eql('+31704157134')
|
288
|
+
expect(PhonyRails.normalize_number('0322-69497', default_country_code: 'BE')).to eql('+3232269497')
|
289
|
+
expect(PhonyRails.normalize_number('+32 3 226 94 97', default_country_code: 'BE')).to eql('+3232269497')
|
290
|
+
expect(PhonyRails.normalize_number('0450 764 000', default_country_code: 'AU')).to eql('+61450764000')
|
259
291
|
end
|
260
292
|
|
261
293
|
it "should normalize even an implausible number" do
|
@@ -263,7 +295,8 @@ describe PhonyRails do
|
|
263
295
|
end
|
264
296
|
end
|
265
297
|
|
266
|
-
describe 'PhonyRails
|
298
|
+
describe 'PhonyRails.plausible_number?' do
|
299
|
+
subject { described_class }
|
267
300
|
let(:valid_number) { '1 555 555 5555' }
|
268
301
|
let(:invalid_number) { '123456789 123456789 123456789 123456789' }
|
269
302
|
let(:normalizable_number) { '555 555 5555' }
|
@@ -272,35 +305,40 @@ describe PhonyRails do
|
|
272
305
|
let(:nil_number) { nil }
|
273
306
|
|
274
307
|
it "should return true for a valid number" do
|
275
|
-
|
308
|
+
is_expected.to be_plausible_number valid_number, country_code: 'US'
|
276
309
|
end
|
277
310
|
|
278
311
|
it "should return false for an invalid number" do
|
279
|
-
|
312
|
+
is_expected.not_to be_plausible_number invalid_number, country_code: 'US'
|
280
313
|
end
|
281
314
|
|
282
315
|
it "should return true for a normalizable number" do
|
283
|
-
|
316
|
+
is_expected.to be_plausible_number normalizable_number, country_code: 'US'
|
284
317
|
end
|
285
318
|
|
286
319
|
it "should return false for a valid number with the wrong country code" do
|
287
|
-
|
320
|
+
is_expected.not_to be_plausible_number normalizable_number, country_code: 'FR'
|
288
321
|
end
|
289
322
|
|
290
323
|
it "should return true for a well formatted valid number" do
|
291
|
-
|
324
|
+
is_expected.to be_plausible_number formatted_french_number_with_country_code, country_code: 'FR'
|
292
325
|
end
|
293
326
|
|
294
327
|
it "should return false for an empty number" do
|
295
|
-
|
328
|
+
is_expected.not_to be_plausible_number empty_number, country_code: 'US'
|
296
329
|
end
|
297
330
|
|
298
331
|
it "should return false for a nil number" do
|
299
|
-
|
332
|
+
is_expected.not_to be_plausible_number nil_number, country_code: 'US'
|
300
333
|
end
|
301
334
|
|
302
335
|
it "should return false when no country code is supplied" do
|
303
|
-
|
336
|
+
is_expected.not_to be_plausible_number normalizable_number
|
337
|
+
end
|
338
|
+
|
339
|
+
it "returns false if something goes wrong" do
|
340
|
+
expect(Phony).to receive(:plausible?).twice.and_raise("unexpected error")
|
341
|
+
is_expected.not_to be_plausible_number normalizable_number, country_code: 'US'
|
304
342
|
end
|
305
343
|
end
|
306
344
|
|
@@ -331,25 +369,25 @@ describe PhonyRails do
|
|
331
369
|
describe 'defining model#phony_normalize' do
|
332
370
|
it "should not accept :as option with multiple attribute names" do
|
333
371
|
expect(lambda {
|
334
|
-
model_klass.phony_normalize(:phone_number, :phone1_method, :
|
372
|
+
model_klass.phony_normalize(:phone_number, :phone1_method, as: 'non_existing_attribute')
|
335
373
|
}).to raise_error(ArgumentError)
|
336
374
|
end
|
337
375
|
|
338
376
|
it "should accept :as option with non existing attribute name" do
|
339
377
|
expect(lambda {
|
340
|
-
dummy_klass.phony_normalize(:non_existing_attribute, :
|
378
|
+
dummy_klass.phony_normalize(:non_existing_attribute, as: 'non_existing_attribute')
|
341
379
|
}).to_not raise_error
|
342
380
|
end
|
343
381
|
|
344
382
|
it "should accept :as option with single non existing attribute name" do
|
345
383
|
expect(lambda {
|
346
|
-
dummy_klass.phony_normalize(:phone_number, :
|
384
|
+
dummy_klass.phony_normalize(:phone_number, as: 'something_else')
|
347
385
|
}).to_not raise_error
|
348
386
|
end
|
349
387
|
|
350
388
|
it "should accept :as option with single existing attribute name" do
|
351
389
|
expect(lambda {
|
352
|
-
model_klass.phony_normalize(:phone_number, :
|
390
|
+
model_klass.phony_normalize(:phone_number, as: 'phone_number_as_normalized')
|
353
391
|
}).to_not raise_error
|
354
392
|
end
|
355
393
|
|
@@ -378,82 +416,82 @@ describe PhonyRails do
|
|
378
416
|
describe 'using model#phony_normalized_method' do
|
379
417
|
# Following examples have complete number (with country code!)
|
380
418
|
it "should return a normalized version of an attribute" do
|
381
|
-
model = model_klass.new(:
|
419
|
+
model = model_klass.new(phone_attribute: "+31-(0)10-1234123")
|
382
420
|
expect(model.normalized_phone_attribute).to eql('+31101234123')
|
383
421
|
end
|
384
422
|
|
385
423
|
it "should return a normalized version of a method" do
|
386
|
-
model = model_klass.new(:
|
424
|
+
model = model_klass.new(phone_method: "+31-(0)10-1234123")
|
387
425
|
expect(model.normalized_phone_method).to eql('+31101234123')
|
388
426
|
end
|
389
427
|
|
390
428
|
# Following examples have incomplete number
|
391
429
|
it "should normalize even a unplausible number (no country code)" do
|
392
|
-
model = model_klass.new(:
|
430
|
+
model = model_klass.new(phone_attribute: "(0)10-1234123")
|
393
431
|
expect(model.normalized_phone_attribute).to eql('101234123')
|
394
432
|
end
|
395
433
|
|
396
434
|
it "should use country_code option" do
|
397
|
-
model = model_klass.new(:
|
398
|
-
expect(model.normalized_phone_attribute(:
|
435
|
+
model = model_klass.new(phone_attribute: "(0)10-1234123")
|
436
|
+
expect(model.normalized_phone_attribute(country_code: 'NL')).to eql('+31101234123')
|
399
437
|
end
|
400
438
|
|
401
439
|
it "should use country_code object method" do
|
402
|
-
model = model_klass.new(:
|
440
|
+
model = model_klass.new(phone_attribute: "(0)10-1234123", country_code: 'NL')
|
403
441
|
expect(model.normalized_phone_attribute).to eql('+31101234123')
|
404
442
|
end
|
405
443
|
|
406
444
|
it "should fallback to default_country_code option" do
|
407
|
-
model = model_klass.new(:
|
445
|
+
model = model_klass.new(phone1_method: "(030) 8 61 29 06")
|
408
446
|
expect(model.normalized_phone1_method).to eql('+49308612906')
|
409
447
|
end
|
410
448
|
|
411
449
|
it "should overwrite default_country_code option with object method" do
|
412
|
-
model = model_klass.new(:
|
450
|
+
model = model_klass.new(phone1_method: "(030) 8 61 29 06", country_code: 'NL')
|
413
451
|
expect(model.normalized_phone1_method).to eql('+31308612906')
|
414
452
|
end
|
415
453
|
|
416
454
|
it "should overwrite default_country_code option with option" do
|
417
|
-
model = model_klass.new(:
|
418
|
-
expect(model.normalized_phone1_method(:
|
455
|
+
model = model_klass.new(phone1_method: "(030) 8 61 29 06")
|
456
|
+
expect(model.normalized_phone1_method(country_code: 'NL')).to eql('+31308612906')
|
419
457
|
end
|
420
458
|
|
421
459
|
it "should use last passed options" do
|
422
|
-
model = model_klass.new(:
|
423
|
-
expect(model.normalized_phone1_method(:
|
424
|
-
expect(model.normalized_phone1_method(:
|
425
|
-
expect(model.normalized_phone1_method(:
|
460
|
+
model = model_klass.new(phone1_method: "(030) 8 61 29 06")
|
461
|
+
expect(model.normalized_phone1_method(country_code: 'NL')).to eql('+31308612906')
|
462
|
+
expect(model.normalized_phone1_method(country_code: 'DE')).to eql('+49308612906')
|
463
|
+
expect(model.normalized_phone1_method(country_code: nil)).to eql('+49308612906')
|
426
464
|
end
|
427
465
|
|
428
466
|
it "should use last object method" do
|
429
|
-
model = model_klass.new(:
|
467
|
+
model = model_klass.new(phone1_method: "(030) 8 61 29 06")
|
430
468
|
model.country_code = 'NL'
|
431
469
|
expect(model.normalized_phone1_method).to eql('+31308612906')
|
432
470
|
model.country_code = 'DE'
|
433
471
|
expect(model.normalized_phone1_method).to eql('+49308612906')
|
434
472
|
model.country_code = nil
|
435
|
-
expect(model.normalized_phone1_method(:
|
473
|
+
expect(model.normalized_phone1_method(country_code: nil)).to eql('+49308612906')
|
436
474
|
end
|
437
475
|
end
|
438
476
|
|
439
477
|
describe 'using model#phony_normalize' do
|
440
478
|
it "should not change normalized numbers (see #76)" do
|
441
|
-
model = model_klass.new(:
|
442
|
-
expect(model
|
479
|
+
model = model_klass.new(phone_number: "+31-(0)10-1234123")
|
480
|
+
expect(model).to be_valid
|
443
481
|
expect(model.phone_number).to eql('+31101234123')
|
444
482
|
end
|
445
483
|
|
446
484
|
it "should set a normalized version of an attribute using :as option" do
|
447
|
-
model_klass.phony_normalize :phone_number, :
|
448
|
-
model = model_klass.new(:
|
449
|
-
expect(model
|
485
|
+
model_klass.phony_normalize :phone_number, as: :phone_number_as_normalized
|
486
|
+
model = model_klass.new(phone_number: "+31-(0)10-1234123")
|
487
|
+
expect(model).to be_valid
|
450
488
|
expect(model.phone_number_as_normalized).to eql('+31101234123')
|
451
489
|
end
|
452
490
|
|
453
491
|
it "should not add a + using :add_plus option" do
|
454
|
-
model_klass.phony_normalize :phone_number, :
|
455
|
-
model = model_klass.new(:
|
456
|
-
expect(model
|
492
|
+
model_klass.phony_normalize :phone_number, add_plus: false
|
493
|
+
model = model_klass.new(phone_number: "+31-(0)10-1234123")
|
494
|
+
expect(model).to be_valid
|
457
495
|
expect(model.phone_number).to eql('31101234123')
|
458
496
|
end
|
459
497
|
|
@@ -466,7 +504,7 @@ describe PhonyRails do
|
|
466
504
|
end
|
467
505
|
|
468
506
|
it "should raise a RuntimeError at validation if the :as option attribute doesn't exist" do
|
469
|
-
dummy_klass.phony_normalize :phone_number, :
|
507
|
+
dummy_klass.phony_normalize :phone_number, as: :non_existing_attribute
|
470
508
|
dummy = dummy_klass.new
|
471
509
|
expect(lambda {
|
472
510
|
dummy.valid?
|
@@ -476,12 +514,12 @@ describe PhonyRails do
|
|
476
514
|
end
|
477
515
|
|
478
516
|
describe 'ActiveRecord' do
|
479
|
-
let(:model_klass){ ActiveRecordModel }
|
480
|
-
let(:dummy_klass){ ActiveRecordDummy }
|
517
|
+
let(:model_klass) { ActiveRecordModel }
|
518
|
+
let(:dummy_klass) { ActiveRecordDummy }
|
481
519
|
it_behaves_like 'model with PhonyRails'
|
482
520
|
|
483
521
|
it "should correctly keep a hard set country_code" do
|
484
|
-
model = model_klass.new(:
|
522
|
+
model = model_klass.new(fax_number: '+1 978 555 0000')
|
485
523
|
expect(model.valid?).to be true
|
486
524
|
expect(model.fax_number).to eql('+19785550000')
|
487
525
|
expect(model.save).to be true
|
@@ -545,8 +583,8 @@ describe PhonyRails do
|
|
545
583
|
end
|
546
584
|
|
547
585
|
describe 'Mongoid' do
|
548
|
-
let(:model_klass){ MongoidModel }
|
549
|
-
let(:dummy_klass){ MongoidDummy }
|
586
|
+
let(:model_klass) { MongoidModel }
|
587
|
+
let(:dummy_klass) { MongoidDummy }
|
550
588
|
it_behaves_like 'model with PhonyRails'
|
551
589
|
end
|
552
590
|
end
|