russian_phone 0.6.1 → 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: 8079e8b8283f79b72b447060cf33368019a0d0f3ce1103f793743145c958caaa
4
- data.tar.gz: 19dca849fe9d7928554589337a14122a397938a2c13549a13468757a91aae316
3
+ metadata.gz: 1e7aeaf94f764188fd507b23450b75c326c3ffc6074a56f5500701fd23256ce2
4
+ data.tar.gz: 54cd7b0a6ee69ba2a7e434b33dee4ef70ea8a98411e953957d51407e1e2ab80e
5
5
  SHA512:
6
- metadata.gz: bebce5e5d1740b7fb8e494b9266f7e5620190384490a7b3dff9db5ffdbc4d6611b9bddd2bde03eaded1e92e0894d7912cf967d495a9c7028cb110fbe5b06f833
7
- data.tar.gz: 19678d0c4b312138816cc1ab936be1e378639b44c4b14a8ee4ee2ee4b679c06d781c48f1bac36ba555596ca52c486a17146c47991db2cd7d16284ca2a80073b7
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
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # https://github.com/floere/phony/blob/master/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb
2
3
 
3
4
  module RussianPhone
4
5
  class Codes
@@ -7,20 +8,21 @@ module RussianPhone
7
8
  %w(30130 30131 30132 30133 30134 30135 30136 30137 30138 30140 30141 30142 30143 30144
8
9
  30145 30146 30147 30148 30149 30150 30153 30230 30231 30232 30233 30234 30235 30236 30237 30238 30239 30240 30241
9
10
  30242 30243 30244 30245 30246 30247 30248 30249 30251 30252 30253 30255 30256 30257 30261 30262 30264 30265 30266
11
+ 33622
10
12
  34126 34130 34132 34133 34134 34136 34138 34139 34141 34145 34147 34150 34151 34152 34153 34154 34155 34157 34158
11
- 34159 34161 34162 34163 34164 34166 34240 34241 34242 34243 34244 34245 34246 34248 34249 34250 34251 34252 34253
13
+ 34159 34161 34162 34163 34164 34166 34240 34241 34243 34244 34245 34246 34248 34249 34250 34251 34252 34253
12
14
  34254 34255 34256 34257 34258 34259 34260 34261 34262 34263 34265 34266 34268 34269 34271 34272 34273 34274 34275
13
15
  34276 34277 34278 34279 34291 34292 34293 34294 34296 34297 34298 34341 34342 34343 34344 34345 34346 34347 34349
14
16
  34350 34355 34356 34357 34358 34360 34361 34362 34363 34364 34365 34367 34368 34369 34370 34371 34372 34373 34374
15
17
  34375 34376 34377 34380 34383 34384 34385 34386 34387 34388 34389 34391 34394 34395 34397 34398 34531 34533 34535
16
18
  34537 34539 34541 34542 34543 34544 34545 34546 34547 34550 34551 34553 34554 34555 34556 34557 34561 34634 34638
17
- 34643 34667 34668 34669 34670 34672 34673 34674 34675 34676 34677 34678 34731 34739 34740 34741 34742 34743 34744
19
+ 34643 34667 34668 34669 34670 34672 34674 34675 34676 34677 34678 34731 34739 34740 34741 34742 34743 34744
18
20
  34745 34746 34747 34748 34749 34750 34751 34752 34753 34754 34755 34756 34757 34758 34759 34760 34761 34762 34763
19
21
  34764 34765 34766 34767 34768 34769 34770 34771 34772 34773 34774 34775 34776 34777 34778 34779 34780 34781 34782
20
22
  34783 34784 34785 34786 34787 34788 34789 34791 34792 34794 34795 34796 34797 34798 34922 34932 34934 34936 34938
21
23
  34940 34948 34949 34992 34993 34994 34995 34996 34997 35130 35131 35133 35134 35138 35139 35140 35141 35142 35143
22
24
  35144 35145 35146 35147 35148 35149 35150 35151 35152 35153 35154 35155 35156 35157 35158 35159 35160 35161 35163
23
- 35164 35165 35166 35167 35168 35169 35190 35191 3522 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239
25
+ 35164 35165 35166 35167 35168 35169 35190 35191 35230 35231 35232 35233 35234 35235 35236 35237 35238 35239
24
26
  35240 35241 35242 35243 35244 35245 35247 35248 35249 35251 35252 35253 35256 35257 35330 35331 35332 35333 35334
25
27
  35335 35336 35337 35338 35339 35341 35342 35344 35345 35346 35347 35348 35349 35351 35352 35354 35355 35356 35357
26
28
  35358 35359 35361 35362 35363 35364 35365 35366 35367 35368 35379 38141 38150 38151 38152 38153 38154 38155 38156
@@ -67,7 +69,9 @@ module RussianPhone
67
69
  49146 49147 49148 49151 49152 49153 49154 49155 49156 49157 49158 49231 49232 49233 49234 49235 49236 49237 49238
68
70
  49241 49242 49243 49244 49245 49246 49247 49248 49254 49331 49333 49334 49336 49337 49339 49341 49343 49344 49345
69
71
  49346 49347 49349 49351 49352 49353 49354 49355 49356 49357 49430 49431 49432 49433 49434 49435 49436 49437 49438
70
- 49439 49440 49441 49442 49443 49444 49445 49446 49447 49448 49449 49450 49451 49452 49453 81131 81132 81133 81134
72
+ 49439 49440 49441 49442 49443 49444 49445 49446 49447 49448 49449 49450 49451 49452 49453 71036 71063 71133 71237
73
+ 71336 71337 71431 71433 71435 71536 71538 71543 71630 71636 71644 71645 71651 71837 72137 72153 72251 72335 72336
74
+ 72340 72433 72533 72537 72636 72752 72771 72772 72774 72775 72834 72835 81131 81132 81133 81134
71
75
  81135 81136 81137 81138 81139 81140 81141 81142 81143 81144 81145 81146 81147 81148 81149 81150 81151 81152 81153
72
76
  81361 81362 81363 81364 81365 81366 81367 81368 81369 81370 81371 81372 81373 81374 81375 81376 81378 81379 81430
73
77
  81431 81433 81434 81436 81437 81439 81450 81451 81452 81454 81455 81456 81457 81458 81459 81530 81531 81532 81533
@@ -91,7 +95,7 @@ module RussianPhone
91
95
  84377 84378 84379 84396 84442 84443 84444 84445 84446 84447 84452 84453 84454 84455 84456 84457 84458 84461 84462
92
96
  84463 84464 84465 84466 84467 84468 84472 84473 84474 84475 84476 84477 84478 84479 84492 84493 84494 84495 84540
93
97
  84542 84543 84544 84545 84548 84549 84550 84551 84552 84554 84555 84557 84558 84560 84561 84562 84563 84564 84565
94
- 84566 84567 84568 84573 84574 84575 84576 84577 84578 84579 84591 84592 84593 84595 84596 84630 84635 84639 84646
98
+ 84566 84567 84568 84573 84574 84575 84576 84577 84578 84579 84591 84592 84593 84595 84596 84635 84639 84646
95
99
  84647 84648 84650 84651 84652 84653 84654 84655 84656 84657 84658 84660 84661 84663 84664 84666 84667 84670 84671
96
100
  84672 84673 84674 84675 84676 84677 84722 84731 84732 84733 84734 84735 84736 84741 84742 84743 84744 84745 84746
97
101
  84747 84862 85140 85141 85142 85143 85144 85145 85146 85147 85148 85149 85171 85172 85549 85551 85552 85555 85556
@@ -111,16 +115,19 @@ module RussianPhone
111
115
  end
112
116
 
113
117
  def ndcs_with_6_subscriber_digits
114
- %w(3012 3022 3412 3435 3439 3452 3456 3462 3463 3466 3473 3494 3496 3513 3519 3532 3537
115
- 3812 3822 3823 3842 3843 3846 3852 3854 3882 3902 3919 3942 3952 3953 3955 4012 4112 4132 4152 4162 4212 4217 423 4234
116
- 4236 4242 4712 4722 4725 4742 4752 4812 4822 4832 4842 4852 4855 4862 4872 4912 4922 4932 4942 8112 8142 8152 8162
117
- 8172 8202 8212 8216 8313 8332 8342 8352 8362 8412 8422 8442 8443 8452 8453 8464 8482 8512 8552 8553 8555 8557 8617
118
- 862 8634 8635 8636 8639 8652 8662 8672 8712 8722 8732 8772 8782 8793
118
+ %w(3012 3022 3412 3424 3435 3439 3452 3456 3462 3463 3466 3467 3473 3494 3496 3513 3519
119
+ 3522 3532 3537 3812 3822 3823 3842 3843 3846 3852 3854 3882 3902 3919 3942 3952 3953 3955 4012 4112 4132 4152 4162
120
+ 4212 4217 4234 4236 4242 4712 4722 4725 4742 4752 4812 4822 4832 4842 4852 4855 4862 4872 4912 4922 4932 4942
121
+ 7102 7112 7122 7132 7142 7152 7162 7172 7182 7187 7212 7213 7222 7232 7242 7252 7262 7272 7282 7292 8112 8142 8152
122
+ 8162 8172 8202 8212 8216 8313 8332 8342 8352 8362 8412 8422 8442 8443 8452 8453 8464 8482 8512 8552 8553 8555 8557
123
+ 8617 8622 8634 8635 8636 8639 8652 8662 8672 8712 8722 8732 8772 8782 8793
119
124
  )
120
125
  end
121
126
 
122
127
  def ndcs_with_7_subscriber_digits
123
- %w(342 343 347 351 383 391 473 495 496 498 499 812 818 831 843 844 846 861 862 863)
128
+ %w(342 343 347 351 365 383 391 423 473 495 496 498 499 700 701 702 727 777 778 804 812 818 831 843 844 846 861 863
129
+ 869 900 958 966 968 969 977 978 986 992 993 995 996 999
130
+ )
124
131
  end
125
132
 
126
133
  def cell_codes
@@ -134,8 +141,10 @@ module RussianPhone
134
141
  ndcs_with_6_subscriber_digits
135
142
  elsif digits == 5
136
143
  ndcs_with_5_subscriber_digits
144
+ else
145
+ []
137
146
  end
138
147
  end
139
148
  end
140
149
  end
141
- end
150
+ 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.6.1"
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.6.1
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: 2018-06-05 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,9 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
231
  - !ruby/object:Gem::Version
218
232
  version: '0'
219
233
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.7.7
222
- signing_key:
234
+ rubygems_version: 3.5.9
235
+ signing_key:
223
236
  specification_version: 4
224
237
  summary: Поле для хранения Российских телефонных номеров в Mongoid
225
238
  test_files: