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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d89d8025ce3a7d212137465e97c88b61436b74721834fa8b1e05d77321398506
4
- data.tar.gz: ddfa3266a52fea0bc16d284043185ebc41139a381b260bfcc09b9ad0cd25405e
3
+ metadata.gz: 1e7aeaf94f764188fd507b23450b75c326c3ffc6074a56f5500701fd23256ce2
4
+ data.tar.gz: 54cd7b0a6ee69ba2a7e434b33dee4ef70ea8a98411e953957d51407e1e2ab80e
5
5
  SHA512:
6
- metadata.gz: f4f4e8cc5edf893e31d84a120e57b3b63edbea943c15974ec2b1f7c57e19ee4394bb8519c981bb76f54b52978bbdeb25111c98079712aa226e51c2aa51d5e4a1
7
- data.tar.gz: 95bf4e385a8278395df6cfc95d46dc8b9c7d751f759f33dda5465578a4907b5f3043813e2bbf2c9a0661441cb196eb96e4947ddd92ba1a49eb5037f8dafe5a78
6
+ metadata.gz: 0ee2f16cd01ea105abd80f0100361688c303bc23eea2802d02b3d72c88c4d6bcdd4eea9c69aef1d55514721f0e0f3e3e0c38cf5e33271f9c9eeb50783f529711
7
+ data.tar.gz: 5ff4d42b9647eb79aacb5fc06fcd90f80434a1b9e7410ff6af154268166250f118d27fb95c3edeaee958a50d02bacebb52d5c3065c41cc59d5afec9f82dd0dde
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
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
@@ -141,6 +141,8 @@ module RussianPhone
141
141
  ndcs_with_6_subscriber_digits
142
142
  elsif digits == 5
143
143
  ndcs_with_5_subscriber_digits
144
+ else
145
+ []
144
146
  end
145
147
  end
146
148
  end
@@ -44,5 +44,11 @@ module RussianPhone
44
44
  else object
45
45
  end
46
46
  end
47
+
48
+ # Mongoid 8 hack
49
+ def is_a?(o)
50
+ return true if o == Class
51
+ super
52
+ end
47
53
  end
48
- end
54
+ end
@@ -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
- record.errors[field] << 'Неверный телефонный номер' unless record.send(field).valid? && record.send(field).city_allowed?
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
@@ -218,7 +218,7 @@ module RussianPhone
218
218
  # Телефон слишком длинный для телефона без кода города
219
219
  return nil
220
220
  else
221
- if Codes.codes_for(clean_string.length).include? opts[:default_city]
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
@@ -5,7 +5,7 @@ module RussianPhone
5
5
  def validate(record)
6
6
  options[:fields].each do |field|
7
7
  if record.send(field).phone.blank?
8
- record.errors[field] << 'Необходимо заполнить'
8
+ record.errors.add(field, 'Необходимо заполнить')
9
9
  end
10
10
  end
11
11
  end
@@ -1,4 +1,4 @@
1
1
  module RussianPhone
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
4
4
 
@@ -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
- gem.add_development_dependency "rspec", "~> 2.14"
25
- gem.add_development_dependency 'sqlite3'
26
- gem.add_development_dependency "rspec-rails", "~> 2.14"
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', '< 11.0'
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 be_true
33
+ phone.valid?.should be true
25
34
 
26
- phone.cell?.should be_false
27
- phone.free?.should be_true
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 be_true
47
+ phone.valid?.should be true
39
48
 
40
- phone.cell?.should be_true
41
- phone.free?.should be_false
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 be_true
61
+ phone.valid?.should be true
53
62
 
54
- phone.cell?.should be_false
55
- phone.free?.should be_false
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 be_false
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 be_true
80
+ phone.valid?.should be true
72
81
 
73
- phone.cell?.should be_false
74
- phone.free?.should be_false
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 be_true
94
+ phone.valid?.should be true
86
95
 
87
- phone.cell?.should be_false
88
- phone.free?.should be_false
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 be_true
108
+ phone.valid?.should be true
100
109
 
