validates_zipcode 0.5.1 → 0.5.3

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: df2a33cb45dafbda679e54e3030fc68c6ed9bd333f1b6333c62fd7f55d19e34a
4
- data.tar.gz: 650da19b279aa781e6cfeb3452b9cef2f534bf8eb07a24b9d3335e803ed0c4e0
3
+ metadata.gz: eaccf2cf4e72190040829da37f3da72cd319020b9e97c1dd3a064cb1b4d6b381
4
+ data.tar.gz: dac1daf1928badb6279f0007ae20ab969e854adacbd8e0a25d7e4ded91483125
5
5
  SHA512:
6
- metadata.gz: 96c289be91ec67e3bc2ae13627088b35720f61257449fd372b4dbf96decf90a95a5d24b0dff58d599632aee4f2af803f470a9352b94b2c0a0a815daec6b1197c
7
- data.tar.gz: 4ec5b753940e0f7593249ad0090836ee778b170c5da70632069d1eceb14ec523236ced64ec221b13aaad0350e0537a82aa0c602436e9cf4706019b582670e050
6
+ metadata.gz: 52810b93259d83ba29088bc3b3eb0596bb89f15d8d92f7b8947bf08333f7191fa7e37946dbed18d4045bb4d4fd0d574f73e1c94846bc2c95f39295a42e996616
7
+ data.tar.gz: 3129ba6f20cbe9850aa9448b98271bee9e0d60496fbd47ed9f4df55db896377aa20998832864d37388bc0c4d8c18b2ee19955ff4d4e0de89d4628061842c5861
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## Unreleased
6
+
7
+ ## 0.5.3
8
+
9
+ - See commits up to 4e5a3132061d57d220d1616beb15d15a47d301df
10
+
11
+ ## 0.5.2
12
+
13
+ - Added support for Puerto Rico, thanks to ~ @tahanson
14
+ - Added support for newer Honduras codes with backwards compatibility ~ @tahanson
15
+
5
16
  ## 0.5.1
6
17
 
7
18
  - Fixes Mongolia postal codes, thanks to ~ @lucasfcunha
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.5.1)
4
+ validates_zipcode (0.5.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.5.1)
4
+ validates_zipcode (0.5.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.5.1)
4
+ validates_zipcode (0.5.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- validates_zipcode (0.5.1)
4
+ validates_zipcode (0.5.2)
5
5
  activemodel (>= 4.2.0)
6
6
 
7
7
  GEM
@@ -14,7 +14,7 @@ GIT
14
14
  PATH
15
15
  remote: ..
16
16
  specs:
17
- validates_zipcode (0.5.1)
17
+ validates_zipcode (0.5.2)
18
18
  activemodel (>= 4.2.0)
19
19
 
20
20
  GEM
@@ -32,7 +32,7 @@ module ValidatesZipcode
32
32
  SG: /\A\d{6}\z/,
33
33
  DZ: /\A\d{5}\z/,
34
34
  AD: /\AAD\d{3}\z/,
35
- AR: /\A[A-HJ-NP-Z]{1}\d{4}([A-Z]{3})?\z/,
35
+ AR: /\A([A-HJ-NP-Z]{1}\d{4}([A-Z]{3})?|\d{4})\z/,
36
36
  AM: /\A(37)?\d{4}\z/,
37
37
  BH: /\A(1[0-2]|[1-9])\d{2}\z/,
38
38
  BD: /\A\d{4}\z/,
@@ -42,7 +42,7 @@ module ValidatesZipcode
42
42
  BA: /\A\d{5}\z/,
43
43
  BN: /\A[BKTP][A-Z][ ]?\d{4}\z/i,
44
44
  BG: /\A\d{4}\z/,
45
- KH: /\A\d{5}\z/,
45
+ KH: /\A\d{6}\z/,
46
46
  CV: /\A\d{4}\z/,
47
47
  CL: /\A\d{3}[-]?\d{4}\z/,
48
48
  HR: /\A\d{5}\z/,
@@ -158,7 +158,8 @@ module ValidatesZipcode
158
158
  BJ: /\A([A-Z\d\s]){3,}\z/i,
159
159
  BT: /\A\d{5}\z/,
160
160
  BQ: /\A([A-Z\d\s]){3,}\z/i,
161
- BO: /\A\d{4}\z/,
161
+ # NOTE: Bolivia has no postal codes
162
+ # BO: /\A\d{4}\z/,
162
163
  BW: /\A([A-Z\d\s]){3,}\z/i,
163
164
  CF: /\A([A-Z\d\s]){3,}\z/i,
164
165
  CG: /\A([A-Z\d\s]){3,}\z/i,
@@ -185,7 +186,7 @@ module ValidatesZipcode
185
186
  GI: /\A(GX11[ ]?1AA)\z/i,
186
187
  GR: /\A\d{3}[ ]?\d{2}\z/,
187
188
  GY: /\A([A-Z\d\s]){3,}\z/i,
188
- HN: /\A(([A-Z]){2}|\d{2})\d{4}\z/i,
189
+ HN: /\A([A-Z]{2}|\d{1})\d{4}\z/i,
189
190
  IO: /\A\d{5}\z/,
190
191
  IR: /\A\d{5}\z/,
191
192
  JP: /\A\d{3}\-?\d{4}\z/,
@@ -210,7 +211,7 @@ module ValidatesZipcode
210
211
  MW: /\A([A-Z\d\s]){3,}\z/i,
211
212
  MZ: /\A\d{4}\z/,
212
213
  NA: /\A\d{5}\z/,
213
- NP: /\A\d{6}\z/,
214
+ NP: /\A\d{5}\z/,
214
215
  NR: /\A([A-Z\d\s]){3,}\z/i,
215
216
  PT: /\A\d{4}([\-]\d{3})?\z/,
216
217
  PS: /\A\d{3}\z/,
@@ -19,7 +19,7 @@ module ValidatesZipcode
19
19
  PL: ->(z) { z.scan(/\d/).insert(2, '-').join },
20
20
  SK: :CZ,
21
21
  UK: :GB,
22
- MT: :GB,
22
+ MT: ->(z) { z.upcase.scan(WORD_CHAR_AND_DIGIT).insert(3, ' ').join },
23
23
  FK: :GB,
24
24
  GS: :GB,
25
25
  PN: :GB,
@@ -30,7 +30,8 @@ module ValidatesZipcode
30
30
  digits = z.scan(/\d/)
31
31
  digits.insert(5, '-') if digits.count > 5
32
32
  digits.join
33
- }
33
+ },
34
+ PR: :US
34
35
  }.freeze
35
36
 
36
37
  def initialize(args = {})
@@ -35,7 +35,7 @@ module ValidatesZipcode
35
35
 
36
36
  return if ValidatesZipcode::Zipcode.new(options).valid?
37
37
 
38
- message = @message || I18n.t('errors.messages.invalid_zipcode', value: value, default: 'Zipcode is invalid')
38
+ message = @message || I18n.t('errors.messages.invalid_zipcode', value: value, default: 'is invalid')
39
39
  record.errors.add(attribute, :invalid_zipcode, message: message)
40
40
  end
41
41
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ValidatesZipcode
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.3'
4
4
  end
@@ -35,6 +35,10 @@ describe ValidatesZipcode::Formatter, '#format' do
35
35
  it { check_format('US', '22162 1010' => '22162-1010') }
36
36
  end
37
37
 
38
+ context 'MT' do
39
+ it { check_format('MT', 'GZR1020' => 'GZR 1020') }
40
+ end
41
+
38
42
  def check_format(country, formatting)
39
43
  from_zip, to_zip = formatting.first
40
44
  expect(::ValidatesZipcode::Formatter.new(zipcode: from_zip, country_alpha2: country).format).to eq(to_zip)
data/spec/spec_helper.rb CHANGED
@@ -423,6 +423,7 @@ TEST_DATA = {
423
423
  valid: %w[
424
424
  C1234CHN
425
425
  C1234
426
+ 6000
426
427
  ],
427
428
  invalid: [
428
429
  nil,
@@ -2218,22 +2219,6 @@ TEST_DATA = {
2218
2219
  '12'
2219
2220
  ]
2220
2221
  },
2221
- BO: {
2222
- valid: %w[
2223
- 7113
2224
- 2566
2225
- 6261
2226
- 7113
2227
- ],
2228
- invalid: [
2229
- nil,
2230
- '',
2231
- 'invalid_zip',
2232
- '12345',
2233
- '1234-1234',
2234
- 'D0D0D0'
2235
- ]
2236
- },
2237
2222
  BW: {
2238
2223
  valid: %w[
2239
2224
  42511
@@ -2628,6 +2613,7 @@ TEST_DATA = {
2628
2613
  valid: %w[
2629
2614
  BV2722
2630
2615
  XY1234
2616
+ 12345
2631
2617
  ],
2632
2618
  invalid: [
2633
2619
  nil,
@@ -2635,7 +2621,8 @@ TEST_DATA = {
2635
2621
  'invalid_zip',
2636
2622
  'B2722',
2637
2623
  'XY12345',
2638
- 'XY123'
2624
+ 'XY123',
2625
+ '123456'
2639
2626
  ]
2640
2627
  },
2641
2628
  IO: {
@@ -2975,16 +2962,16 @@ TEST_DATA = {
2975
2962
  },
2976
2963
  NP: {
2977
2964
  valid: %w[
2978
- 071134
2979
- 025663
2980
- 662612
2981
- 071135
2965
+ 44600
2966
+ 44700
2967
+ 44800
2968
+ 32907
2982
2969
  ],
2983
2970
  invalid: [
2984
2971
  nil,
2985
2972
  '',
2986
2973
  'invalid_zip',
2987
- '12345',
2974
+ '123456',
2988
2975
  '123456-123456',
2989
2976
  'D0D0D0'
2990
2977
  ]
@@ -118,7 +118,7 @@ def zipcode_should_be_invalid(record, _zipcode, options = {})
118
118
  ValidatesZipcode::Validator.new(options.merge(attributes: :zipcode)).validate(record)
119
119
 
120
120
  expect(record.errors.size).to eq 1
121
- expect(record.errors.messages[:zipcode]).to include 'Zipcode is invalid'
121
+ expect(record.errors.messages[:zipcode]).to include 'is invalid'
122
122
  end
123
123
 
124
124
  def zipcode_should_be_invalid_with_custom_message(record, _zipcode, options = {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_zipcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Gil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-13 00:00:00.000000000 Z
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubygems_version: 3.2.22
173
+ rubygems_version: 3.5.17
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Localizable zipcode validation for Rails.