vat_id_validator 0.0.2 → 0.1.0
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 +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +19 -0
- data/CHANGELOG.md +16 -0
- data/Fudgefile +1 -0
- data/Guardfile +2 -2
- data/Rakefile +1 -1
- data/lib/active_model/validations/vat_id_validator.rb +58 -59
- data/lib/rspec/matchers/validate_vat_id_of.rb +2 -2
- data/lib/vat_id_validator/version.rb +1 -1
- data/spec/active_model/validations/vat_id_validator_spec.rb +273 -271
- data/spec/rspec/matchers/validate_vat_id_of_spec.rb +7 -8
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_model_test_class.rb +4 -1
- data/vat_id_validator.gemspec +12 -10
- metadata +50 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e561972f975d1a75617f7dbee35f8080661be9
|
4
|
+
data.tar.gz: 6f06ca5e167c909f1307a6a07506c1739cc32bb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3439ac1cca3617c9445ea2fc593b5ade67b89d18c91861e4959750e2a1748ea97adee2b9569db1478d5b9baa99e1312d89153a17afc6be0a87448e705560f8f8
|
7
|
+
data.tar.gz: fff9ac2c3ba6f979ebaa099da4db65971a69c67634b399dac7a663cd4c6fd4a3468fd0e52380f944bf55f0e70dab9586e9312689c5b6a372c2fec987aad8655a
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-10-19 14:57:55 +0200 using RuboCop version 0.44.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 59
|
10
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
11
|
+
# URISchemes: http, https
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 100
|
14
|
+
|
15
|
+
# Offense count: 1
|
16
|
+
# Configuration parameters: MinBodyLength.
|
17
|
+
Style/GuardClause:
|
18
|
+
Exclude:
|
19
|
+
- 'lib/active_model/validations/vat_id_validator.rb'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
### Next
|
2
|
+
|
3
|
+
#### Features
|
4
|
+
|
5
|
+
* Your contribution here.
|
6
|
+
|
7
|
+
#### Fixes
|
8
|
+
|
9
|
+
* Your contribution here.
|
10
|
+
|
11
|
+
|
12
|
+
### 0.1.0 (2016/10/19)
|
13
|
+
|
14
|
+
#### Features
|
15
|
+
|
16
|
+
* [5](https://github.com/Sage/vat_id_validator/pull/5): Makes ready for rails 4 and 5 - [@LeFnord](https://github.com/LeFnord).
|
data/Fudgefile
CHANGED
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
guard 'rspec', :
|
1
|
+
guard 'rspec', version: 2, cli: '--drb' do
|
2
2
|
watch(%r{^spec/.+_spec\.rb$})
|
3
3
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
4
|
-
watch('spec/spec_helper.rb') {
|
4
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
5
5
|
end
|
data/Rakefile
CHANGED
@@ -8,67 +8,66 @@ module ActiveModel
|
|
8
8
|
module Validations
|
9
9
|
# Validator for VAT-ID based on ActiveModel::EachValidator.
|
10
10
|
class VatIdValidator < ::ActiveModel::EachValidator
|
11
|
-
|
12
11
|
# All Countries with the vat pattern
|
13
12
|
VAT_PATTERNS = {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
13
|
+
'AL' => /\AAL(J|K)[0-9]{8}[A-Z]\Z/, # Albania
|
14
|
+
'AR' => /\AAR[0-9]{11}\Z/, # Argentina
|
15
|
+
'AT' => /\AATU[0-9]{8}\Z/, # Austria
|
16
|
+
'AU' => /\AAU[0-9]{9}\Z/, # Australia
|
17
|
+
'BE' => /\ABE0[0-9]{9}\Z/, # Belgium
|
18
|
+
'BG' => /\ABG[0-9]{9,10}\Z/, # Bulgaria
|
19
|
+
'BO' => /\ABO/, # Bolivia
|
20
|
+
'BR' => /\ABR[0-9]{8}\Z/, # Brasil
|
21
|
+
'BY' => /\ABY[0-9]{9}\Z/, # Belarus
|
22
|
+
'CA' => /\ACA[0-9]{15}\Z/, # Canada
|
23
|
+
'CH' => /\ACHE[0-9]{9}(MWST|TVA|IVA)\Z/, # Switzerland
|
24
|
+
'CL' => /\ACL[0-9]{9}\Z/, # Chile
|
25
|
+
'CO' => /\ACO[0-9]{10}\Z/, # Colombia
|
26
|
+
'CR' => /\ACR/, # Costa Rica
|
27
|
+
'CY' => /\ACY[0-9]{8}[A-Z]\Z/, # Cyprus
|
28
|
+
'CZ' => /\ACZ[0-9]{8,10}\Z/, # Czech Republic
|
29
|
+
'DE' => /\ADE[0-9]{9}\Z/, # Germany
|
30
|
+
'DK' => /\ADK[0-9]{8}\Z/, # Denmark
|
31
|
+
'DO' => /\ADO/, # Dominican Republic
|
32
|
+
'EC' => /\AEC[0-9]{13}\Z/, # Ecuador
|
33
|
+
'EE' => /\AEE[0-9]{9}\Z/, # Estonia
|
34
|
+
'EL' => /\AEL[0-9]{9}\Z/, # Greece
|
35
|
+
'ES' => /\AES([A-Z][0-9]{8}|[0-9]{8}[A-Z]|[A-Z][0-9]{7}[A-Z])\Z/, # Spain
|
36
|
+
'FI' => /\AFI[0-9]{8}\Z/, # Finland
|
37
|
+
'FR' => /\AFR[A-Z0-9]{2}[0-9]{9}\Z/, # France
|
38
|
+
'GB' => /\AGB([0-9]{9}|[0-9]{12}|(HA|GD)[0-9]{3})\Z/, # United Kingdom
|
39
|
+
'GT' => /\AGT[0-9]{8}\Z/, # Guatemala
|
40
|
+
'HN' => /\AHN/, # Honduras
|
41
|
+
'HR' => /\AHR[0-9]{11}\Z/, # Croatia
|
42
|
+
'HU' => /\AHU[0-9]{8}\Z/, # Hungary
|
43
|
+
'IE' => /\AIE([0-9][A-Z][0-9]{5}|[0-9]{7})[A-Z]{1,2}\Z/, # Ireland
|
44
|
+
'IT' => /\AIT[0-9]{11}\Z/, # Italy
|
45
|
+
'LT' => /\ALT([0-9]{9}|[0-9]{12})\Z/, # Lithuania
|
46
|
+
'LU' => /\ALU[0-9]{8}\Z/, # Luxembourg
|
47
|
+
'LV' => /\ALV[0-9]{11}\Z/, # Latvia
|
48
|
+
'MT' => /\AMT[0-9]{8}\Z/, # Malta
|
49
|
+
'MX' => /\AMX[0-9]{12}\Z/, # Mexico
|
50
|
+
'NI' => /\ANI/, # Nicaragua
|
51
|
+
'NL' => /\ANL[0-9]{9}B[0-9]{2}\Z/, # Netherlands
|
52
|
+
'NO' => /\ANO[0-9]{9}\Z/, # Norway
|
53
|
+
'PA' => /\APA/, # Panama
|
54
|
+
'PE' => /\APE/, # Peru
|
55
|
+
'PH' => /\APH[0-9]{12}\Z/, # Philippines
|
56
|
+
'PL' => /\APL[0-9]{10}\Z/, # Poland
|
57
|
+
'PT' => /\APT[0-9]{9}\Z/, # Portugal
|
58
|
+
'PY' => /\APY/, # Paraguay
|
59
|
+
'RO' => /\ARO[1-9][0-9]{1,9}\Z/, # Romania
|
60
|
+
'RU' => /\ARU[0-9]{10}\Z/, # Russia
|
61
|
+
'SE' => /\ASE[0-9]{10}01\Z/, # Sweden
|
62
|
+
'SI' => /\ASI[0-9]{8}\Z/, # Slovenia
|
63
|
+
'SK' => /\ASK[0-9]{10}\Z/, # Slovakia
|
64
|
+
'SM' => /\ASM[0-9]{5}\Z/, # San Marino
|
65
|
+
'SV' => /\ASV/, # El Salvador
|
66
|
+
'TR' => /\ATR[0-9]{10}\Z/, # Turkey
|
67
|
+
'UA' => /\AUA[0-9]{12}\Z/, # Ukraine
|
68
|
+
'UY' => /\AUY/, # Uruguay
|
69
|
+
'VE' => /\AVE(J|G|V|E)[0-9]{9}\Z/ # Venezuela
|
70
|
+
}.freeze
|
72
71
|
|
73
72
|
# Validates an attribute of a record if it contains a valid VAT-ID.
|
74
73
|
#
|
@@ -21,7 +21,7 @@ module VatIdValidator # :nodoc:
|
|
21
21
|
# @return [boolean]
|
22
22
|
def matches?(actual)
|
23
23
|
validators = actual._validators[@expected]
|
24
|
-
validators.select { |val| val.
|
24
|
+
validators.select { |val| val.is_a?(ActiveModel::Validations::VatIdValidator) }.count > 0
|
25
25
|
end
|
26
26
|
|
27
27
|
# Returns a error message for should matches
|
@@ -42,7 +42,7 @@ module VatIdValidator # :nodoc:
|
|
42
42
|
#
|
43
43
|
# @return [String] the description
|
44
44
|
def description
|
45
|
-
|
45
|
+
'be a vat id'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -7,203 +7,202 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
7
7
|
shared_examples_for 'tax_number with 8 digits' do
|
8
8
|
it 'should be valid with 8 digits' do
|
9
9
|
subject.tax_number = prefix + '12345678'
|
10
|
-
subject.
|
10
|
+
expect(subject).to be_valid
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should not be valid with less then 8 digits' do
|
14
14
|
subject.tax_number = prefix + '1234567'
|
15
|
-
subject.
|
15
|
+
expect(subject).not_to be_valid
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should not be valid with more then 8 digits' do
|
19
19
|
subject.tax_number = prefix + '123456789'
|
20
|
-
subject.
|
20
|
+
expect(subject).not_to be_valid
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
shared_examples_for 'tax_number with 9 digits' do
|
25
25
|
it 'should be valid with 9 digits' do
|
26
26
|
subject.tax_number = prefix + '123456789'
|
27
|
-
subject.
|
27
|
+
expect(subject).to be_valid
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should not be valid with less then 9 digits' do
|
31
31
|
subject.tax_number = prefix + '12345678'
|
32
|
-
subject.
|
32
|
+
expect(subject).not_to be_valid
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should not be valid with more then 9 digits' do
|
36
36
|
subject.tax_number = prefix + '1234567890'
|
37
|
-
subject.
|
37
|
+
expect(subject).not_to be_valid
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
shared_examples_for 'tax_number with 10 digits' do
|
42
42
|
it 'should be valid with 10 digits' do
|
43
43
|
subject.tax_number = prefix + '1234567890'
|
44
|
-
subject.
|
44
|
+
expect(subject).to be_valid
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should not be valid with less then 10 digits' do
|
48
48
|
subject.tax_number = prefix + '123456789'
|
49
|
-
subject.
|
49
|
+
expect(subject).not_to be_valid
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should not be valid with more then 10 digits' do
|
53
53
|
subject.tax_number = prefix + '12345678901'
|
54
|
-
subject.
|
54
|
+
expect(subject).not_to be_valid
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
shared_examples_for 'tax_number with 11 digits' do
|
59
59
|
it 'should be valid with 11 digits' do
|
60
60
|
subject.tax_number = prefix + '12345678901'
|
61
|
-
subject.
|
61
|
+
expect(subject).to be_valid
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should not be valid with less then 11 digits' do
|
65
65
|
subject.tax_number = prefix + '1234567890'
|
66
|
-
subject.
|
66
|
+
expect(subject).not_to be_valid
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should not be valid with more then 11 digits' do
|
70
70
|
subject.tax_number = prefix + '123456789012'
|
71
|
-
subject.
|
71
|
+
expect(subject).not_to be_valid
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
shared_examples_for 'tax_number with 12 digits' do
|
76
76
|
it 'should be valid with 12 digits' do
|
77
77
|
subject.tax_number = prefix + '123456789012'
|
78
|
-
subject.
|
78
|
+
expect(subject).to be_valid
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should not be valid with less then 12 digits' do
|
82
82
|
subject.tax_number = prefix + '12345678901'
|
83
|
-
subject.
|
83
|
+
expect(subject).not_to be_valid
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should not be valid with more then 12 digits' do
|
87
87
|
subject.tax_number = prefix + '1234567890123'
|
88
|
-
subject.
|
88
|
+
expect(subject).not_to be_valid
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
shared_examples_for 'tax_number with only prefix check' do
|
93
93
|
it 'should be valid with the given prefix' do
|
94
94
|
subject.tax_number = prefix + '123ABC'
|
95
|
-
subject.
|
95
|
+
expect(subject).to be_valid
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should be valid without tax_number' do
|
100
|
-
|
100
|
+
is_expected.to be_valid
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'should not be valid without prefix' do
|
104
104
|
subject.tax_number = '123456789'
|
105
|
-
subject.
|
105
|
+
expect(subject).not_to be_valid
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should ignore special character and spaces for validation (formatting)' do
|
109
109
|
subject.tax_number = 'DE 12-345.678/9'
|
110
|
-
subject.
|
110
|
+
expect(subject).to be_valid
|
111
111
|
end
|
112
112
|
|
113
113
|
context 'when the tax_number starts with' do
|
114
|
-
|
115
114
|
context 'AL (Albania)' do
|
116
115
|
let(:prefix) { 'AL' }
|
117
|
-
|
116
|
+
|
118
117
|
it 'should be valid with "K" + 8 digits + 1 char' do
|
119
118
|
subject.tax_number = prefix + 'K12345678X'
|
120
|
-
subject.
|
119
|
+
expect(subject).to be_valid
|
121
120
|
end
|
122
|
-
|
121
|
+
|
123
122
|
it 'should be valid with "J" + 8 digits + 1 char' do
|
124
123
|
subject.tax_number = prefix + 'J12345678X'
|
125
|
-
subject.
|
124
|
+
expect(subject).to be_valid
|
126
125
|
end
|
127
|
-
|
126
|
+
|
128
127
|
it 'should not be valid if the first char is not "K" or "J"' do
|
129
128
|
subject.tax_number = prefix + 'X12345678X'
|
130
|
-
subject.
|
129
|
+
expect(subject).not_to be_valid
|
131
130
|
end
|
132
|
-
|
131
|
+
|
133
132
|
it 'should not be valid with less then 8 digits' do
|
134
133
|
subject.tax_number = prefix + 'J1234567X'
|
135
|
-
subject.
|
134
|
+
expect(subject).not_to be_valid
|
136
135
|
end
|
137
|
-
|
136
|
+
|
138
137
|
it 'should not be valid with more then 8 digits' do
|
139
138
|
subject.tax_number = prefix + 'K123456789X'
|
140
|
-
subject.
|
139
|
+
expect(subject).not_to be_valid
|
141
140
|
end
|
142
141
|
end
|
143
|
-
|
142
|
+
|
144
143
|
context 'AR (Argentina)' do
|
145
144
|
let(:prefix) { 'AR' }
|
146
145
|
|
147
146
|
it_behaves_like 'tax_number with 11 digits'
|
148
147
|
end
|
149
|
-
|
148
|
+
|
150
149
|
context 'ATU (Austria)' do
|
151
150
|
let(:prefix) { 'ATU' }
|
152
|
-
|
151
|
+
|
153
152
|
it_behaves_like 'tax_number with 8 digits'
|
154
153
|
end
|
155
|
-
|
154
|
+
|
156
155
|
context 'AU (Australia)' do
|
157
156
|
let(:prefix) { 'AU' }
|
158
|
-
|
157
|
+
|
159
158
|
it_behaves_like 'tax_number with 9 digits'
|
160
159
|
end
|
161
|
-
|
160
|
+
|
162
161
|
context 'BE (Belgium)' do
|
163
162
|
let(:prefix) { 'BE' }
|
164
|
-
|
163
|
+
|
165
164
|
it 'should be valid with 10 digits (first digit == 0)' do
|
166
165
|
subject.tax_number = prefix + '0123456789'
|
167
|
-
subject.
|
166
|
+
expect(subject).to be_valid
|
168
167
|
end
|
169
|
-
|
168
|
+
|
170
169
|
it 'should not be valid with 10 digits (first digit != 0)' do
|
171
170
|
subject.tax_number = prefix + '1123456789'
|
172
|
-
subject.
|
171
|
+
expect(subject).not_to be_valid
|
173
172
|
end
|
174
|
-
|
173
|
+
|
175
174
|
it 'should not be valid with less then 10 digits' do
|
176
175
|
subject.tax_number = prefix + '012345678'
|
177
|
-
subject.
|
176
|
+
expect(subject).not_to be_valid
|
178
177
|
end
|
179
|
-
|
178
|
+
|
180
179
|
it 'should not be valid with more then 10 digits' do
|
181
180
|
subject.tax_number = prefix + '01234567890'
|
182
|
-
subject.
|
181
|
+
expect(subject).not_to be_valid
|
183
182
|
end
|
184
183
|
end
|
185
|
-
|
184
|
+
|
186
185
|
context 'BG (Bulgaria)' do
|
187
186
|
let(:prefix) { 'BG' }
|
188
|
-
|
187
|
+
|
189
188
|
it 'should be valid with 9 digits' do
|
190
189
|
subject.tax_number = prefix + '123456789'
|
191
|
-
subject.
|
190
|
+
expect(subject).to be_valid
|
192
191
|
end
|
193
|
-
|
192
|
+
|
194
193
|
it 'should be valid with 10 digits' do
|
195
194
|
subject.tax_number = prefix + '1234567890'
|
196
|
-
subject.
|
195
|
+
expect(subject).to be_valid
|
197
196
|
end
|
198
|
-
|
197
|
+
|
199
198
|
it 'should not be valid with less then 9 digits' do
|
200
199
|
subject.tax_number = prefix + '12345678'
|
201
|
-
subject.
|
200
|
+
expect(subject).not_to be_valid
|
202
201
|
end
|
203
|
-
|
202
|
+
|
204
203
|
it 'should not be valid with more then 10 digits' do
|
205
204
|
subject.tax_number = prefix + '12345678901'
|
206
|
-
subject.
|
205
|
+
expect(subject).not_to be_valid
|
207
206
|
end
|
208
207
|
end
|
209
208
|
|
@@ -221,93 +220,91 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
221
220
|
|
222
221
|
context 'BY (Belarus)' do
|
223
222
|
let(:prefix) { 'BY' }
|
224
|
-
|
223
|
+
|
225
224
|
it_behaves_like 'tax_number with 9 digits'
|
226
225
|
end
|
227
|
-
|
226
|
+
|
228
227
|
context 'CA (Canada)' do
|
229
228
|
let(:prefix) { 'CA' }
|
230
|
-
|
229
|
+
|
231
230
|
it 'should be valid with 15 digits' do
|
232
231
|
subject.tax_number = prefix + '123456789012345'
|
233
|
-
subject.
|
232
|
+
expect(subject).to be_valid
|
234
233
|
end
|
235
|
-
|
234
|
+
|
236
235
|
it 'should not be valid with less then 15 digits' do
|
237
236
|
subject.tax_number = prefix + '12345678901234'
|
238
|
-
subject.
|
237
|
+
expect(subject).not_to be_valid
|
239
238
|
end
|
240
|
-
|
239
|
+
|
241
240
|
it 'should not be valid with more then 15 digits' do
|
242
241
|
subject.tax_number = prefix + '1234567890123456'
|
243
|
-
subject.
|
242
|
+
expect(subject).not_to be_valid
|
244
243
|
end
|
245
244
|
end
|
246
|
-
|
245
|
+
|
247
246
|
context 'CHE (Switzerland)' do
|
248
247
|
let(:prefix) { 'CHE' }
|
249
|
-
|
248
|
+
|
250
249
|
it 'should not be valid without suffix' do
|
251
250
|
subject.tax_number = prefix + '123456789'
|
252
|
-
subject.
|
251
|
+
expect(subject).not_to be_valid
|
253
252
|
end
|
254
|
-
|
253
|
+
|
255
254
|
context 'and the tax_number ends with MWST (de-CH)' do
|
256
255
|
let(:suffix) { 'MWST' }
|
257
256
|
it 'should be valid with 9 digits' do
|
258
257
|
subject.tax_number = prefix + '123456789' + suffix
|
259
|
-
subject.
|
258
|
+
expect(subject).to be_valid
|
260
259
|
end
|
261
|
-
|
260
|
+
|
262
261
|
it 'should not be valid with less then 9 digits' do
|
263
262
|
subject.tax_number = prefix + '12345678' + suffix
|
264
|
-
subject.
|
263
|
+
expect(subject).not_to be_valid
|
265
264
|
end
|
266
|
-
|
265
|
+
|
267
266
|
it 'should not be valid with more then 9 digits' do
|
268
267
|
subject.tax_number = prefix + '1234567890' + suffix
|
269
|
-
subject.
|
268
|
+
expect(subject).not_to be_valid
|
270
269
|
end
|
271
270
|
end
|
272
|
-
|
271
|
+
|
273
272
|
context 'and the tax_number ends with TVA (de-FR)' do
|
274
273
|
let(:suffix) { 'TVA' }
|
275
|
-
|
274
|
+
|
276
275
|
it 'should be valid with 9 digits' do
|
277
276
|
subject.tax_number = prefix + '123456789' + suffix
|
278
|
-
subject.
|
277
|
+
expect(subject).to be_valid
|
279
278
|
end
|
280
|
-
|
279
|
+
|
281
280
|
it 'should not be valid with less then 9 digits' do
|
282
281
|
subject.tax_number = prefix + '12345678' + suffix
|
283
|
-
subject.
|
282
|
+
expect(subject).not_to be_valid
|
284
283
|
end
|
285
|
-
|
284
|
+
|
286
285
|
it 'should not be valid with more then 9 digits' do
|
287
286
|
subject.tax_number = prefix + '1234567890' + suffix
|
288
|
-
subject.
|
287
|
+
expect(subject).not_to be_valid
|
289
288
|
end
|
290
289
|
end
|
291
|
-
|
290
|
+
|
292
291
|
context 'and the tax_number ends with IVA (de-IT)' do
|
293
292
|
let(:suffix) { 'IVA' }
|
294
293
|
it 'should be valid with 9 digits' do
|
295
294
|
subject.tax_number = prefix + '123456789' + suffix
|
296
|
-
subject.
|
295
|
+
expect(subject).to be_valid
|
297
296
|
end
|
298
|
-
|
297
|
+
|
299
298
|
it 'should not be valid with less then 9 digits' do
|
300
299
|
subject.tax_number = prefix + '12345678' + suffix
|
301
|
-
subject.
|
300
|
+
expect(subject).not_to be_valid
|
302
301
|
end
|
303
|
-
|
302
|
+
|
304
303
|
it 'should not be valid with more then 9 digits' do
|
305
304
|
subject.tax_number = prefix + '1234567890' + suffix
|
306
|
-
subject.
|
305
|
+
expect(subject).not_to be_valid
|
307
306
|
end
|
308
307
|
end
|
309
|
-
|
310
|
-
|
311
308
|
end
|
312
309
|
|
313
310
|
context 'CL (Chile)' do
|
@@ -331,66 +328,66 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
331
328
|
context 'CY (Cyprus)' do
|
332
329
|
let(:prefix) { 'CY' }
|
333
330
|
let(:suffix) { 'L' } # A-Z
|
334
|
-
|
331
|
+
|
335
332
|
it 'should not be valid without suffix' do
|
336
333
|
subject.tax_number = prefix + '12345678'
|
337
|
-
subject.
|
334
|
+
expect(subject).not_to be_valid
|
338
335
|
end
|
339
|
-
|
336
|
+
|
340
337
|
it 'should be valid with 8 digits' do
|
341
338
|
subject.tax_number = prefix + '12345678' + suffix
|
342
|
-
subject.
|
339
|
+
expect(subject).to be_valid
|
343
340
|
end
|
344
|
-
|
341
|
+
|
345
342
|
it 'should not be valid with less then 8 digits' do
|
346
343
|
subject.tax_number = prefix + '1234567' + suffix
|
347
|
-
subject.
|
344
|
+
expect(subject).not_to be_valid
|
348
345
|
end
|
349
|
-
|
346
|
+
|
350
347
|
it 'should not be valid with more then 8 digits' do
|
351
348
|
subject.tax_number = prefix + '123456789' + suffix
|
352
|
-
subject.
|
349
|
+
expect(subject).not_to be_valid
|
353
350
|
end
|
354
351
|
end
|
355
|
-
|
352
|
+
|
356
353
|
context 'CZ (Czech Republic)' do
|
357
354
|
let(:prefix) { 'CZ' }
|
358
|
-
|
355
|
+
|
359
356
|
it 'should be valid with 8 digits' do
|
360
357
|
subject.tax_number = prefix + '12345678'
|
361
|
-
subject.
|
358
|
+
expect(subject).to be_valid
|
362
359
|
end
|
363
|
-
|
360
|
+
|
364
361
|
it 'should be valid with 9 digits' do
|
365
362
|
subject.tax_number = prefix + '123456789'
|
366
|
-
subject.
|
363
|
+
expect(subject).to be_valid
|
367
364
|
end
|
368
|
-
|
365
|
+
|
369
366
|
it 'should be valid with 10 digits' do
|
370
367
|
subject.tax_number = prefix + '1234567890'
|
371
|
-
subject.
|
368
|
+
expect(subject).to be_valid
|
372
369
|
end
|
373
|
-
|
370
|
+
|
374
371
|
it 'should not be valid with less then 8 digits' do
|
375
372
|
subject.tax_number = prefix + '1234567'
|
376
|
-
subject.
|
373
|
+
expect(subject).not_to be_valid
|
377
374
|
end
|
378
|
-
|
375
|
+
|
379
376
|
it 'should not be valid with more then 10 digits' do
|
380
377
|
subject.tax_number = prefix + '12345678901'
|
381
|
-
subject.
|
378
|
+
expect(subject).not_to be_valid
|
382
379
|
end
|
383
380
|
end
|
384
|
-
|
381
|
+
|
385
382
|
context 'DE (Germany)' do
|
386
383
|
let(:prefix) { 'DE' }
|
387
|
-
|
384
|
+
|
388
385
|
it_behaves_like 'tax_number with 9 digits'
|
389
386
|
end
|
390
|
-
|
387
|
+
|
391
388
|
context 'DK (Denmark)' do
|
392
389
|
let(:prefix) { 'DK' }
|
393
|
-
|
390
|
+
|
394
391
|
it_behaves_like 'tax_number with 8 digits'
|
395
392
|
end
|
396
393
|
|
@@ -405,156 +402,156 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
405
402
|
|
406
403
|
it 'should be valid with 13 digits' do
|
407
404
|
subject.tax_number = prefix + '1234567890123'
|
408
|
-
subject.
|
405
|
+
expect(subject).to be_valid
|
409
406
|
end
|
410
407
|
|
411
408
|
it 'should not be valid with less then 13 digits' do
|
412
409
|
subject.tax_number = prefix + '123456789012'
|
413
|
-
subject.
|
410
|
+
expect(subject).not_to be_valid
|
414
411
|
end
|
415
412
|
|
416
413
|
it 'should not be valid with more then 13 digits' do
|
417
414
|
subject.tax_number = prefix + '12345678901234'
|
418
|
-
subject.
|
415
|
+
expect(subject).not_to be_valid
|
419
416
|
end
|
420
417
|
end
|
421
418
|
|
422
419
|
context 'EE (Estonia)' do
|
423
420
|
let(:prefix) { 'EE' }
|
424
|
-
|
421
|
+
|
425
422
|
it_behaves_like 'tax_number with 9 digits'
|
426
423
|
end
|
427
|
-
|
424
|
+
|
428
425
|
context 'EL (Greece)' do
|
429
426
|
let(:prefix) { 'EL' }
|
430
|
-
|
427
|
+
|
431
428
|
it_behaves_like 'tax_number with 9 digits'
|
432
429
|
end
|
433
|
-
|
430
|
+
|
434
431
|
context 'ES (Spain)' do
|
435
432
|
let(:prefix) { 'ES' }
|
436
|
-
|
433
|
+
|
437
434
|
it 'should be valid with 1 char + 8 digits' do
|
438
435
|
subject.tax_number = prefix + 'X12345678'
|
439
|
-
subject.
|
436
|
+
expect(subject).to be_valid
|
440
437
|
end
|
441
|
-
|
438
|
+
|
442
439
|
it 'should be valid with 8 digits + 1 char' do
|
443
440
|
subject.tax_number = prefix + '12345678X'
|
444
|
-
subject.
|
441
|
+
expect(subject).to be_valid
|
445
442
|
end
|
446
|
-
|
443
|
+
|
447
444
|
it 'should be valid with 1 char + 7 digits + 1 char' do
|
448
445
|
subject.tax_number = prefix + 'X1234567X'
|
449
|
-
subject.
|
446
|
+
expect(subject).to be_valid
|
450
447
|
end
|
451
|
-
|
448
|
+
|
452
449
|
it 'should not be valid with less then 9 digits/chars' do
|
453
450
|
subject.tax_number = prefix + 'X1234567'
|
454
|
-
subject.
|
451
|
+
expect(subject).not_to be_valid
|
455
452
|
end
|
456
|
-
|
453
|
+
|
457
454
|
it 'should not be valid with more then 9 digits/chats' do
|
458
455
|
subject.tax_number = prefix + '123456789X'
|
459
|
-
subject.
|
456
|
+
expect(subject).not_to be_valid
|
460
457
|
end
|
461
458
|
end
|
462
|
-
|
459
|
+
|
463
460
|
context 'FI (Finland)' do
|
464
461
|
let(:prefix) { 'FI' }
|
465
|
-
|
462
|
+
|
466
463
|
it_behaves_like 'tax_number with 8 digits'
|
467
464
|
end
|
468
|
-
|
465
|
+
|
469
466
|
context 'FR (France)' do
|
470
467
|
let(:prefix) { 'FR' }
|
471
|
-
|
468
|
+
|
472
469
|
it 'should be valid with 2 digits/chars + 9 digits' do
|
473
470
|
subject.tax_number = prefix + '1X123456789'
|
474
|
-
subject.
|
471
|
+
expect(subject).to be_valid
|
475
472
|
end
|
476
|
-
|
473
|
+
|
477
474
|
it 'should not be valid with less then 11 digits' do
|
478
475
|
subject.tax_number = prefix + '1234567890'
|
479
|
-
subject.
|
476
|
+
expect(subject).not_to be_valid
|
480
477
|
end
|
481
|
-
|
478
|
+
|
482
479
|
it 'should not be valid with more then 11 digits' do
|
483
480
|
subject.tax_number = prefix + '123456789012'
|
484
|
-
subject.
|
481
|
+
expect(subject).not_to be_valid
|
485
482
|
end
|
486
483
|
end
|
487
|
-
|
484
|
+
|
488
485
|
context 'GB (United Kingdom)' do
|
489
486
|
let(:prefix) { 'GB' }
|
490
|
-
|
487
|
+
|
491
488
|
context 'with digets only' do
|
492
489
|
it 'should be valid with 9 digits (standard)' do
|
493
490
|
subject.tax_number = prefix + '123456789'
|
494
|
-
subject.
|
491
|
+
expect(subject).to be_valid
|
495
492
|
end
|
496
|
-
|
493
|
+
|
497
494
|
it 'should be valid with 12 digits (branch traders)' do
|
498
495
|
subject.tax_number = prefix + '123456789012'
|
499
|
-
subject.
|
496
|
+
expect(subject).to be_valid
|
500
497
|
end
|
501
|
-
|
498
|
+
|
502
499
|
it 'should not be valid with less then 9 digits' do
|
503
500
|
subject.tax_number = prefix + '12345678'
|
504
|
-
subject.
|
501
|
+
expect(subject).not_to be_valid
|
505
502
|
end
|
506
|
-
|
503
|
+
|
507
504
|
it 'should not be valid with 10 digits' do
|
508
505
|
subject.tax_number = prefix + '1234567890'
|
509
|
-
subject.
|
506
|
+
expect(subject).not_to be_valid
|
510
507
|
end
|
511
|
-
|
508
|
+
|
512
509
|
it 'should not be valid with 11 digits' do
|
513
510
|
subject.tax_number = prefix + '12345678901'
|
514
|
-
subject.
|
511
|
+
expect(subject).not_to be_valid
|
515
512
|
end
|
516
|
-
|
513
|
+
|
517
514
|
it 'should not be valid with more then 12 digits' do
|
518
515
|
subject.tax_number = prefix + '1234567890123'
|
519
|
-
subject.
|
516
|
+
expect(subject).not_to be_valid
|
520
517
|
end
|
521
518
|
end
|
522
|
-
|
519
|
+
|
523
520
|
context 'with prefix addition "HA" (health authorities)' do
|
524
521
|
let(:addition) { 'HA' }
|
525
|
-
|
522
|
+
|
526
523
|
it 'should be valid with 3 digits' do
|
527
524
|
subject.tax_number = prefix + addition + '123'
|
528
|
-
subject.
|
525
|
+
expect(subject).to be_valid
|
529
526
|
end
|
530
|
-
|
527
|
+
|
531
528
|
it 'should not be valid with less then 3 digits' do
|
532
529
|
subject.tax_number = prefix + addition + '12'
|
533
|
-
subject.
|
530
|
+
expect(subject).not_to be_valid
|
534
531
|
end
|
535
|
-
|
532
|
+
|
536
533
|
it 'should not be valid with more then 3 digits' do
|
537
534
|
subject.tax_number = prefix + addition + '1234'
|
538
|
-
subject.
|
535
|
+
expect(subject).not_to be_valid
|
539
536
|
end
|
540
537
|
end
|
541
|
-
|
538
|
+
|
542
539
|
context 'with prefix addition "GD" (government departments)' do
|
543
540
|
let(:addition) { 'GD' }
|
544
|
-
|
541
|
+
|
545
542
|
it 'should be valid with 3 digits' do
|
546
543
|
subject.tax_number = prefix + addition + '123'
|
547
|
-
subject.
|
544
|
+
expect(subject).to be_valid
|
548
545
|
end
|
549
|
-
|
546
|
+
|
550
547
|
it 'should not be valid with less then 3 digits' do
|
551
548
|
subject.tax_number = prefix + addition + '12'
|
552
|
-
subject.
|
549
|
+
expect(subject).not_to be_valid
|
553
550
|
end
|
554
|
-
|
551
|
+
|
555
552
|
it 'should not be valid with more then 3 digits' do
|
556
553
|
subject.tax_number = prefix + addition + '1234'
|
557
|
-
subject.
|
554
|
+
expect(subject).not_to be_valid
|
558
555
|
end
|
559
556
|
end
|
560
557
|
end
|
@@ -573,100 +570,105 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
573
570
|
|
574
571
|
context 'HR (Croatia)' do
|
575
572
|
let(:prefix) { 'HR' }
|
576
|
-
|
573
|
+
|
577
574
|
it_behaves_like 'tax_number with 11 digits'
|
578
575
|
end
|
579
|
-
|
576
|
+
|
580
577
|
context 'HU (Hungary)' do
|
581
578
|
let(:prefix) { 'HU' }
|
582
|
-
|
579
|
+
|
583
580
|
it_behaves_like 'tax_number with 8 digits'
|
584
581
|
end
|
585
|
-
|
582
|
+
|
586
583
|
context 'IE (Ireland)' do
|
587
584
|
let(:prefix) { 'IE' }
|
588
|
-
|
589
|
-
it 'should be valid with 1 digit + 1 char + 5 digets +
|
590
|
-
subject.tax_number = prefix + '
|
591
|
-
subject.
|
585
|
+
|
586
|
+
it 'should be valid with 1 digit + 1 char + 5 digets + 2 char' do
|
587
|
+
subject.tax_number = prefix + '1X12345LT'
|
588
|
+
expect(subject).to be_valid
|
592
589
|
end
|
593
|
-
|
590
|
+
|
594
591
|
it 'should be valid with 7 digits + 1 char' do
|
595
592
|
subject.tax_number = prefix + '1234567L'
|
596
|
-
subject.
|
593
|
+
expect(subject).to be_valid
|
597
594
|
end
|
598
|
-
|
595
|
+
|
596
|
+
it 'should be valid with 7 digits + 2 char' do
|
597
|
+
subject.tax_number = prefix + '1234567LS'
|
598
|
+
expect(subject).to be_valid
|
599
|
+
end
|
600
|
+
|
599
601
|
it 'should not be valid if last is not a char' do
|
600
602
|
subject.tax_number = prefix + '12345678'
|
601
|
-
subject.
|
603
|
+
expect(subject).not_to be_valid
|
602
604
|
end
|
603
|
-
|
605
|
+
|
604
606
|
it 'should not be valid with less then 7 digits + 1 char' do
|
605
607
|
subject.tax_number = prefix + '123456L'
|
606
|
-
subject.
|
608
|
+
expect(subject).not_to be_valid
|
607
609
|
end
|
608
|
-
|
610
|
+
|
609
611
|
it 'should not be valid with more then 7 digits + 1 char' do
|
610
612
|
subject.tax_number = prefix + '12345678L'
|
611
|
-
subject.
|
613
|
+
expect(subject).not_to be_valid
|
612
614
|
end
|
613
615
|
end
|
614
|
-
|
616
|
+
|
615
617
|
context 'IT (Italy)' do
|
616
618
|
let(:prefix) { 'IT' }
|
617
|
-
|
619
|
+
|
618
620
|
it_behaves_like 'tax_number with 11 digits'
|
619
621
|
end
|
620
|
-
|
622
|
+
|
621
623
|
context 'LT (Lithuania)' do
|
622
624
|
let(:prefix) { 'LT' }
|
623
|
-
|
625
|
+
|
624
626
|
it 'should be valid with 9 digits' do
|
625
627
|
subject.tax_number = prefix + '123456789'
|
626
|
-
subject.
|
628
|
+
expect(subject).to be_valid
|
627
629
|
end
|
628
|
-
|
630
|
+
|
629
631
|
it 'should be valid with 12 digits' do
|
630
632
|
subject.tax_number = prefix + '123456789012'
|
631
|
-
subject.
|
633
|
+
expect(subject).to be_valid
|
632
634
|
end
|
633
|
-
|
635
|
+
|
634
636
|
it 'should not be valid with less then 9 digits' do
|
635
637
|
subject.tax_number = prefix + '12345678'
|
636
|
-
subject.
|
638
|
+
expect(subject).not_to be_valid
|
637
639
|
end
|
638
|
-
|
640
|
+
|
639
641
|
it 'should not be valid with 10 digits' do
|
640
642
|
subject.tax_number = prefix + '1234567890'
|
641
|
-
subject.
|
643
|
+
expect(subject).not_to be_valid
|
642
644
|
end
|
643
|
-
|
645
|
+
|
644
646
|
it 'should not be valid with 11 digits' do
|
645
647
|
subject.tax_number = prefix + '12345678901'
|
646
|
-
subject.
|
648
|
+
expect(subject).not_to be_valid
|
647
649
|
end
|
648
|
-
|
650
|
+
|
649
651
|
it 'should not be valid with more then 12 digits' do
|
650
652
|
subject.tax_number = prefix + '1234567890123'
|
651
|
-
subject.
|
653
|
+
expect(subject).not_to be_valid
|
652
654
|
end
|
653
655
|
end
|
654
|
-
|
656
|
+
|
655
657
|
context 'LU (Luxembourg)' do
|
656
658
|
let(:prefix) { 'LU' }
|
657
|
-
|
659
|
+
|
658
660
|
it_behaves_like 'tax_number with 8 digits'
|
659
661
|
end
|
660
|
-
|
662
|
+
|
661
663
|
context 'LV (Latvia)' do
|
662
664
|
let(:prefix) { 'LV' }
|
663
|
-
|
665
|
+
|
664
666
|
it_behaves_like 'tax_number with 11 digits'
|
665
667
|
end
|
666
668
|
|
667
669
|
context 'MT (Malta)' do
|
668
670
|
let(:prefix) { 'MT' }
|
669
|
-
|
671
|
+
|
670
672
|
it_behaves_like 'tax_number with 8 digits'
|
671
673
|
end
|
672
674
|
|
@@ -684,41 +686,41 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
684
686
|
|
685
687
|
context 'NL (Netherlands)' do
|
686
688
|
let(:prefix) { 'NL' }
|
687
|
-
|
689
|
+
|
688
690
|
it 'should be valid with 9 digits + "B" + 2 digits' do
|
689
691
|
subject.tax_number = prefix + '123456789B12'
|
690
|
-
subject.
|
692
|
+
expect(subject).to be_valid
|
691
693
|
end
|
692
|
-
|
694
|
+
|
693
695
|
it 'should not be valid without "B" on the 10 position' do
|
694
696
|
subject.tax_number = prefix + '123456789X12'
|
695
|
-
subject.
|
697
|
+
expect(subject).not_to be_valid
|
696
698
|
end
|
697
|
-
|
699
|
+
|
698
700
|
it 'should not be valid with less 9 digits + "B" + 2 digits' do
|
699
701
|
subject.tax_number = prefix + '12345678B12'
|
700
|
-
subject.
|
702
|
+
expect(subject).not_to be_valid
|
701
703
|
end
|
702
|
-
|
704
|
+
|
703
705
|
it 'should not be valid with more 9 digits + "B" + 2 digits' do
|
704
706
|
subject.tax_number = prefix + '1234567890B12'
|
705
|
-
subject.
|
707
|
+
expect(subject).not_to be_valid
|
706
708
|
end
|
707
|
-
|
709
|
+
|
708
710
|
it 'should not be valid with 8 digits + "B" + less then 2 digits' do
|
709
711
|
subject.tax_number = prefix + '12345678B1'
|
710
|
-
subject.
|
712
|
+
expect(subject).not_to be_valid
|
711
713
|
end
|
712
|
-
|
714
|
+
|
713
715
|
it 'should not be valid with more 8 digits + "B" + more then 2 digits' do
|
714
716
|
subject.tax_number = prefix + '12345678B123'
|
715
|
-
subject.
|
717
|
+
expect(subject).not_to be_valid
|
716
718
|
end
|
717
719
|
end
|
718
|
-
|
720
|
+
|
719
721
|
context 'NO (Norway)' do
|
720
722
|
let(:prefix) { 'NO' }
|
721
|
-
|
723
|
+
|
722
724
|
it_behaves_like 'tax_number with 9 digits'
|
723
725
|
end
|
724
726
|
|
@@ -736,19 +738,19 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
736
738
|
|
737
739
|
context 'PH (Philippines)' do
|
738
740
|
let(:prefix) { 'PH' }
|
739
|
-
|
741
|
+
|
740
742
|
it_behaves_like 'tax_number with 12 digits'
|
741
743
|
end
|
742
|
-
|
744
|
+
|
743
745
|
context 'PL (Poland)' do
|
744
746
|
let(:prefix) { 'PL' }
|
745
|
-
|
747
|
+
|
746
748
|
it_behaves_like 'tax_number with 10 digits'
|
747
749
|
end
|
748
|
-
|
750
|
+
|
749
751
|
context 'PT (Portugal)' do
|
750
752
|
let(:prefix) { 'PT' }
|
751
|
-
|
753
|
+
|
752
754
|
it_behaves_like 'tax_number with 9 digits'
|
753
755
|
end
|
754
756
|
|
@@ -760,126 +762,126 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
760
762
|
|
761
763
|
context 'RO (Romania)' do
|
762
764
|
let(:prefix) { 'RO' }
|
763
|
-
|
765
|
+
|
764
766
|
it 'should be valid with 2 digits' do
|
765
767
|
subject.tax_number = prefix + '12'
|
766
|
-
subject.
|
768
|
+
expect(subject).to be_valid
|
767
769
|
end
|
768
|
-
|
770
|
+
|
769
771
|
it 'should be valid with 3 digits' do
|
770
772
|
subject.tax_number = prefix + '123'
|
771
|
-
subject.
|
773
|
+
expect(subject).to be_valid
|
772
774
|
end
|
773
|
-
|
775
|
+
|
774
776
|
it 'should be valid with 4 digits' do
|
775
777
|
subject.tax_number = prefix + '1234'
|
776
|
-
subject.
|
778
|
+
expect(subject).to be_valid
|
777
779
|
end
|
778
|
-
|
780
|
+
|
779
781
|
it 'should be valid with 5 digits' do
|
780
782
|
subject.tax_number = prefix + '12345'
|
781
|
-
subject.
|
783
|
+
expect(subject).to be_valid
|
782
784
|
end
|
783
|
-
|
785
|
+
|
784
786
|
it 'should be valid with 6 digits' do
|
785
787
|
subject.tax_number = prefix + '123456'
|
786
|
-
subject.
|
788
|
+
expect(subject).to be_valid
|
787
789
|
end
|
788
|
-
|
790
|
+
|
789
791
|
it 'should be valid with 7 digits' do
|
790
792
|
subject.tax_number = prefix + '1234567'
|
791
|
-
subject.
|
793
|
+
expect(subject).to be_valid
|
792
794
|
end
|
793
|
-
|
795
|
+
|
794
796
|
it 'should be valid with 8 digits' do
|
795
797
|
subject.tax_number = prefix + '12345678'
|
796
|
-
subject.
|
798
|
+
expect(subject).to be_valid
|
797
799
|
end
|
798
|
-
|
800
|
+
|
799
801
|
it 'should be valid with 9 digits' do
|
800
802
|
subject.tax_number = prefix + '123456789'
|
801
|
-
subject.
|
803
|
+
expect(subject).to be_valid
|
802
804
|
end
|
803
|
-
|
805
|
+
|
804
806
|
it 'should be valid with 10 digits' do
|
805
807
|
subject.tax_number = prefix + '123456789'
|
806
|
-
subject.
|
808
|
+
expect(subject).to be_valid
|
807
809
|
end
|
808
|
-
|
810
|
+
|
809
811
|
it 'should not be valid if the first digit is 0' do
|
810
812
|
subject.tax_number = prefix + '01'
|
811
|
-
subject.
|
813
|
+
expect(subject).not_to be_valid
|
812
814
|
end
|
813
|
-
|
815
|
+
|
814
816
|
it 'should not be valid with less then 2 digits' do
|
815
817
|
subject.tax_number = prefix + '1'
|
816
|
-
subject.
|
818
|
+
expect(subject).not_to be_valid
|
817
819
|
end
|
818
|
-
|
820
|
+
|
819
821
|
it 'should not be valid with more then 10 digits' do
|
820
822
|
subject.tax_number = prefix + '12345678901'
|
821
|
-
subject.
|
823
|
+
expect(subject).not_to be_valid
|
822
824
|
end
|
823
825
|
end
|
824
|
-
|
826
|
+
|
825
827
|
context 'RU (Russia)' do
|
826
828
|
let(:prefix) { 'RU' }
|
827
|
-
|
829
|
+
|
828
830
|
it_behaves_like 'tax_number with 10 digits'
|
829
831
|
end
|
830
|
-
|
832
|
+
|
831
833
|
context 'SE (Sweden)' do
|
832
834
|
let(:prefix) { 'SE' }
|
833
|
-
|
835
|
+
|
834
836
|
it 'should be valid with 10 digits + "01"' do
|
835
837
|
subject.tax_number = prefix + '123456789001'
|
836
|
-
subject.
|
838
|
+
expect(subject).to be_valid
|
837
839
|
end
|
838
|
-
|
840
|
+
|
839
841
|
it 'should not be valid without "01" at the end' do
|
840
842
|
subject.tax_number = prefix + '123456789012'
|
841
|
-
subject.
|
843
|
+
expect(subject).not_to be_valid
|
842
844
|
end
|
843
|
-
|
845
|
+
|
844
846
|
it 'should not be valid with less then 10 digits + "01"' do
|
845
847
|
subject.tax_number = prefix + '12345678901'
|
846
|
-
subject.
|
848
|
+
expect(subject).not_to be_valid
|
847
849
|
end
|
848
|
-
|
850
|
+
|
849
851
|
it 'should not be valid with more then 10 digits + "01"' do
|
850
852
|
subject.tax_number = prefix + '1234567890101'
|
851
|
-
subject.
|
853
|
+
expect(subject).not_to be_valid
|
852
854
|
end
|
853
855
|
end
|
854
|
-
|
856
|
+
|
855
857
|
context 'SI (Slovenia)' do
|
856
858
|
let(:prefix) { 'SI' }
|
857
|
-
|
859
|
+
|
858
860
|
it_behaves_like 'tax_number with 8 digits'
|
859
861
|
end
|
860
|
-
|
862
|
+
|
861
863
|
context 'SK (Slovakia)' do
|
862
864
|
let(:prefix) { 'SK' }
|
863
|
-
|
865
|
+
|
864
866
|
it_behaves_like 'tax_number with 10 digits'
|
865
867
|
end
|
866
|
-
|
868
|
+
|
867
869
|
context 'SM (San Marino)' do
|
868
870
|
let(:prefix) { 'SM' }
|
869
|
-
|
871
|
+
|
870
872
|
it 'should be valid with 5 digits' do
|
871
873
|
subject.tax_number = prefix + '12345'
|
872
|
-
subject.
|
874
|
+
expect(subject).to be_valid
|
873
875
|
end
|
874
|
-
|
876
|
+
|
875
877
|
it 'should not be valid with less then 5 digits' do
|
876
878
|
subject.tax_number = prefix + '1234'
|
877
|
-
subject.
|
879
|
+
expect(subject).not_to be_valid
|
878
880
|
end
|
879
|
-
|
881
|
+
|
880
882
|
it 'should not be valid with more then 5 digits' do
|
881
883
|
subject.tax_number = prefix + '123456'
|
882
|
-
subject.
|
884
|
+
expect(subject).not_to be_valid
|
883
885
|
end
|
884
886
|
end
|
885
887
|
|
@@ -891,13 +893,13 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
891
893
|
|
892
894
|
context 'TR (Turkey)' do
|
893
895
|
let(:prefix) { 'TR' }
|
894
|
-
|
896
|
+
|
895
897
|
it_behaves_like 'tax_number with 10 digits'
|
896
898
|
end
|
897
|
-
|
899
|
+
|
898
900
|
context 'UA (Ukraine)' do
|
899
901
|
let(:prefix) { 'UA' }
|
900
|
-
|
902
|
+
|
901
903
|
it_behaves_like 'tax_number with 12 digits'
|
902
904
|
end
|
903
905
|
|
@@ -912,32 +914,32 @@ describe ActiveModel::Validations::VatIdValidator do
|
|
912
914
|
|
913
915
|
it 'should be valid with "J" + 9 digits' do
|
914
916
|
subject.tax_number = prefix + 'J123456789'
|
915
|
-
subject.
|
917
|
+
expect(subject).to be_valid
|
916
918
|
end
|
917
919
|
|
918
920
|
it 'should be valid with "G" + 9 digits' do
|
919
921
|
subject.tax_number = prefix + 'G123456789'
|
920
|
-
subject.
|
922
|
+
expect(subject).to be_valid
|
921
923
|
end
|
922
924
|
|
923
925
|
it 'should be valid with "V" + 9 digits' do
|
924
926
|
subject.tax_number = prefix + 'V123456789'
|
925
|
-
subject.
|
927
|
+
expect(subject).to be_valid
|
926
928
|
end
|
927
929
|
|
928
930
|
it 'should be valid with "E" + 9 digits' do
|
929
931
|
subject.tax_number = prefix + 'E123456789'
|
930
|
-
subject.
|
932
|
+
expect(subject).to be_valid
|
931
933
|
end
|
932
934
|
|
933
935
|
it 'should not be valid with less then 9 digits' do
|
934
936
|
subject.tax_number = prefix + 'E12345678'
|
935
|
-
subject.
|
937
|
+
expect(subject).not_to be_valid
|
936
938
|
end
|
937
939
|
|
938
940
|
it 'should not be valid with more then 9 digits' do
|
939
941
|
subject.tax_number = prefix + 'E1234567890'
|
940
|
-
subject.
|
942
|
+
expect(subject).not_to be_valid
|
941
943
|
end
|
942
944
|
end
|
943
945
|
end
|