101
- phone.cell?.should be_false
102
- phone.free?.should be_false
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 be_true
122
+ phone.valid?.should be true
114
123
 
115
- phone.cell?.should be_false
116
- phone.free?.should be_false
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 be_true
136
+ phone.valid?.should be true
128
137
 
129
- phone.cell?.should be_false
130
- phone.free?.should be_false
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 be_true
150
+ phone.valid?.should be true
142
151
 
143
- phone.cell?.should be_false
144
- phone.free?.should be_false
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 be_true
166
+ phone.valid?.should be true
158
167
 
159
- phone.cell?.should be_false
160
- phone.free?.should be_false
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 be_true
182
+ phone.valid?.should be true
174
183
 
175
- phone.cell?.should be_true
176
- phone.free?.should be_false
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 be_true
196
+ phone.valid?.should be true
188
197
 
189
- phone.cell?.should be_true
190
- phone.free?.should be_false
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 be_true
210
+ phone.valid?.should be true
202
211
 
203
- phone.cell?.should be_true
204
- phone.free?.should be_false
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 be_true
224
+ phone.valid?.should be true
216
225
 
217
- phone.cell?.should be_true
218
- phone.free?.should be_false
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 be_true
238
+ phone.valid?.should be true
230
239
 
231
- phone.cell?.should be_true
232
- phone.free?.should be_false
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 be_true
252
+ phone.valid?.should be true
244
253
 
245
- phone.cell?.should be_false
246
- phone.free?.should be_false
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 be_true
307
+ phone.valid?.should be true
299
308
 
300
309
  if %w(927 926).include? result[1].to_s
301
- phone.cell?.should be_true
310
+ phone.cell?.should be true
302
311
  else
303
- phone.cell?.should be_false
312
+ phone.cell?.should be false
304
313
  end
305
314
 
306
- phone.free?.should be_false
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 be_false
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 be_true
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 be_true
352
- u.phone.free?.should be_false
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 be_false
364
- u.save.should be_false
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 be_true
371
- u.save.should be_true
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 be_true
379
- u.save.should be_true
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 be_true
387
- u.save.should be_true
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 be_true
395
- u.save.should be_true
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 be_true
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 be_true
409
- u.phone.free?.should be_false
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: '111 11 11', phone_in_812: '222 2222')
420
- u.save.should be_true
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 be_false
427
- u.phone_in_495.free?.should be_false
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 be_false
439
- u.phone_in_812.free?.should be_false
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 be_false
452
- u.save.should be_false
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 be_true
459
- u.save.should be_true
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 be_true
467
- u.save.should be_true
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 be_true
475
- u.save.should be_true
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 be_true
483
- u.save.should be_true
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 be_true
492
- u.save.should be_true
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 be_true
500
- u.save.should be_true
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 be_true
508
- u.save.should be_true
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 be_true
516
- u.save.should be_true
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 be_true
524
- u.save.should be_true
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 be_true
532
- u.save.should be_true
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 be_false
540
- u.save.should be_false
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 be_true
548
- u.save.should be_true
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 be_true
555
- u.save.should be_true
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 be_true
562
- u.save.should be_true
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 be_true
569
- u.save.should be_true
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 be_true
576
- u.save.should be_true
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 be_false
582
- u.save.should be_false
590
+ u.valid?.should be false
591
+ u.save.should be false
583
592
 
584
593
  u = UserWithRequired.new(phone: '')
585
- u.valid?.should be_false
586
- u.save.should be_false
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 = :truncation
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
@@ -3,5 +3,10 @@ test:
3
3
  default:
4
4
  database: russian_phone
5
5
  hosts:
6
- - localhost:27017
6
+ - localhost:27018
7
+ options:
8
+ user: 'admin'
9
+ password: 'rs123456'
10
+ auth_source: admin
11
+
7
12
 
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.7.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: 2019-11-22 00:00:00.000000000 Z
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: '2.14'
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: '2.14'
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: '0'
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: '0'
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: '2.14'
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: '2.14'
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: '11.0'
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: '11.0'
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.0.6
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: