phony_rails 0.14.13 → 0.15.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: c65b83fb1c77dccdf0b125fa2195b997067bc06efa4fff2284ab3542e643a7b3
4
- data.tar.gz: '09e7d37472c4c0ccfa050f381506c11f2ec5b939c75199c26e2529b531ccfa90'
3
+ metadata.gz: 9f5029f29270fa190a8d6bb493268065d2abed1652c3bb63622340309018cced
4
+ data.tar.gz: f6f307074a3348693e6ef4bce515b81b3890ff396a35dd4ed343bcefa3476a8a
5
5
  SHA512:
6
- metadata.gz: 5b35b337390b7c90d8c1a0d9ef972205089f56a04e1d4e51c59ded39acc7bfee6568fbf7d06e7a603d9091e58bfe0ef8f12f974b2170d55b704bc9d375a23846
7
- data.tar.gz: a2cb0e49ce1039adb889b4e080cb5418a0c3ea88bd129edc991028e5aa0b5c6620c7fa4ab0a82316655b00d31d06eda7e9a5eb1cd824e0dc422f0e95506ae272
6
+ metadata.gz: 9153aa4dfd473744cd30b227d1429b0766fd27a0b58c8003aba6677e851390adc0f1b8c237d8b77e0f386c5e3c5f05958aff5a1f1f842a495b68caba5511ffe5
7
+ data.tar.gz: 8cc31c41aceec40c3d0ea203a1e8cec344bc9e0e5fbc407bd78456e9a4fe16b020c5b8b4895eedc3a9e19247dd8f55e41e8349283512871a0282289ea825216a
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+ require: rubocop-performance
2
3
  AllCops:
3
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.4
4
5
  Metrics/BlockLength:
5
6
  ExcludedMethods: ['describe', 'context', 'define', 'shared_examples_for']
data/.rubocop_todo.yml CHANGED
@@ -13,6 +13,13 @@ Lint/AssignmentInCondition:
13
13
  - 'lib/phony_rails.rb'
14
14
 
15
15
  # Offense count: 2
16
+ # Cop supports --auto-correct.
17
+ Lint/SendWithMixinArgument:
18
+ Exclude:
19
+ - 'lib/phony_rails.rb'
20
+
21
+ # Offense count: 2
22
+ # Configuration parameters: AllowKeywordBlockArguments.
16
23
  Lint/UnderscorePrefixedVariableName:
17
24
  Exclude:
18
25
  - 'lib/phony_rails.rb'
@@ -46,6 +53,12 @@ Performance/StartWith:
46
53
  Exclude:
47
54
  - 'lib/phony_rails.rb'
48
55
 
56
+ # Offense count: 1
57
+ # Cop supports --auto-correct.
58
+ Performance/RegexpMatch:
59
+ Exclude:
60
+ - 'lib/phony_rails.rb'
61
+
49
62
  # Offense count: 1
50
63
  # Configuration parameters: EnforcedStyle, SupportedStyles.
51
64
  # SupportedStyles: nested, compact
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.7
4
3
  - 2.4.4
5
4
  - 2.5.5
6
5
  - 2.6.2
6
+ - 3.0.0
7
7
  script:
8
8
  - bundle exec rspec spec
