spanish_vat_validators 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 995ed6c4e633b68a19b9389d085b5547ed9af33df5fef486b2ee465f4b79cc4c
|
4
|
+
data.tar.gz: c27a6100f2899bec7a73c878408d35d487024ca656411a47e9a68503571524a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91242e0f2e4951057255ce3d7549d135d4caa20aa706cec9ea9c778c95b51f58d61362262a4535c7daed11b30df1e2a8491abcbaff595af41383751bc02c03f9
|
7
|
+
data.tar.gz: 2922558e2018e8f3b5af22a5e33ff85475b0868aaeefb831419fb8c739e3473e2176f62d3304b417c40aec1752f04a46896368ef92c8b4c911a7521dcbd497b2
|
@@ -13,7 +13,7 @@ module ActiveModel::Validations
|
|
13
13
|
def validate_nif(v)
|
14
14
|
return false if v.nil? || v.empty?
|
15
15
|
value = v.upcase
|
16
|
-
return false unless value.match(
|
16
|
+
return false unless value.match(/\A[0-9]{8}[a-z]\z/i)
|
17
17
|
letters = "TRWAGMYFPDXBNJZSQVHLCKE"
|
18
18
|
check = value.slice!(value.length - 1)
|
19
19
|
calculated_letter = letters[value.to_i % 23].chr
|
@@ -24,12 +24,12 @@ module ActiveModel::Validations
|
|
24
24
|
def validate_cif(v)
|
25
25
|
return false if v.nil? || v.empty?
|
26
26
|
value = v.clone
|
27
|
-
return false unless value.match(
|
27
|
+
return false unless value.match(/\A[a-wyz][0-9]{7}[0-9a-z]\z/i)
|
28
28
|
even = 0
|
29
29
|
odd = 0
|
30
30
|
uletter = ["J", "A", "B", "C", "D", "E", "F", "G", "H", "I"]
|
31
31
|
text = value.upcase
|
32
|
-
regular =
|
32
|
+
regular = /\A[ABCDEFGHJKLMNPQRSVW]\d{7}[0-9,A-J]\z/i
|
33
33
|
if regular.match(value).blank?
|
34
34
|
false
|
35
35
|
else
|
@@ -54,7 +54,7 @@ module ActiveModel::Validations
|
|
54
54
|
def validate_nie(v)
|
55
55
|
return false if v.nil? || v.empty?
|
56
56
|
value = v.upcase
|
57
|
-
return false unless value.match(
|
57
|
+
return false unless value.match(/\A[xyz][0-9]{7}[a-z]\z/i)
|
58
58
|
value[0] = {"X" => "0", "Y" => "1", "Z" => "2"}[value[0]]
|
59
59
|
validate_nif(value)
|
60
60
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.expand_path('../lib/spanish_vat_validators/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Javier Toledo"]
|
5
|
+
gem.authors = ["David Gil", "Javier Toledo"]
|
6
6
|
gem.email = ["javier@theagilemonkeys.com"]
|
7
7
|
gem.description = %q{Provides validators for spanish VAT numbers (NIF, CIF and NIE)}
|
8
8
|
gem.summary = %q{Provides Rails3+ compatible validators for spanish VAT numbers (NIF, CIF and NIE), with support for I18n}
|
@@ -22,6 +22,26 @@ describe ActiveModel::Validations::ValidSpanishVatValidator do
|
|
22
22
|
should_be_invalid(record, 'invalid')
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
it 'adds errors when there are surrounding characters' do
|
27
|
+
%w[22472947S S6185663I Y8527549Z].each do |identification_number|
|
28
|
+
surrounded = %W[junk#{identification_number} #{identification_number}junk junk#{identification_number}junk]
|
29
|
+
surrounded.each do |surrounded_identification_number|
|
30
|
+
record = build_record(surrounded_identification_number)
|
31
|
+
should_be_invalid(record)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'adds errors when there are surrounding lines' do
|
37
|
+
%w[22472947S S6185663I Y8527549Z].each do |identification_number|
|
38
|
+
surrounded = %W[\n#{identification_number} #{identification_number}\n \n#{identification_number}\n]
|
39
|
+
surrounded.each do |surrounded_identification_number|
|
40
|
+
record = build_record(surrounded_identification_number)
|
41
|
+
should_be_invalid(record)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
25
45
|
end
|
26
46
|
end
|
27
47
|
|
@@ -48,6 +68,28 @@ describe ActiveModel::Validations::ValidSpanishIdValidator do
|
|
48
68
|
should_be_invalid(record, 'invalid')
|
49
69
|
end
|
50
70
|
end
|
71
|
+
|
72
|
+
it 'adds errors when there are surrounding characters' do
|
73
|
+
%w[22472947S 96380632Y 28459349T 35696134L 86159868M 29052409M
|
74
|
+
Y8527549Z Y8305424T X9393496C X0012309G Y9370869Q Y2995306F].each do |identification_number|
|
75
|
+
surrounded = %W[junk#{identification_number} #{identification_number}junk junk#{identification_number}junk]
|
76
|
+
surrounded.each do |surrounded_identification_number|
|
77
|
+
record = build_record(surrounded_identification_number)
|
78
|
+
should_be_invalid(record)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'adds errors when there are surrounding lines' do
|
84
|
+
%w[22472947S 96380632Y 28459349T 35696134L 86159868M 29052409M
|
85
|
+
Y8527549Z Y8305424T X9393496C X0012309G Y9370869Q Y2995306F].each do |identification_number|
|
86
|
+
surrounded = %W[\n#{identification_number} #{identification_number}\n \n#{identification_number}\n]
|
87
|
+
surrounded.each do |surrounded_identification_number|
|
88
|
+
record = build_record(surrounded_identification_number)
|
89
|
+
should_be_invalid(record)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
51
93
|
end
|
52
94
|
end
|
53
95
|
|
@@ -73,6 +115,26 @@ describe ActiveModel::Validations::ValidNifValidator do
|
|
73
115
|
should_be_invalid(record, 'invalid')
|
74
116
|
end
|
75
117
|
end
|
118
|
+
|
119
|
+
it 'adds errors when there are surrounding characters' do
|
120
|
+
%w[22472947S 96380632Y 28459349T 35696134L 86159868M 29052409M].each do |identification_number|
|
121
|
+
surrounded = %W[junk#{identification_number} #{identification_number}junk junk#{identification_number}junk]
|
122
|
+
surrounded.each do |surrounded_identification_number|
|
123
|
+
record = build_record(surrounded_identification_number)
|
124
|
+
should_be_invalid(record)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'adds errors when there are surrounding lines' do
|
130
|
+
%w[22472947S 96380632Y 28459349T 35696134L 86159868M 29052409M].each do |identification_number|
|
131
|
+
surrounded = %W[\n#{identification_number} #{identification_number}\n \n#{identification_number}\n]
|
132
|
+
surrounded.each do |surrounded_identification_number|
|
133
|
+
record = build_record(surrounded_identification_number)
|
134
|
+
should_be_invalid(record)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
76
138
|
end
|
77
139
|
end
|
78
140
|
|
@@ -98,6 +160,26 @@ describe ActiveModel::Validations::ValidCifValidator do
|
|
98
160
|
should_be_invalid(record, 'invalid')
|
99
161
|
end
|
100
162
|
end
|
163
|
+
|
164
|
+
it 'adds errors when there are surrounding characters' do
|
165
|
+
%w[S6185663I C2871341J G37880135 F43766880 A58818501 J27950005 V63423321].each do |identification_number|
|
166
|
+
surrounded = %W[junk#{identification_number} #{identification_number}junk junk#{identification_number}junk]
|
167
|
+
surrounded.each do |surrounded_identification_number|
|
168
|
+
record = build_record(surrounded_identification_number)
|
169
|
+
should_be_invalid(record)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'adds errors when there are surrounding lines' do
|
175
|
+
%w[S6185663I C2871341J G37880135 F43766880 A58818501 J27950005 V63423321].each do |identification_number|
|
176
|
+
surrounded = %W[\n#{identification_number} #{identification_number}\n \n#{identification_number}\n]
|
177
|
+
surrounded.each do |surrounded_identification_number|
|
178
|
+
record = build_record(surrounded_identification_number)
|
179
|
+
should_be_invalid(record)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
101
183
|
end
|
102
184
|
end
|
103
185
|
|
@@ -123,6 +205,26 @@ describe ActiveModel::Validations::ValidNieValidator do
|
|
123
205
|
should_be_invalid(record, 'invalid')
|
124
206
|
end
|
125
207
|
end
|
208
|
+
|
209
|
+
it 'adds errors when there are surrounding characters' do
|
210
|
+
%w[Y8527549Z Y8305424T X9393496C X0012309G Y9370869Q Y2995306F].each do |identification_number|
|
211
|
+
surrounded = %W[junk#{identification_number} #{identification_number}junk junk#{identification_number}junk]
|
212
|
+
surrounded.each do |surrounded_identification_number|
|
213
|
+
record = build_record(surrounded_identification_number)
|
214
|
+
should_be_invalid(record)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'adds errors when there are surrounding lines' do
|
220
|
+
%w[Y8527549Z Y8305424T X9393496C X0012309G Y9370869Q Y2995306F].each do |identification_number|
|
221
|
+
surrounded = %W[\n#{identification_number} #{identification_number}\n \n#{identification_number}\n]
|
222
|
+
surrounded.each do |surrounded_identification_number|
|
223
|
+
record = build_record(surrounded_identification_number)
|
224
|
+
should_be_invalid(record)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
126
228
|
end
|
127
229
|
end
|
128
230
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spanish_vat_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- David Gil
|
7
8
|
- Javier Toledo
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2019-12-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activemodel
|
@@ -156,8 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
- !ruby/object:Gem::Version
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
|
-
|
160
|
-
rubygems_version: 2.6.11
|
160
|
+
rubygems_version: 3.0.3
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: Provides Rails3+ compatible validators for spanish VAT numbers (NIF, CIF
|