russian_phone 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +9 -0
- data/lib/russian_phone/codes.rb +2 -0
- data/lib/russian_phone/field.rb +7 -1
- data/lib/russian_phone/format_validator.rb +3 -1
- data/lib/russian_phone/number.rb +2 -2
- data/lib/russian_phone/presence_validator.rb +1 -1
- data/lib/russian_phone/version.rb +1 -1
- data/russian_phone.gemspec +5 -4
- data/spec/phone_spec.rb +124 -115
- data/spec/spec_helper.rb +7 -2
- data/spec/support/mongoid.yml +6 -1
- metadata +36 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7aeaf94f764188fd507b23450b75c326c3ffc6074a56f5500701fd23256ce2
|
4
|
+
data.tar.gz: 54cd7b0a6ee69ba2a7e434b33dee4ef70ea8a98411e953957d51407e1e2ab80e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ee2f16cd01ea105abd80f0100361688c303bc23eea2802d02b3d72c88c4d6bcdd4eea9c69aef1d55514721f0e0f3e3e0c38cf5e33271f9c9eeb50783f529711
|
7
|
+
data.tar.gz: 5ff4d42b9647eb79aacb5fc06fcd90f80434a1b9e7410ff6af154268166250f118d27fb95c3edeaee958a50d02bacebb52d5c3065c41cc59d5afec9f82dd0dde
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.3.1
|
data/README.md
CHANGED
@@ -21,6 +21,15 @@ https://gitlab.com/rocket-science/russian_phone
|
|
21
21
|
|
22
22
|
Разработка - glebtv и [Rocket Scicence](https://github.com/rs-pro)
|
23
23
|
|
24
|
+
## Mongoid 8
|
25
|
+
|
26
|
+
Новый синтаксис полей, требуется заменить
|
27
|
+
```
|
28
|
+
field :phone, type: RussianPhone.field(default_country: 7), validate: true, required: true
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
24
33
|
## Альтернативные решения
|
25
34
|
|
26
35
|
https://github.com/floere/phony
|
data/lib/russian_phone/codes.rb
CHANGED
data/lib/russian_phone/field.rb
CHANGED
@@ -5,7 +5,9 @@ module RussianPhone
|
|
5
5
|
def validate(record)
|
6
6
|
options[:fields].each do |field|
|
7
7
|
unless record.send(field).phone.blank?
|
8
|
-
|
8
|
+
unless record.send(field).valid? && record.send(field).city_allowed?
|
9
|
+
record.errors.add(field, 'Неверный телефонный номер')
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/lib/russian_phone/number.rb
CHANGED
@@ -218,7 +218,7 @@ module RussianPhone
|
|
218
218
|
# Телефон слишком длинный для телефона без кода города
|
219
219
|
return nil
|
220
220
|
else
|
221
|
-
if Codes.codes_for(clean_string.length).include?
|
221
|
+
if !opts[:default_city].blank? && Codes.codes_for(clean_string.length).include?(opts[:default_city])
|
222
222
|
return {country: opts[:default_country], city: opts[:default_city], subscriber: clean_string}
|
223
223
|
else
|
224
224
|
# Количество цифр в телефоне не соответствует количеству цифр местных номеров города
|
@@ -289,4 +289,4 @@ module RussianPhone
|
|
289
289
|
end
|
290
290
|
end
|
291
291
|
end
|
292
|
-
end
|
292
|
+
end
|
data/russian_phone.gemspec
CHANGED
@@ -21,14 +21,15 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.add_development_dependency 'mongoid', '>= 3.0.0'
|
23
23
|
gem.add_development_dependency "rails", ">= 3.0"
|
24
|
-
|
25
|
-
gem.add_development_dependency 'sqlite3'
|
26
|
-
gem.add_development_dependency "rspec-rails"
|
24
|
+
gem.add_development_dependency "rspec"
|
25
|
+
gem.add_development_dependency 'sqlite3', '~> 1.4'
|
26
|
+
gem.add_development_dependency "rspec-rails"
|
27
27
|
gem.add_development_dependency 'activerecord'
|
28
28
|
gem.add_development_dependency 'bundler'
|
29
|
-
gem.add_development_dependency 'rake'
|
29
|
+
gem.add_development_dependency 'rake'
|
30
30
|
gem.add_development_dependency 'simplecov'
|
31
31
|
gem.add_development_dependency 'pry'
|
32
32
|
gem.add_development_dependency 'database_cleaner'
|
33
|
+
gem.add_development_dependency 'database_cleaner-mongoid'
|
33
34
|
end
|
34
35
|
|
data/spec/phone_spec.rb
CHANGED
@@ -17,14 +17,23 @@ describe RussianPhone do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
describe '#full' do
|
21
|
+
it "formats number" do
|
22
|
+
RussianPhone::Number.new('906 111-11-11').full.should eq '+7 (906) 111-11-11'
|
23
|
+
RussianPhone::Number.new('9061111111').full.should eq '+7 (906) 111-11-11'
|
24
|
+
RussianPhone::Number.new('79061111111').full.should eq '+7 (906) 111-11-11'
|
25
|
+
RussianPhone::Number.new('89061111111').full.should eq '+7 (906) 111-11-11'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
describe 'when parsing' do
|
21
30
|
it 'should parse 8-800-111-11-11 number' do
|
22
31
|
phone = RussianPhone::Number.new('8-800-111-11-11', default_country: 7)
|
23
32
|
phone.should_not be_nil
|
24
|
-
phone.valid?.should
|
33
|
+
phone.valid?.should be true
|
25
34
|
|
26
|
-
phone.cell?.should
|
27
|
-
phone.free?.should
|
35
|
+
phone.cell?.should be false
|
36
|
+
phone.free?.should be true
|
28
37
|
|
29
38
|
phone.city.should eq '800'
|
30
39
|
phone.country.should eq '7'
|
@@ -35,10 +44,10 @@ describe RussianPhone do
|
|
35
44
|
it 'should parse (906) 111-11-11 number' do
|
36
45
|
phone = RussianPhone::Number.new('(906) 111-11-11', default_country: 7)
|
37
46
|
phone.should_not be_nil
|
38
|
-
phone.valid?.should
|
47
|
+
phone.valid?.should be true
|
39
48
|
|
40
|
-
phone.cell?.should
|
41
|
-
phone.free?.should
|
49
|
+
phone.cell?.should be true
|
50
|
+
phone.free?.should be false
|
42
51
|
|
43
52
|
phone.city.should eq '906'
|
44
53
|
phone.country.should eq '7'
|
@@ -49,10 +58,10 @@ describe RussianPhone do
|
|
49
58
|
it 'should parse 111-11-11 number with default city' do
|
50
59
|
phone = RussianPhone::Number.new('111-11-11', default_country: 7, default_city: 495)
|
51
60
|
phone.should_not be_nil
|
52
|
-
phone.valid?.should
|
61
|
+
phone.valid?.should be true
|
53
62
|
|
54
|
-
phone.cell?.should
|
55
|
-
phone.free?.should
|
63
|
+
phone.cell?.should be false
|
64
|
+
phone.free?.should be false
|
56
65
|
|
57
66
|
phone.city.should eq '495'
|
58
67
|
phone.country.should eq '7'
|
@@ -62,16 +71,16 @@ describe RussianPhone do
|
|
62
71
|
|
63
72
|
it 'should not parse 111-11-11 number without default city' do
|
64
73
|
phone = RussianPhone::Number.new('111-11-11', default_country: 7)
|
65
|
-
phone.valid?.should
|
74
|
+
phone.valid?.should be false
|
66
75
|
end
|
67
76
|
|
68
77
|
it 'should parse 1111111 number with default city' do
|
69
78
|
phone = RussianPhone::Number.new('1111111', default_country: 7, default_city: 495)
|
70
79
|
phone.should_not be_nil
|
71
|
-
phone.valid?.should
|
80
|
+
phone.valid?.should be true
|
72
81
|
|
73
|
-
phone.cell?.should
|
74
|
-
phone.free?.should
|
82
|
+
phone.cell?.should be false
|
83
|
+
phone.free?.should be false
|
75
84
|
|
76
85
|
phone.city.should eq '495'
|
77
86
|
phone.country.should eq '7'
|
@@ -82,10 +91,10 @@ describe RussianPhone do
|
|
82
91
|
it 'should parse +7 (495) 111-11-11 number' do
|
83
92
|
phone = RussianPhone::Number.new('+7 (495) 111-11-11')
|
84
93
|
phone.should_not be_nil
|
85
|
-
phone.valid?.should
|
94
|
+
phone.valid?.should be true
|
86
95
|
|
87
|
-
phone.cell?.should
|
88
|
-
phone.free?.should
|
96
|
+
phone.cell?.should be false
|
97
|
+
phone.free?.should be false
|
89
98
|
|
90
99
|
phone.city.should eq '495'
|
91
100
|
phone.country.should eq '7'
|
@@ -96,10 +105,10 @@ describe RussianPhone do
|
|
96
105
|
it 'should parse +7 (495) 111-11-11 number' do
|
97
106
|
phone = RussianPhone::Number.new('+7 (495) 111-11-11')
|
98
107
|
phone.should_not be_nil
|
99
|
-
phone.valid?.should
|
108
|
+
phone.valid?.should be true
|
100
109
|
|
101
|
-
phone.cell?.should
|
102
|
-
phone.free?.should
|
110
|
+
phone.cell?.should be false
|
111
|
+
phone.free?.should be false
|
103
112
|
|
104
113
|
phone.city.should eq '495'
|
105
114
|
phone.country.should eq '7'
|
@@ -110,10 +119,10 @@ describe RussianPhone do
|
|
110
119
|
it 'should parse 8(4912)12-34-56 number' do
|
111
120
|
phone = RussianPhone::Number.new('+7 (4912) 12-34-56', default_country: 7)
|
112
121
|
phone.should_not be_nil
|
113
|
-
phone.valid?.should
|
122
|
+
phone.valid?.should be true
|
114
123
|
|
115
|
-
phone.cell?.should
|
116
|
-
phone.free?.should
|
124
|
+
phone.cell?.should be false
|
125
|
+
phone.free?.should be false
|
117
126
|
|
118
127
|
phone.city.should eq '4912'
|
119
128
|
phone.country.should eq '7'
|
@@ -124,10 +133,10 @@ describe RussianPhone do
|
|
124
133
|
it 'should parse 2-34-56 number whith default city' do
|
125
134
|
phone = RussianPhone::Number.new('2-34-56', default_country: 7, default_city: 87252)
|
126
135
|
phone.should_not be_nil
|
127
|
-
phone.valid?.should
|
136
|
+
phone.valid?.should be true
|
128
137
|
|
129
|
-
phone.cell?.should
|
130
|
-
phone.free?.should
|
138
|
+
phone.cell?.should be false
|
139
|
+
phone.free?.should be false
|
131
140
|
|
132
141
|
phone.city.should eq '87252'
|
133
142
|
phone.country.should eq '7'
|
@@ -138,10 +147,10 @@ describe RussianPhone do
|
|
138
147
|
it 'should parse 12-34-56 number whith default city' do
|
139
148
|
phone = RussianPhone::Number.new('12-34-56', default_country: 7, default_city: 4912)
|
140
149
|
phone.should_not be_nil
|
141
|
-
phone.valid?.should
|
150
|
+
phone.valid?.should be true
|
142
151
|
|
143
|
-
phone.cell?.should
|
144
|
-
phone.free?.should
|
152
|
+
phone.cell?.should be false
|
153
|
+
phone.free?.should be false
|
145
154
|
|
146
155
|
phone.city.should eq '4912'
|
147
156
|
phone.country.should eq '7'
|
@@ -154,10 +163,10 @@ describe RussianPhone do
|
|
154
163
|
|
155
164
|
phone = RussianPhone::Number.new('8(34356)5-67-89', default_country: 7)
|
156
165
|
phone.should_not be_nil
|
157
|
-
phone.valid?.should
|
166
|
+
phone.valid?.should be true
|
158
167
|
|
159
|
-
phone.cell?.should
|
160
|
-
phone.free?.should
|
168
|
+
phone.cell?.should be false
|
169
|
+
phone.free?.should be false
|
161
170
|
|
162
171
|
phone.city.should eq '343'
|
163
172
|
phone.country.should eq '7'
|
@@ -170,10 +179,10 @@ describe RussianPhone do
|
|
170
179
|
|
171
180
|
phone = RussianPhone::Number.new('7 (906) 123-45-67', default_country: 7)
|
172
181
|
phone.should_not be_nil
|
173
|
-
phone.valid?.should
|
182
|
+
phone.valid?.should be true
|
174
183
|
|
175
|
-
phone.cell?.should
|
176
|
-
phone.free?.should
|
184
|
+
phone.cell?.should be true
|
185
|
+
phone.free?.should be false
|
177
186
|
phone.extra.should eq ''
|
178
187
|
phone.city.should eq '906'
|
179
188
|
phone.country.should eq '7'
|
@@ -184,10 +193,10 @@ describe RussianPhone do
|
|
184
193
|
it 'should handle phones with extra stuff [8 (906) 111-11-11 доб. 123]' do
|
185
194
|
phone = RussianPhone::Number.new('8 (906) 111-11-11 доб. 123', default_country: 7)
|
186
195
|
phone.should_not be_nil
|
187
|
-
phone.valid?.should
|
196
|
+
phone.valid?.should be true
|
188
197
|
|
189
|
-
phone.cell?.should
|
190
|
-
phone.free?.should
|
198
|
+
phone.cell?.should be true
|
199
|
+
phone.free?.should be false
|
191
200
|
|
192
201
|
phone.city.should eq '906'
|
193
202
|
phone.country.should eq '7'
|
@@ -198,10 +207,10 @@ describe RussianPhone do
|
|
198
207
|
it 'should handle phones with extra stuff [8 (906) 111-11-11 д. 123]' do
|
199
208
|
phone = RussianPhone::Number.new('8 (906) 111-11-11 д. 123', default_country: 7)
|
200
209
|
phone.should_not be_nil
|
201
|
-
phone.valid?.should
|
210
|
+
phone.valid?.should be true
|
202
211
|
|
203
|
-
phone.cell?.should
|
204
|
-
phone.free?.should
|
212
|
+
phone.cell?.should be true
|
213
|
+
phone.free?.should be false
|
205
214
|
|
206
215
|
phone.city.should eq '906'
|
207
216
|
phone.country.should eq '7'
|
@@ -212,10 +221,10 @@ describe RussianPhone do
|
|
212
221
|
it 'should handle phones with extra stuff [89061010101 д. 123]' do
|
213
222
|
phone = RussianPhone::Number.new('89061010101 д. 123', default_country: 7)
|
214
223
|
phone.should_not be_nil
|
215
|
-
phone.valid?.should
|
224
|
+
phone.valid?.should be true
|
216
225
|
|
217
|
-
phone.cell?.should
|
218
|
-
phone.free?.should
|
226
|
+
phone.cell?.should be true
|
227
|
+
phone.free?.should be false
|
219
228
|
|
220
229
|
phone.city.should eq '906'
|
221
230
|
phone.country.should eq '7'
|
@@ -226,10 +235,10 @@ describe RussianPhone do
|
|
226
235
|
it 'should handle phones with extra stuff [89061010101-д. 123]' do
|
227
236
|
phone = RussianPhone::Number.new('89061010101-д. 123', default_country: 7)
|
228
237
|
phone.should_not be_nil
|
229
|
-
phone.valid?.should
|
238
|
+
phone.valid?.should be true
|
230
239
|
|
231
|
-
phone.cell?.should
|
232
|
-
phone.free?.should
|
240
|
+
phone.cell?.should be true
|
241
|
+
phone.free?.should be false
|
233
242
|
|
234
243
|
phone.city.should eq '906'
|
235
244
|
phone.country.should eq '7'
|
@@ -240,10 +249,10 @@ describe RussianPhone do
|
|
240
249
|
it 'should handle phones with unknown codes [8 (533) 111-11-11]' do
|
241
250
|
phone = RussianPhone::Number.new('8 (533) 111-11-11', default_country: 7)
|
242
251
|
phone.should_not be_nil
|
243
|
-
phone.valid?.should
|
252
|
+
phone.valid?.should be true
|
244
253
|
|
245
|
-
phone.cell?.should
|
246
|
-
phone.free?.should
|
254
|
+
phone.cell?.should be false
|
255
|
+
phone.free?.should be false
|
247
256
|
|
248
257
|
phone.city.should eq '533'
|
249
258
|
phone.country.should eq '7'
|
@@ -295,15 +304,15 @@ describe RussianPhone do
|
|
295
304
|
it "should parse #{str}" do
|
296
305
|
phone = RussianPhone::Number.new(str, default_country: 7)
|
297
306
|
phone.should_not be_nil
|
298
|
-
phone.valid?.should
|
307
|
+
phone.valid?.should be true
|
299
308
|
|
300
309
|
if %w(927 926).include? result[1].to_s
|
301
|
-
phone.cell?.should
|
310
|
+
phone.cell?.should be true
|
302
311
|
else
|
303
|
-
phone.cell?.should
|
312
|
+
phone.cell?.should be false
|
304
313
|
end
|
305
314
|
|
306
|
-
phone.free?.should
|
315
|
+
phone.free?.should be false
|
307
316
|
|
308
317
|
phone.country.should eq result[0].to_s
|
309
318
|
phone.city.should eq result[1].to_s
|
@@ -323,7 +332,7 @@ describe RussianPhone do
|
|
323
332
|
bad_phones.each do |phone|
|
324
333
|
it "should not parse #{phone}" do
|
325
334
|
phone = RussianPhone::Number.new(phone, default_country: 7)
|
326
|
-
phone.valid?.should
|
335
|
+
phone.valid?.should be false
|
327
336
|
end
|
328
337
|
end
|
329
338
|
end
|
@@ -345,11 +354,11 @@ describe RussianPhone do
|
|
345
354
|
describe 'when storing with activerecord' do
|
346
355
|
it 'should parse, store and retrieve numbers correctly' do
|
347
356
|
u = ArUser.new(name: 'test', phone: '906 111 11 11')
|
348
|
-
u.save.should
|
357
|
+
u.save.should be true
|
349
358
|
u = ArUser.first
|
350
359
|
u.phone.should eq '+7 (906) 111-11-11'
|
351
|
-
u.phone.cell?.should
|
352
|
-
u.phone.free?.should
|
360
|
+
u.phone.cell?.should be true
|
361
|
+
u.phone.free?.should be false
|
353
362
|
|
354
363
|
u.phone.clean.should eq '79061111111'
|
355
364
|
|
@@ -360,39 +369,39 @@ describe RussianPhone do
|
|
360
369
|
|
361
370
|
it 'should fail validation when validate is on and phone is invalid' do
|
362
371
|
u = ArUser.new(validated_phone: '123')
|
363
|
-
u.valid?.should
|
364
|
-
u.save.should
|
372
|
+
u.valid?.should be false
|
373
|
+
u.save.should be false
|
365
374
|
u.errors.messages.should eq({:validated_phone =>["Неверный телефонный номер"]})
|
366
375
|
end
|
367
376
|
|
368
377
|
it 'should pass validation when validate is on and phone is valid' do
|
369
378
|
u = ArUser.new(validated_phone: '495 121 11 11')
|
370
|
-
u.valid?.should
|
371
|
-
u.save.should
|
379
|
+
u.valid?.should be true
|
380
|
+
u.save.should be true
|
372
381
|
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
373
382
|
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
374
383
|
end
|
375
384
|
|
376
385
|
it 'should pass validation when validate is on and phone is valid' do
|
377
386
|
u = ArUser.new(validated_phone: '7495 121 11 11')
|
378
|
-
u.valid?.should
|
379
|
-
u.save.should
|
387
|
+
u.valid?.should be true
|
388
|
+
u.save.should be true
|
380
389
|
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
381
390
|
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
382
391
|
end
|
383
392
|
|
384
393
|
it 'should pass validation when validate is on and phone is valid' do
|
385
394
|
u = ArUser.new(validated_phone: '7 495 121 11 11')
|
386
|
-
u.valid?.should
|
387
|
-
u.save.should
|
395
|
+
u.valid?.should be true
|
396
|
+
u.save.should be true
|
388
397
|
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
389
398
|
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
390
399
|
end
|
391
400
|
|
392
401
|
it 'should pass validation when validate is on and phone is valid' do
|
393
402
|
u = ArUser.new(validated_phone: '8495 121 11 11')
|
394
|
-
u.valid?.should
|
395
|
-
u.save.should
|
403
|
+
u.valid?.should be true
|
404
|
+
u.save.should be true
|
396
405
|
ArUser.first.read_attribute(:validated_phone).should eq '+7 (495) 121-11-11'
|
397
406
|
ArUser.first.validated_phone.should eq '+7 (495) 121-11-11'
|
398
407
|
end
|
@@ -401,12 +410,12 @@ describe RussianPhone do
|
|
401
410
|
describe 'when storing with mongoid' do
|
402
411
|
it 'should parse, store and retrieve numbers correctly' do
|
403
412
|
u = User.new(name: 'test', phone: '906 111 11 11')
|
404
|
-
u.save.should
|
413
|
+
u.save.should be true
|
405
414
|
u = User.first
|
406
415
|
|
407
416
|
u.phone.should eq '+7 (906) 111-11-11'
|
408
|
-
u.phone.cell?.should
|
409
|
-
u.phone.free?.should
|
417
|
+
u.phone.cell?.should be true
|
418
|
+
u.phone.free?.should be false
|
410
419
|
|
411
420
|
u.phone.clean.should eq '79061111111'
|
412
421
|
|
@@ -416,15 +425,15 @@ describe RussianPhone do
|
|
416
425
|
end
|
417
426
|
|
418
427
|
it 'should respect field options' do
|
419
|
-
u = User.create(name: 'test', phone_in_495: '
|
420
|
-
u.save.should
|
428
|
+
u = User.create(name: 'test', phone_in_495: '+7 (495) 111-11-11', phone_in_812: '222 2222')
|
429
|
+
u.save.should be true
|
421
430
|
|
422
431
|
u = User.first
|
423
432
|
|
424
433
|
u.phone_in_495.class.name.should eq 'RussianPhone::Number'
|
425
434
|
u.phone_in_495.should eq '+7 (495) 111-11-11'
|
426
|
-
u.phone_in_495.cell?.should
|
427
|
-
u.phone_in_495.free?.should
|
435
|
+
u.phone_in_495.cell?.should be false
|
436
|
+
u.phone_in_495.free?.should be false
|
428
437
|
|
429
438
|
u.phone_in_495.country.should eq '7'
|
430
439
|
u.phone_in_495.city.should eq '495'
|
@@ -435,8 +444,8 @@ describe RussianPhone do
|
|
435
444
|
|
436
445
|
u.phone_in_812.class.name.should eq 'RussianPhone::Number'
|
437
446
|
u.phone_in_812.should eq '+7 (812) 222-22-22'
|
438
|
-
u.phone_in_812.cell?.should
|
439
|
-
u.phone_in_812.free?.should
|
447
|
+
u.phone_in_812.cell?.should be false
|
448
|
+
u.phone_in_812.free?.should be false
|
440
449
|
|
441
450
|
u.phone_in_812.country.should eq '7'
|
442
451
|
u.phone_in_812.city.should eq '812'
|
@@ -448,39 +457,39 @@ describe RussianPhone do
|
|
448
457
|
|
449
458
|
it 'should fail validation when validate is on and phone is invalid' do
|
450
459
|
u = UserWithValidation.new(phone: '123')
|
451
|
-
u.valid?.should
|
452
|
-
u.save.should
|
460
|
+
u.valid?.should be false
|
461
|
+
u.save.should be false
|
453
462
|
u.errors.messages.should eq({:phone =>["Неверный телефонный номер"]})
|
454
463
|
end
|
455
464
|
|
456
465
|
it 'should pass validation when validate is on and phone is valid' do
|
457
466
|
u = UserWithValidation.new(phone: '495 121 11 11')
|
458
|
-
u.valid?.should
|
459
|
-
u.save.should
|
467
|
+
u.valid?.should be true
|
468
|
+
u.save.should be true
|
460
469
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11'
|
461
470
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11'
|
462
471
|
end
|
463
472
|
|
464
473
|
it 'should pass validation when validate is on and phone is valid' do
|
465
474
|
u = UserWithValidation.new(phone: '7495 121 11 11')
|
466
|
-
u.valid?.should
|
467
|
-
u.save.should
|
475
|
+
u.valid?.should be true
|
476
|
+
u.save.should be true
|
468
477
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11'
|
469
478
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11'
|
470
479
|
end
|
471
480
|
|
472
481
|
it 'should pass validation when validate is on and phone is valid' do
|
473
482
|
u = UserWithValidation.new(phone: '7 495 121 11 11')
|
474
|
-
u.valid?.should
|
475
|
-
u.save.should
|
483
|
+
u.valid?.should be true
|
484
|
+
u.save.should be true
|
476
485
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11'
|
477
486
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11'
|
478
487
|
end
|
479
488
|
|
480
489
|
it 'should pass validation when validate is on and phone is valid' do
|
481
490
|
u = UserWithValidation.new(phone: '8495 121 11 11')
|
482
|
-
u.valid?.should
|
483
|
-
u.save.should
|
491
|
+
u.valid?.should be true
|
492
|
+
u.save.should be true
|
484
493
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11'
|
485
494
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11'
|
486
495
|
end
|
@@ -488,103 +497,103 @@ describe RussianPhone do
|
|
488
497
|
it 'should pass validation when validate is on and phone is valid' do
|
489
498
|
u = UserWithValidation.new(phone: '7495123-12-12 доб 123')
|
490
499
|
|
491
|
-
u.valid?.should
|
492
|
-
u.save.should
|
500
|
+
u.valid?.should be true
|
501
|
+
u.save.should be true
|
493
502
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 123-12-12 доб 123'
|
494
503
|
UserWithValidation.first.phone.should eq '+7 (495) 123-12-12 доб 123'
|
495
504
|
end
|
496
505
|
|
497
506
|
it 'should pass validation when phone is valid (unknown city code)' do
|
498
507
|
u = UserWithAnyCode.new(phone: '7701123-12-12 доб 123')
|
499
|
-
u.valid?.should
|
500
|
-
u.save.should
|
508
|
+
u.valid?.should be true
|
509
|
+
u.save.should be true
|
501
510
|
UserWithAnyCode.first.read_attribute(:phone).should eq '+7 (701) 123-12-12 доб 123'
|
502
511
|
UserWithAnyCode.first.phone.should eq '+7 (701) 123-12-12 доб 123'
|
503
512
|
end
|
504
513
|
|
505
514
|
it 'should pass validation when validate is on and phone is valid (unknown city code)' do
|
506
515
|
u = UserWithAnyCode.new(phone: '701123-12-12 доб 123')
|
507
|
-
u.valid?.should
|
508
|
-
u.save.should
|
516
|
+
u.valid?.should be true
|
517
|
+
u.save.should be true
|
509
518
|
UserWithAnyCode.first.read_attribute(:phone).should eq '+7 (701) 123-12-12 доб 123'
|
510
519
|
UserWithAnyCode.first.phone.should eq '+7 (701) 123-12-12 доб 123'
|
511
520
|
end
|
512
521
|
|
513
522
|
it 'should pass validation when validate is on and phone is valid' do
|
514
523
|
u = UserWithValidation.new(phone: '8 495 121 11 11')
|
515
|
-
u.valid?.should
|
516
|
-
u.save.should
|
524
|
+
u.valid?.should be true
|
525
|
+
u.save.should be true
|
517
526
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11'
|
518
527
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11'
|
519
528
|
end
|
520
529
|
|
521
530
|
it 'should pass validation when validate is on and phone is valid' do
|
522
531
|
u = UserWithValidation.new(phone: '+7 495 121 11 11')
|
523
|
-
u.valid?.should
|
524
|
-
u.save.should
|
532
|
+
u.valid?.should be true
|
533
|
+
u.save.should be true
|
525
534
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11'
|
526
535
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11'
|
527
536
|
end
|
528
537
|
|
529
538
|
it 'should pass validation when validate is on and phone is valid' do
|
530
539
|
u = UserWithValidation.new(phone: '495 121 11 11 доб 123')
|
531
|
-
u.valid?.should
|
532
|
-
u.save.should
|
540
|
+
u.valid?.should be true
|
541
|
+
u.save.should be true
|
533
542
|
UserWithValidation.first.read_attribute(:phone).should eq '+7 (495) 121-11-11 доб 123'
|
534
543
|
UserWithValidation.first.phone.should eq '+7 (495) 121-11-11 доб 123'
|
535
544
|
end
|
536
545
|
|
537
546
|
it 'should fail validation when validate is on and city is not in allowed_cities' do
|
538
547
|
u = UserWithValidation.new(phone: '906 121 11 11')
|
539
|
-
u.valid?.should
|
540
|
-
u.save.should
|
548
|
+
u.valid?.should be false
|
549
|
+
u.save.should be false
|
541
550
|
u.errors.messages.should eq({:phone =>["Неверный телефонный номер"]})
|
542
551
|
end
|
543
552
|
|
544
553
|
it 'should pass validation when validate is off and phone is invalid' do
|
545
554
|
u = UserWithoutValidation.new(phone: '123')
|
546
555
|
|
547
|
-
u.valid?.should
|
548
|
-
u.save.should
|
556
|
+
u.valid?.should be true
|
557
|
+
u.save.should be true
|
549
558
|
end
|
550
559
|
|
551
560
|
it 'should pass validation when validate is off and phone is valid' do
|
552
561
|
u = UserWithoutValidation.new(phone: '495 121 11 11')
|
553
562
|
|
554
|
-
u.valid?.should
|
555
|
-
u.save.should
|
563
|
+
u.valid?.should be true
|
564
|
+
u.save.should be true
|
556
565
|
end
|
557
566
|
|
558
567
|
it 'should pass validation when validate is off and city is not in allowed_cities' do
|
559
568
|
u = UserWithoutValidation.new(phone: '906 121 11 11')
|
560
569
|
|
561
|
-
u.valid?.should
|
562
|
-
u.save.should
|
570
|
+
u.valid?.should be true
|
571
|
+
u.save.should be true
|
563
572
|
end
|
564
573
|
|
565
574
|
it 'should pass validation when required but not validated' do
|
566
575
|
u = UserWithRequired.new(phone: '906 121 11 11')
|
567
576
|
|
568
|
-
u.valid?.should
|
569
|
-
u.save.should
|
577
|
+
u.valid?.should be true
|
578
|
+
u.save.should be true
|
570
579
|
end
|
571
580
|
|
572
581
|
it 'should pass validation when required but not validated' do
|
573
582
|
u = UserWithRequired.new(phone: '11 11')
|
574
583
|
|
575
|
-
u.valid?.should
|
576
|
-
u.save.should
|
584
|
+
u.valid?.should be true
|
585
|
+
u.save.should be true
|
577
586
|
end
|
578
587
|
|
579
588
|
it 'should fail validation when required and not present' do
|
580
589
|
u = UserWithRequired.new()
|
581
|
-
u.valid?.should
|
582
|
-
u.save.should
|
590
|
+
u.valid?.should be false
|
591
|
+
u.save.should be false
|
583
592
|
|
584
593
|
u = UserWithRequired.new(phone: '')
|
585
|
-
u.valid?.should
|
586
|
-
u.save.should
|
594
|
+
u.valid?.should be false
|
595
|
+
u.save.should be false
|
587
596
|
end
|
588
597
|
end
|
589
598
|
|
590
|
-
end
|
599
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,11 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
5
|
require 'rspec'
|
6
6
|
require 'simplecov'
|
7
|
+
require 'sqlite3'
|
7
8
|
require 'mongoid'
|
8
9
|
require 'active_record'
|
9
10
|
require 'database_cleaner'
|
11
|
+
require 'database_cleaner-mongoid'
|
10
12
|
require 'pry'
|
11
13
|
SimpleCov.start
|
12
14
|
require 'russian_phone'
|
@@ -31,21 +33,24 @@ ActiveRecord::Base.send :include, RussianPhone::ActiveRecord
|
|
31
33
|
# in ./support/ and its subdirectories.
|
32
34
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
33
35
|
|
34
|
-
DatabaseCleaner.orm = "mongoid"
|
36
|
+
# DatabaseCleaner.orm = "mongoid"
|
35
37
|
|
36
38
|
RSpec.configure do |config|
|
37
39
|
config.before(:all) do
|
38
|
-
DatabaseCleaner.strategy = :
|
40
|
+
DatabaseCleaner.strategy = :deletion
|
39
41
|
end
|
40
42
|
|
41
43
|
config.before(:each) do
|
44
|
+
DatabaseCleaner[:mongoid].start
|
42
45
|
DatabaseCleaner.start
|
43
46
|
end
|
44
47
|
|
45
48
|
config.after(:each) do
|
49
|
+
DatabaseCleaner[:mongoid].clean
|
46
50
|
DatabaseCleaner.clean
|
47
51
|
ArUser.destroy_all
|
48
52
|
end
|
49
53
|
|
54
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
50
55
|
config.mock_with :rspec
|
51
56
|
end
|
data/spec/support/mongoid.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: russian_phone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GlebTv
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -42,44 +42,44 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '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
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.4'
|
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
|
-
version: '
|
68
|
+
version: '1.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activerecord
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: database_cleaner-mongoid
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: Russian Phone Numbers for Mongoid
|
168
182
|
email:
|
169
183
|
- glebtv@gmail.com
|
@@ -202,7 +216,7 @@ files:
|
|
202
216
|
homepage: https://gitlab.com/rocket-science/russian_phone
|
203
217
|
licenses: []
|
204
218
|
metadata: {}
|
205
|
-
post_install_message:
|
219
|
+
post_install_message:
|
206
220
|
rdoc_options: []
|
207
221
|
require_paths:
|
208
222
|
- lib
|
@@ -217,8 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
231
|
- !ruby/object:Gem::Version
|
218
232
|
version: '0'
|
219
233
|
requirements: []
|
220
|
-
rubygems_version: 3.
|
221
|
-
signing_key:
|
234
|
+
rubygems_version: 3.5.9
|
235
|
+
signing_key:
|
222
236
|
specification_version: 4
|
223
237
|
summary: Поле для хранения Российских телефонных номеров в Mongoid
|
224
238
|
test_files:
|