9
9
  - bundle exec rubocop
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.14.13](https://github.com/joost/phony_rails/tree/v0.14.13) (2019-07-03)
4
+ [Full Changelog](https://github.com/joost/phony_rails/compare/v0.14.12...v0.14.13)
5
+
6
+ **Closed issues:**
7
+
8
+ - 0.4.11 was the latest release. However the new normalize\_when\_valid has been sitting here for a while... Release? [\#194](https://github.com/joost/phony_rails/issues/194)
9
+
10
+ **Merged pull requests:**
11
+
12
+ - Fixing \#195 - Original value should be cached in correct instance var [\#196](https://github.com/joost/phony_rails/pull/196) ([dlikhten](https://github.com/dlikhten))
13
+
3
14
  ## [v0.14.12](https://github.com/joost/phony_rails/tree/v0.14.12) (2019-06-21)
4
15
  [Full Changelog](https://github.com/joost/phony_rails/compare/v0.14.11...v0.14.12)
5
16
 
data/Gemfile CHANGED
@@ -11,3 +11,4 @@ gem 'guard-rspec' # , '~> 4.2.0'
11
11
  gem 'rake'
12
12
  gem 'rspec' # , '~> 2.14.0'
13
13
  gem 'rubocop'
14
+ gem 'rubocop-performance'
data/README.md CHANGED
@@ -7,10 +7,10 @@ Find version information in the [CHANGELOG](CHANGELOG.md).
7
7
 
8
8
  ## Installation
9
9
 
10
- Add this line to your application's Gemfile:
10
+ Add this line to your application's Gemfile (requires Ruby > 2.3):
11
11
 
12
12
  ```ruby
13
- gem 'phony_rails' # Include phony_rails after mongoid (if you use mongoid, see issue #66 on github).
13
+ gem 'phony_rails'
14
14
  ```
15
15
 
16
16
  And then execute:
@@ -66,18 +66,10 @@ class SomeModel
66
66
  end
67
67
  ```
68
68
 
69
- #### Mongoid
69
+ #### Mongoid (DEPRECATED)
70
70
 
71
- For **Mongoid**, in keeping with Mongoid plug-in conventions you must include the `Mongoid::Phony` module:
71
+ WARNING: From v0.15.0 Mongoid support has been removed!
72
72
 
73
- ```ruby
74
- class SomeModel
75
- include Mongoid::Document
76
- include Mongoid::Phony
77
-
78
- # methods are same as ActiveRecord usage
79
- end
80
- ```
81
73
  #### General info
82
74
 
83
75
  The `:default_country_code` options is used to specify a country_code when normalizing.
@@ -114,6 +106,7 @@ In your model use the Phony.plausible method to validate an attribute:
114
106
  ```ruby
115
107
  validates :phone_number, phony_plausible: true
116
108
  ```
109
+
117
110
  or the helper method:
118
111
 
119
112
  ```ruby
@@ -121,8 +114,9 @@ validates_plausible_phone :phone_number
121
114
  ```
122
115
 
123
116
  this method use other validators under the hood to provide:
124
- * presence validation using `ActiveModel::Validations::PresenceValidator`
125
- * format validation using `ActiveModel::Validations::FormatValidator`
117
+
118
+ - presence validation using `ActiveModel::Validations::PresenceValidator`
119
+ - format validation using `ActiveModel::Validations::FormatValidator`
126
120
 
127
121
  so we can use:
128
122
 
@@ -174,11 +168,11 @@ When number is valid, it will save the normalized number (e.g. `+48 888 888 888`
174
168
 
175
169
  #### Allowing records country codes to not match phone number country codes
176
170
 
177
- You may have a record specifying one country (via a `country_code` attribute) but using a phone number from another country. For example, your record may be from Japan but have a phone number from the Philippines. By default, `phony_rails` will consider your record's `country_code` as part of the validation. If that country doesn't match the country code in the phone number, validation will fail.
171
+ You may have a record specifying one country (via a `country_code` attribute) but using a phone number from another country. For example, your record may be from Japan but have a phone number from the Philippines. By default, `phony_rails` will consider your record's `country_code` as part of the validation. If that country doesn't match the country code in the phone number, validation will fail.
178
172
 
179
173
  Additionally, `phony_normalize` will always add the records country code as the country number (eg. the user enters '+81xxx' for Japan and the records `country_code` is 'DE' then `phony_normalize` will change the number to '+4981'). You can turn this off by adding `enforce_record_country: false` to the validation options. The country_code will then only be added if no country code is specified.
180
174
 
181
- If you want to allow records from one country to have phone numbers from a different one, there are a couple of options you can use: `ignore_record_country_number` and `ignore_record_country_code`. Use them like so:
175
+ If you want to allow records from one country to have phone numbers from a different one, there are a couple of options you can use: `ignore_record_country_number` and `ignore_record_country_code`. Use them like so:
182
176
 
183
177
  ```ruby
184
178
  validates :phone_number, phony_plausible: { ignore_record_country_code: true, ignore_record_country_number: true }
@@ -232,7 +226,6 @@ Extensions are supported (identified by "ext", "ex", "x", "xt", "#", or ":") and
232
226
  "+31 (0)30 1234 123 #999".phony_normalized # => '31301234123 x999'
233
227
  ```
234
228
 
235
-
236
229
  ### Find by normalized number
237
230
 
238
231
  Say you want to find a record by a phone number. Best is to normalize user input and compare to an attribute stored in the db.
data/lib/phony_rails.rb CHANGED
@@ -50,7 +50,7 @@ module PhonyRails
50
50
  original_number = number
51
51
  number = number.dup # Just to be sure, we don't want to change the original.
52
52
  number, ext = extract_extension(number)
53
- number.gsub!(/[^\(\)\d\+]/, '') # Strips weird stuff from the number
53
+ number.gsub!(/[^()\d+]/, '') # Strips weird stuff from the number
54
54
  return if number.blank?
55
55
 
56
56
  if _country_number = options[:country_number] || country_number_for(options[:country_code])
@@ -67,8 +67,7 @@ module PhonyRails
67
67
  normalized_number = options[:add_plus] ? "+#{normalized_number}" : normalized_number
68
68
 
69
69
  options[:extension] = true if options[:extension].nil?
70
- normalized_number = options[:extension] ? format_extension(normalized_number, ext) : normalized_number
71
- normalized_number
70
+ options[:extension] ? format_extension(normalized_number, ext) : normalized_number
72
71
  rescue StandardError
73
72
  original_number # If all goes wrong .. we still return the original input.
74
73
  end
@@ -129,7 +128,7 @@ module PhonyRails
129
128
  false
130
129
  end
131
130
 
132
- COMMON_EXTENSIONS = /[ ]*(ext|ex|x|xt|#|:)+[^0-9]*\(?([-0-9]{1,})\)?#?$/i.freeze
131
+ COMMON_EXTENSIONS = / *(ext|ex|x|xt|#|:)+[^0-9]*\(?([-0-9]{1,})\)?#?$/i.freeze
133
132
 
134
133
  def self.extract_extension(number_and_ext)
135
134
  return [nil, nil] if number_and_ext.nil?
@@ -203,9 +202,7 @@ module PhonyRails
203
202
  def phony_normalize(*attributes)
204
203
  options = attributes.last.is_a?(Hash) ? attributes.pop : {}
205
204
  options.assert_valid_keys(*PHONY_RAILS_COLLECTION_VALID_KEYS)
206
- if options[:as].present?
207
- raise ArgumentError, ':as option can not be used on phony_normalize with multiple attribute names! (PhonyRails)' if attributes.size > 1
208
- end
205
+ raise ArgumentError, ':as option can not be used on phony_normalize with multiple attribute names! (PhonyRails)' if options[:as].present? && (attributes.size > 1)
209
206
 
210
207
  options[:enforce_record_country] = true if options[:enforce_record_country].nil?
211
208
 
@@ -278,12 +275,12 @@ end
278
275
 
279
276
  ActiveModel::Model.send :include, PhonyRails::Extension if defined?(ActiveModel::Model)
280
277
 
281
- if defined?(Mongoid)
282
- module Mongoid::Phony
283
- extend ActiveSupport::Concern
284
- include PhonyRails::Extension
285
- end
286
- end
278
+ # if defined?(Mongoid)
279
+ # module Mongoid::Phony
280
+ # extend ActiveSupport::Concern
281
+ # include PhonyRails::Extension
282
+ # end
283
+ # end
287
284
 
288
285
  Dir["#{File.dirname(__FILE__)}/phony_rails/locales/*.yml"].each do |file|
289
286
  I18n.load_path << file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhonyRails
4
- VERSION = '0.14.13'
4
+ VERSION = '0.15.0'
5
5
  end
data/phony_rails.gemspec CHANGED
@@ -16,14 +16,14 @@ Gem::Specification.new do |gem|
16
16
  gem.name = 'phony_rails'
17
17
  gem.require_paths = ['lib']
18
18
  gem.version = PhonyRails::VERSION
19
+ gem.required_ruby_version = '>= 2.4'
19
20
 
20
21
  gem.post_install_message = "PhonyRails v0.10.0 changes the way numbers are stored!\nIt now adds a ' + ' to the normalized number when it starts with a country number!"
21
22
 
22
23
  gem.add_runtime_dependency 'activesupport', '>= 3.0'
23
- gem.add_runtime_dependency 'phony', '> 2.15'
24
+ gem.add_runtime_dependency 'phony', '>= 2.18.12'
24
25
  gem.add_development_dependency 'activerecord', '>= 3.0'
25
- gem.add_development_dependency 'mongoid', '>= 3.0'
26
26
 
27
27
  # For testing
28
- gem.add_development_dependency 'sqlite3', '~> 1.3.6'
28
+ gem.add_development_dependency 'sqlite3', '>= 1.4.0'
29
29
  end
@@ -2,9 +2,8 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
+ EXT_PREFIXES = %w[ext ex x xt # :].freeze
5
6
  describe PhonyRails do
6
- EXT_PREFIXES = %w[ext ex x xt # :].freeze
7
-
8
7
  it 'should not pollute the global namespace with a Country class' do
9
8
  should_not be_const_defined 'Country'
10
9
  end
@@ -200,17 +199,20 @@ describe PhonyRails do
200
199
  end
201
200
  end
202
201
 
202
+ # rubocop:disable Lint/ConstantDefinitionInBlock
203
203
  class NormalHome < ActiveRecord::Base
204
204
  attr_accessor :phone_number
205
+
205
206
  phony_normalize :phone_number, default_country_code: 'US'
206
207
  validates :phone_number, phony_plausible: true
207
208
  end
209
+ # rubocop:enable Lint/ConstantDefinitionInBlock
208
210
 
209
211
  normal = NormalHome.new
210
212
  normal.phone_number = 'HAHA'
211
213
  expect(normal).to_not be_valid
212
214
  expect(normal.phone_number).to eq('HAHA')
213
- expect(normal.errors.messages).to include(phone_number: ['is an invalid number'])
215
+ expect(normal.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
214
216
  end
215
217
 
216
218
  it 'should pass Github issue #170' do
@@ -510,7 +512,7 @@ describe PhonyRails do
510
512
  after { PhonyRails.default_country_code = nil }
511
513
 
512
514
  it 'can set a global default country code' do
513
- expect(PhonyRails.default_country_code). to eq 'US'
515
+ expect(PhonyRails.default_country_code).to eq 'US'
514
516
  end
515
517
 
516
518
  it 'can set a global default country code' do
@@ -923,9 +925,9 @@ describe PhonyRails do
923
925
  end
924
926
  end
925
927
 
926
- describe 'Mongoid' do
927
- let(:model_klass) { MongoidModel }
928
- let(:dummy_klass) { MongoidDummy }
929
- it_behaves_like 'model with PhonyRails'
930
- end
928
+ # describe 'Mongoid' do
929
+ # let(:model_klass) { MongoidModel }
930
+ # let(:dummy_klass) { MongoidDummy }
931
+ # it_behaves_like 'model with PhonyRails'
932
+ # end
931
933
  end
@@ -69,66 +69,77 @@ end
69
69
  #--------------------
70
70
  class SimpleHome < ActiveRecord::Base
71
71
  attr_accessor :phone_number
72
+
72
73
  validates :phone_number, phony_plausible: true
73
74
  end
74
75
 
75
76
  #--------------------
76
77
  class HelpfulHome < ActiveRecord::Base
77
78
  attr_accessor :phone_number
79
+
78
80
  validates_plausible_phone :phone_number
79
81
  end
80
82
 
81
83
  #--------------------
82
84
  class RequiredHelpfulHome < ActiveRecord::Base
83
85
  attr_accessor :phone_number
86
+
84
87
  validates_plausible_phone :phone_number, presence: true
85
88
  end
86
89
 
87
90
  #--------------------
88
91
  class OptionalHelpfulHome < ActiveRecord::Base
89
92
  attr_accessor :phone_number
93
+
90
94
  validates_plausible_phone :phone_number, presence: false
91
95
  end
92
96
 
93
97
  #--------------------
94
98
  class FormattedHelpfulHome < ActiveRecord::Base
95
99
  attr_accessor :phone_number
100
+
96
101
  validates_plausible_phone :phone_number, with: /\A\+\d+/
97
102
  end
98
103
 
99
104
  #--------------------
100
105
  class NotFormattedHelpfulHome < ActiveRecord::Base
101
106
  attr_accessor :phone_number
107
+
102
108
  validates_plausible_phone :phone_number, without: /\A\+\d+/
103
109
  end
104
110
 
105
111
  #--------------------
106
112
  class NormalizableHelpfulHome < ActiveRecord::Base
107
113
  attr_accessor :phone_number
114
+
108
115
  validates_plausible_phone :phone_number, normalized_country_code: 'US'
109
116
  end
110
117
 
111
118
  #--------------------
112
119
  class AustralianHelpfulHome < ActiveRecord::Base
113
120
  attr_accessor :phone_number
121
+
114
122
  validates_plausible_phone :phone_number, country_number: '61'
115
123
  end
116
124
 
117
125
  #--------------------
118
126
  class PolishHelpfulHome < ActiveRecord::Base
119
127
  attr_accessor :phone_number
128
+
120
129
  validates_plausible_phone :phone_number, country_code: 'PL'
121
130
  end
122
131
 
123
132
  #--------------------
124
133
  class BigHelpfulHome < ActiveRecord::Base
125
134
  attr_accessor :phone_number
135
+
126
136
  validates_plausible_phone :phone_number, presence: true, with: /\A\+\d+/, country_number: '33'
127
137
  end
128
138
 
129
139
  #--------------------
130
140
  class MismatchedHelpfulHome < ActiveRecord::Base
131
141
  attr_accessor :phone_number, :country_code
142
+
132
143
  validates :phone_number, phony_plausible: { ignore_record_country_code: true }
133
144
  end
134
145
 
@@ -136,6 +147,7 @@ end
136
147
 
137
148
  class InvalidCountryCodeHelpfulHome < ActiveRecord::Base
138
149
  attr_accessor :phone_number
150
+
139
151
  validates_plausible_phone :phone_number
140
152
 
141
153
  def country_code
@@ -146,33 +158,39 @@ end
146
158
  #--------------------
147
159
  class SymbolizableHelpfulHome < ActiveRecord::Base
148
160
  attr_accessor :phone_number, :phone_number_country_code
161
+
149
162
  validates_plausible_phone :phone_number, country_code: :phone_number_country_code
150
163
  end
151
164
 
152
165
  #--------------------
153
166
  class NoModelMethod < HelpfulHome
154
167
  attr_accessor :phone_number
168
+
155
169
  validates_plausible_phone :phone_number, country_code: :nonexistent_method
156
170
  end
157
171
 
158
172
  #--------------------
159
173
  class MessageOptionUndefinedInModel < HelpfulHome
160
174
  attr_accessor :phone_number
175
+
161
176
  validates_plausible_phone :phone_number, message: :email
162
177
  end
163
178
 
164
179
  #--------------------
165
180
  class MessageOptionSameAsModelMethod < HelpfulHome
166
181
  attr_accessor :phone_number
182
+
167
183
  validates_plausible_phone :phone_number, message: :email
168
184
 
169
185
  def email
170
186
  'user@example.com'
171
187
  end
172
188
  end
189
+
173
190
  #--------------------
174
191
  class NormalizabledPhoneHome < ActiveRecord::Base
175
192
  attr_accessor :phone_number, :phone_number2, :country_code
193
+
176
194
  validates_plausible_phone :phone_number
177
195
  validates_plausible_phone :phone_number2
178
196
  phony_normalize :phone_number, country_code: 'PL', normalize_when_valid: true
@@ -223,26 +241,26 @@ describe PhonyPlausibleValidator do
223
241
  it 'should invalidate an invalid number' do
224
242
  @home.phone_number = INVALID_NUMBER
225
243
  expect(@home).to_not be_valid
226
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
244
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
227
245
  end
228
246
 
229
247
  it 'should invalidate an valid number with invalid extension' do
230
248
  @home.phone_number = VALID_NUMBER_WITH_INVALID_EXTENSION
231
249
  expect(@home).to_not be_valid
232
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
250
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
233
251
  end
234
252
 
235
253
  it 'should invalidate not a number' do
236
254
  @home.phone_number = NOT_A_NUMBER
237
255
  expect(@home).to_not be_valid
238
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
256
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
239
257
  end
240
258
 
241
259
  it 'should translate the error message in Dutch' do
242
260
  I18n.with_locale(:nl) do
243
261
  @home.phone_number = INVALID_NUMBER
244
262
  @home.valid?
245
- expect(@home.errors.messages).to include(phone_number: ['is geen geldig nummer'])
263
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is geen geldig nummer'])
246
264
  end
247
265
  end
248
266
 
@@ -250,7 +268,7 @@ describe PhonyPlausibleValidator do
250
268
  I18n.with_locale(:en) do
251
269
  @home.phone_number = INVALID_NUMBER
252
270
  @home.valid?
253
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
271
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
254
272
  end
255
273
  end
256
274
 
@@ -258,7 +276,7 @@ describe PhonyPlausibleValidator do
258
276
  I18n.with_locale(:es) do
259
277
  @home.phone_number = INVALID_NUMBER
260
278
  @home.valid?
261
- expect(@home.errors.messages).to include(phone_number: ['es un número inválido'])
279
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['es un número inválido'])
262
280
  end
263
281
  end
264
282
 
@@ -266,7 +284,7 @@ describe PhonyPlausibleValidator do
266
284
  I18n.with_locale(:fr) do
267
285
  @home.phone_number = INVALID_NUMBER
268
286
  @home.valid?
269
- expect(@home.errors.messages).to include(phone_number: ['est un numéro invalide'])
287
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['est un numéro invalide'])
270
288
  end
271
289
  end
272
290
 
@@ -274,7 +292,7 @@ describe PhonyPlausibleValidator do
274
292
  I18n.with_locale(:ja) do
275
293
  @home.phone_number = INVALID_NUMBER
276
294
  @home.valid?
277
- expect(@home.errors.messages).to include(phone_number: ['は正しい電話番号ではありません'])
295
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['は正しい電話番号ではありません'])
278
296
  end
279
297
  end
280
298
 
@@ -282,7 +300,7 @@ describe PhonyPlausibleValidator do
282
300
  I18n.with_locale(:km) do
283
301
  @home.phone_number = INVALID_NUMBER
284
302
  @home.valid?
285
- expect(@home.errors.messages).to include(phone_number: ['គឺជាលេខមិនត្រឹមត្រូវ'])
303
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['គឺជាលេខមិនត្រឹមត្រូវ'])
286
304
  end
287
305
  end
288
306
 
@@ -290,7 +308,7 @@ describe PhonyPlausibleValidator do
290
308
  I18n.with_locale(:ko) do
291
309
  @home.phone_number = INVALID_NUMBER
292
310
  @home.valid?
293
- expect(@home.errors.messages).to include(phone_number: ['는 올바른 전화번호가 아닙니다'])
311
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['는 올바른 전화번호가 아닙니다'])
294
312
  end
295
313
  end
296
314
 
@@ -298,7 +316,7 @@ describe PhonyPlausibleValidator do
298
316
  I18n.with_locale(:uk) do
299
317
  @home.phone_number = INVALID_NUMBER
300
318
  @home.valid?
301
- expect(@home.errors.messages).to include(phone_number: ['є недійсним номером'])
319
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['є недійсним номером'])
302
320
  end
303
321
  end
304
322
 
@@ -306,7 +324,7 @@ describe PhonyPlausibleValidator do
306
324
  I18n.with_locale(:ru) do
307
325
  @home.phone_number = INVALID_NUMBER
308
326
  @home.valid?
309
- expect(@home.errors.messages).to include(phone_number: ['является недействительным номером'])
327
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['является недействительным номером'])
310
328
  end
311
329
  end
312
330
  end
@@ -334,7 +352,7 @@ describe ActiveModel::Validations::HelperMethods do
334
352
  it 'should invalidate an invalid number' do
335
353
  @home.phone_number = INVALID_NUMBER
336
354
  expect(@home).to_not be_valid
337
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
355
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
338
356
  end
339
357
  end
340
358
 
@@ -346,7 +364,7 @@ describe ActiveModel::Validations::HelperMethods do
346
364
 
347
365
  it 'should invalidate an empty number' do
348
366
  expect(@home).to_not be_valid
349
- expect(@home.errors.messages).to include(phone_number: ["can't be blank"])
367
+ expect(@home.errors.messages.to_hash).to include(phone_number: ["can't be blank"])
350
368
  end
351
369
 
352
370
  it 'should validate a valid number' do
@@ -357,7 +375,7 @@ describe ActiveModel::Validations::HelperMethods do
357
375
  it 'should invalidate an invalid number' do
358
376
  @home.phone_number = INVALID_NUMBER
359
377
  expect(@home).to_not be_valid
360
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
378
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
361
379
  end
362
380
  end
363
381
 
@@ -385,7 +403,7 @@ describe ActiveModel::Validations::HelperMethods do
385
403
  it 'should invalidate an invalid number' do
386
404
  @home.phone_number = INVALID_NUMBER
387
405
  expect(@home).to_not be_valid
388
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
406
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
389
407
  end
390
408
  end
391
409
 
@@ -397,7 +415,7 @@ describe ActiveModel::Validations::HelperMethods do
397
415
 
398
416
  it 'should invalidate an empty number' do
399
417
  expect(@home).to_not be_valid
400
- expect(@home.errors.messages).to include(phone_number: ['is invalid'])
418
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is invalid'])
401
419
  end
402
420
 
403
421
  it 'should validate a well formatted valid number' do
@@ -408,7 +426,7 @@ describe ActiveModel::Validations::HelperMethods do
408
426
  it 'should invalidate a bad formatted valid number' do
409
427
  @home.phone_number = VALID_NUMBER
410
428
  expect(@home).to_not be_valid
411
- expect(@home.errors.messages).to include(phone_number: ['is invalid'])
429
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is invalid'])
412
430
  end
413
431
  end
414
432
 
@@ -430,7 +448,7 @@ describe ActiveModel::Validations::HelperMethods do
430
448
  it 'should invalidate a bad formatted valid number' do
431
449
  @home.phone_number = "+#{VALID_NUMBER}"
432
450
  expect(@home).to_not be_valid
433
- expect(@home.errors.messages).to include(phone_number: ['is invalid'])
451
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is invalid'])
434
452
  end
435
453
  end
436
454
 
@@ -452,13 +470,13 @@ describe ActiveModel::Validations::HelperMethods do
452
470
  it 'should invalidate a valid number with the wrong country code' do
453
471
  @home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
454
472
  expect(@home).to_not be_valid
455
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
473
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
456
474
  end
457
475
 
458
476
  it 'should invalidate a valid number without a country code' do
459
477
  @home.phone_number = VALID_NUMBER
460
478
  expect(@home).to_not be_valid
461
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
479
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
462
480
  end
463
481
  end
464
482
 
@@ -485,7 +503,7 @@ describe ActiveModel::Validations::HelperMethods do
485
503
  it 'should invalidate an invalid number' do
486
504
  @home.phone_number = INVALID_NUMBER
487
505
  expect(@home).to_not be_valid
488
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
506
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
489
507
  end
490
508
  end
491
509
 
@@ -507,13 +525,13 @@ describe ActiveModel::Validations::HelperMethods do
507
525
  it 'should invalidate a valid number with the wrong country code' do
508
526
  @home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
509
527
  expect(@home).to_not be_valid
510
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
528
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
511
529
  end
512
530
 
513
531
  it 'should invalidate a valid number without a country code' do
514
532
  @home.phone_number = VALID_NUMBER
515
533
  expect(@home).to_not be_valid
516
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
534
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
517
535
  end
518
536
  end
519
537
 
@@ -606,14 +624,14 @@ describe ActiveModel::Validations::HelperMethods do
606
624
  @home.phone_number = FRENCH_NUMBER_WITH_COUNTRY_CODE
607
625
  @home.phone_number_country_code = 'PL'
608
626
  expect(@home).to_not be_valid
609
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
627
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
610
628
  end
611
629
 
612
630
  it 'should invalidate a valid number without a country code' do
613
631
  @home.phone_number = VALID_NUMBER
614
632
  @home.phone_number_country_code = 'PL'
615
633
  expect(@home).to_not be_valid
616
- expect(@home.errors.messages).to include(phone_number: ['is an invalid number'])
634
+ expect(@home.errors.messages.to_hash).to include(phone_number: ['is an invalid number'])
617
635
  end
618
636
 
619
637
  it 'should pass Gitlab issue #165' do
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,7 @@ require 'rubygems'
9
9
  require 'bundler/setup'
10
10
 
11
11
  require 'active_record'
12
- require 'mongoid'
12
+ # require 'mongoid'
13
13
  require 'phony_rails'
14
14
 
15
15
  ActiveRecord::Base.establish_connection(
@@ -35,6 +35,7 @@ module SharedModelMethods
35
35
  :country_code, :country_code_attribute, :custom_country_code, :delivery_method,
36
36
  :home_country, :phone_method, :phone1_method, :recipient, :symboled_phone_method
37
37
  )
38
+
38
39
  phony_normalized_method :phone_attribute # adds normalized_phone_attribute method
39
40
  phony_normalized_method :phone_method # adds normalized_phone_method method
40
41
  phony_normalized_method :phone1_method, default_country_code: 'DE' # adds normalized_phone_method method
@@ -80,20 +81,20 @@ end
80
81
  class ActiveModelDummy < ActiveModelModel
81
82
  end
82
83
 
83
- class MongoidModel
84
- include Mongoid::Document
85
- include Mongoid::Phony
86
- field :phone_attribute, type: String
87
- field :phone_number, type: String
88
- field :phone_number_as_normalized, type: String
89
- field :fax_number
90
- field :country_code_attribute, type: String
91
- field :symboled_phone, type: String
92
- include SharedModelMethods
93
- end
84
+ # class MongoidModel
85
+ # include Mongoid::Document
86
+ # include Mongoid::Phony
87
+ # field :phone_attribute, type: String
88
+ # field :phone_number, type: String
89
+ # field :phone_number_as_normalized, type: String
90
+ # field :fax_number
91
+ # field :country_code_attribute, type: String
92
+ # field :symboled_phone, type: String
93
+ # include SharedModelMethods
94
+ # end
94
95
 
95
- class MongoidDummy < MongoidModel
96
- end
96
+ # class MongoidDummy < MongoidModel
97
+ # end
97
98
 
98
99
  I18n.config.enforce_available_locales = true
99
100
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.13
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joost Hietbrink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-03 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: phony
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.15'
33
+ version: 2.18.12
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.15'
40
+ version: 2.18.12
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,33 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mongoid
56
+ name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: 1.4.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: sqlite3
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 1.3.6
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 1.3.6
68
+ version: 1.4.0
83
69
  description: This Gem adds useful methods to your Rails app to validate, display and
84
70
  save phone numbers.
85
71
  email:
@@ -135,15 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - ">="
137
123
  - !ruby/object:Gem::Version
138
- version: '0'
124
+ version: '2.4'
139
125
  required_rubygems_version: !ruby/object:Gem::Requirement
140
126
  requirements:
141
127
  - - ">="
142
128
  - !ruby/object:Gem::Version
143
129
  version: '0'
144
130
  requirements: []
145
- rubyforge_project:
146
- rubygems_version: 2.7.7
131
+ rubygems_version: 3.0.3
147
132
  signing_key:
148
133
  specification_version: 4
149
134
  summary: This Gem adds useful methods to your Rails app to validate, display and save