valvat 1.0.1 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/ruby.yml +41 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +15 -0
  6. data/CHANGES.md +27 -1
  7. data/Gemfile +2 -0
  8. data/Guardfile +6 -4
  9. data/README.md +6 -4
  10. data/Rakefile +3 -1
  11. data/certs/yolk.pem +25 -24
  12. data/gemfiles/activemodel-5 +1 -1
  13. data/gemfiles/activemodel-6 +1 -1
  14. data/gemfiles/{activemodel-3-2 → activemodel-7} +2 -2
  15. data/lib/active_model/validations/valvat_validator.rb +65 -32
  16. data/lib/valvat/checksum/at.rb +3 -1
  17. data/lib/valvat/checksum/be.rb +3 -1
  18. data/lib/valvat/checksum/bg.rb +17 -17
  19. data/lib/valvat/checksum/cy.rb +2 -0
  20. data/lib/valvat/checksum/de.rb +5 -3
  21. data/lib/valvat/checksum/dk.rb +3 -1
  22. data/lib/valvat/checksum/ee.rb +2 -0
  23. data/lib/valvat/checksum/es.rb +14 -16
  24. data/lib/valvat/checksum/fi.rb +3 -1
  25. data/lib/valvat/checksum/fr.rb +4 -2
  26. data/lib/valvat/checksum/gb.rb +46 -31
  27. data/lib/valvat/checksum/gr.rb +4 -2
  28. data/lib/valvat/checksum/hr.rb +2 -0
  29. data/lib/valvat/checksum/hu.rb +2 -0
  30. data/lib/valvat/checksum/ie.rb +5 -6
  31. data/lib/valvat/checksum/it.rb +7 -5
  32. data/lib/valvat/checksum/lt.rb +2 -0
  33. data/lib/valvat/checksum/lu.rb +3 -1
  34. data/lib/valvat/checksum/mt.rb +2 -0
  35. data/lib/valvat/checksum/nl.rb +5 -3
  36. data/lib/valvat/checksum/pl.rb +3 -1
  37. data/lib/valvat/checksum/pt.rb +3 -1
  38. data/lib/valvat/checksum/ro.rb +2 -0
  39. data/lib/valvat/checksum/se.rb +5 -3
  40. data/lib/valvat/checksum/si.rb +4 -2
  41. data/lib/valvat/checksum.rb +24 -28
  42. data/lib/valvat/error.rb +8 -2
  43. data/lib/valvat/local.rb +6 -4
  44. data/lib/valvat/locales/de.yml +2 -1
  45. data/lib/valvat/locales/en.yml +2 -1
  46. data/lib/valvat/locales/es.yml +1 -0
  47. data/lib/valvat/locales/fr.yml +1 -0
  48. data/lib/valvat/locales/hu.yml +1 -0
  49. data/lib/valvat/locales/nl.yml +1 -0
  50. data/lib/valvat/locales/pl.yml +1 -0
  51. data/lib/valvat/lookup/fault.rb +29 -21
  52. data/lib/valvat/lookup/request.rb +21 -16
  53. data/lib/valvat/lookup/response.rb +11 -10
  54. data/lib/valvat/lookup.rb +5 -4
  55. data/lib/valvat/syntax.rb +31 -30
  56. data/lib/valvat/utils.rb +12 -9
  57. data/lib/valvat/version.rb +3 -1
  58. data/lib/valvat.rb +4 -2
  59. data/spec/active_model/validations/valvat_validator_spec.rb +99 -93
  60. data/spec/spec_helper.rb +8 -8
  61. data/spec/valvat/checksum/at_spec.rb +6 -4
  62. data/spec/valvat/checksum/be_spec.rb +6 -4
  63. data/spec/valvat/checksum/bg_spec.rb +7 -4
  64. data/spec/valvat/checksum/cy_spec.rb +3 -1
  65. data/spec/valvat/checksum/de_spec.rb +6 -4
  66. data/spec/valvat/checksum/dk_spec.rb +6 -4
  67. data/spec/valvat/checksum/ee_spec.rb +3 -1
  68. data/spec/valvat/checksum/es_spec.rb +7 -4
  69. data/spec/valvat/checksum/fi_spec.rb +6 -4
  70. data/spec/valvat/checksum/fr_spec.rb +6 -4
  71. data/spec/valvat/checksum/gb_spec.rb +4 -2
  72. data/spec/valvat/checksum/gr_spec.rb +6 -4
  73. data/spec/valvat/checksum/hr_spec.rb +3 -1
  74. data/spec/valvat/checksum/hu_spec.rb +3 -1
  75. data/spec/valvat/checksum/ie_spec.rb +8 -6
  76. data/spec/valvat/checksum/it_spec.rb +10 -8
  77. data/spec/valvat/checksum/lt_spec.rb +3 -1
  78. data/spec/valvat/checksum/lu_spec.rb +6 -4
  79. data/spec/valvat/checksum/mt_spec.rb +3 -1
  80. data/spec/valvat/checksum/nl_spec.rb +9 -7
  81. data/spec/valvat/checksum/pl_spec.rb +8 -6
  82. data/spec/valvat/checksum/pt_spec.rb +10 -11
  83. data/spec/valvat/checksum/ro_spec.rb +3 -1
  84. data/spec/valvat/checksum/se_spec.rb +8 -6
  85. data/spec/valvat/checksum/si_spec.rb +10 -8
  86. data/spec/valvat/checksum_spec.rb +24 -9
  87. data/spec/valvat/lookup/fault_spec.rb +34 -0
  88. data/spec/valvat/lookup/request_spec.rb +32 -0
  89. data/spec/valvat/lookup/response_spec.rb +29 -0
  90. data/spec/valvat/lookup_spec.rb +171 -152
  91. data/spec/valvat/syntax_spec.rb +59 -280
  92. data/spec/valvat/utils_spec.rb +64 -47
  93. data/spec/valvat_spec.rb +140 -152
  94. data/valvat.gemspec +17 -17
  95. data.tar.gz.sig +1 -2
  96. metadata +48 -50
  97. metadata.gz.sig +0 -0
  98. data/.travis.yml +0 -47
  99. data/gemfiles/activemodel-4 +0 -7
  100. data/gemfiles/before-ruby21/activemodel-3-2 +0 -8
  101. data/gemfiles/before-ruby21/activemodel-4 +0 -8
  102. data/gemfiles/before-ruby21/standalone +0 -7
  103. data/spec/valvat/lockup/fault_spec.rb +0 -32
  104. data/spec/valvat/lockup/request_spec.rb +0 -15
  105. data/spec/valvat/lockup/response_spec.rb +0 -27
@@ -1,289 +1,68 @@
1
- require 'spec_helper'
2
-
3
- describe Valvat::Syntax do
4
- describe "#validate" do
5
- it "validates a DE VAT number" do
6
- expect(subject.validate("DE345889003")).to eql(true)
7
-
8
- expect(subject.validate("DE34588900")).to eql(false)
9
- expect(subject.validate("DE3458890090")).to eql(false)
10
- expect(subject.validate("DE34588900C")).to eql(false)
11
- end
12
-
13
- it "validates a AT VAT number" do
14
- expect(subject.validate("ATU03458890")).to eql(true)
15
-
16
- expect(subject.validate("ATU034588908")).to eql(false)
17
- expect(subject.validate("ATU0345908")).to eql(false)
18
- expect(subject.validate("ATU0345889Y")).to eql(false)
19
- end
20
-
21
- it "should validate BE VAT number" do
22
- expect(subject.validate("BE0817331995")).to eql(true)
23
-
24
- expect(subject.validate("BE081733199")).to eql(false)
25
- expect(subject.validate("BE08173319944")).to eql(false)
26
- expect(subject.validate("BE081733199H")).to eql(false)
27
- expect(subject.validate("BE1817331999")).to eql(false)
28
- end
29
-
30
- it "validates a BG VAT number" do
31
- expect(subject.validate("BG468134789")).to eql(true)
32
- expect(subject.validate("BG4681347897")).to eql(true)
33
-
34
- expect(subject.validate("BG46813478979")).to eql(false)
35
- expect(subject.validate("BG4681347897C")).to eql(false)
36
- expect(subject.validate("BG46813478G")).to eql(false)
37
- expect(subject.validate("BG46813478")).to eql(false)
38
- end
39
-
40
- it "validates a CY VAT number" do
41
- expect(subject.validate("CY36579347A")).to eql(true)
42
- expect(subject.validate("CY36579347C")).to eql(true)
43
-
44
- expect(subject.validate("CY36579347")).to eql(false)
45
- expect(subject.validate("CY365793478")).to eql(false)
46
- expect(subject.validate("CY365793478A")).to eql(false)
47
- expect(subject.validate("CY365793G")).to eql(false)
48
- end
49
-
50
- it "validates a DK VAT number" do
51
- expect(subject.validate("DK67893463")).to eql(true)
52
-
53
- expect(subject.validate("DK678934637")).to eql(false)
54
- expect(subject.validate("DK6789346")).to eql(false)
55
- expect(subject.validate("DK6789346H")).to eql(false)
56
- end
57
-
58
- it "validates a ES VAT number" do
59
- expect(subject.validate("ESX67345987")).to eql(true)
60
- expect(subject.validate("ESA6734598B")).to eql(true)
61
- expect(subject.validate("ES56734598C")).to eql(true)
62
-
63
- expect(subject.validate("ES167345987")).to eql(false)
64
- expect(subject.validate("ESX6734598")).to eql(false)
65
- expect(subject.validate("ESX673459890")).to eql(false)
66
- end
67
-
68
- it "validates a EE VAT number" do
69
- expect(subject.validate("EE100207415")).to eql(true)
70
- expect(subject.validate("EE1002074150")).to eql(false)
71
- expect(subject.validate("EE10020741")).to eql(false)
72
- expect(subject.validate("EE100207415K")).to eql(false)
73
- end
74
-
75
- it "validates a FI VAT number" do
76
- expect(subject.validate("FI67845638")).to eql(true)
77
-
78
- expect(subject.validate("FI678456389")).to eql(false)
79
- expect(subject.validate("FI6784563")).to eql(false)
80
- expect(subject.validate("FI6784563K")).to eql(false)
81
- end
82
-
83
- it "validates a FR VAT number" do
84
- expect(subject.validate("FR99123543267")).to eql(true)
85
- expect(subject.validate("FRBB123543267")).to eql(true)
86
- expect(subject.validate("FR9B123543267")).to eql(true)
87
- expect(subject.validate("FRB9123543267")).to eql(true)
88
-
89
- expect(subject.validate("FR99123543267B")).to eql(false)
90
- expect(subject.validate("FRBB12354326")).to eql(false)
91
- expect(subject.validate("FR9B123543F67")).to eql(false)
92
- expect(subject.validate("FRB9123543")).to eql(false)
93
- end
94
-
95
- it "validates a EL VAT number" do
96
- expect(subject.validate("EL678456345")).to eql(true)
97
-
98
- expect(subject.validate("EL67845634")).to eql(false)
99
- expect(subject.validate("EL6784563459")).to eql(false)
100
- expect(subject.validate("EL67845634P")).to eql(false)
101
- end
102
-
103
- it "validates a HU VAT number" do
104
- expect(subject.validate("HU67894595")).to eql(true)
105
-
106
- expect(subject.validate("HU6789459")).to eql(false)
107
- expect(subject.validate("HU67894595L")).to eql(false)
108
- expect(subject.validate("HU6789459J")).to eql(false)
109
- end
110
-
111
- it "validates a HR VAT number" do
112
- expect(subject.validate("HR12345678912")).to eql(true)
113
-
114
- expect(subject.validate("HR6789459")).to eql(false)
115
- expect(subject.validate("HR67894595L")).to eql(false)
116
- expect(subject.validate("HR6789459J")).to eql(false)
117
- end
118
-
119
- it "validates a IE VAT number" do
120
- expect(subject.validate("IE1B12345J")).to eql(true)
121
- expect(subject.validate("IE1234567B")).to eql(true)
122
- expect(subject.validate("IE1234567XX")).to eql(true)
123
-
124
- expect(subject.validate("IE1B123459")).to eql(false)
125
- expect(subject.validate("IE19123450")).to eql(false)
126
- expect(subject.validate("IEA9123450")).to eql(false)
127
- expect(subject.validate("IE1B12345XX")).to eql(false)
128
- expect(subject.validate("IE1X34567XX")).to eql(false)
129
- end
130
-
131
- it "validates a IT VAT number" do
132
- expect(subject.validate("IT45875359285")).to eql(true)
1
+ # frozen_string_literal: true
133
2
 
134
- expect(subject.validate("IT458753592859")).to eql(false)
135
- expect(subject.validate("IT4587535928G")).to eql(false)
136
- expect(subject.validate("IT4587535928")).to eql(false)
137
- end
138
-
139
- it "validates a LV VAT number" do
140
- expect(subject.validate("LV85678368906")).to eql(true)
141
-
142
- expect(subject.validate("LV8567836890")).to eql(false)
143
- expect(subject.validate("LV856783689066")).to eql(false)
144
- expect(subject.validate("LV8567836890S")).to eql(false)
145
- end
146
-
147
- it "validates a LT VAT number" do
148
- expect(subject.validate("LT213179412")).to eql(true)
149
- expect(subject.validate("LT290061371314")).to eql(true)
150
-
151
- expect(subject.validate("LT21317942")).to eql(false)
152
- expect(subject.validate("LT213179422")).to eql(false)
153
- expect(subject.validate("LT2131794120")).to eql(false)
154
- expect(subject.validate("LT213179412K")).to eql(false)
155
- expect(subject.validate("LT29006137132")).to eql(false)
156
- expect(subject.validate("LT290061371324")).to eql(false)
157
- expect(subject.validate("LT29006137131C")).to eql(false)
158
- expect(subject.validate("LT290061371314H")).to eql(false)
159
- end
160
-
161
- it "validates a LU VAT number" do
162
- expect(subject.validate("LU45679456")).to eql(true)
163
-
164
- expect(subject.validate("LU4567945")).to eql(false)
165
- expect(subject.validate("LU456794560")).to eql(false)
166
- expect(subject.validate("LU4567945J")).to eql(false)
167
- end
168
-
169
- it "validates a MT VAT number" do
170
- expect(subject.validate("MT64569367")).to eql(true)
171
-
172
- expect(subject.validate("MT6456936")).to eql(false)
173
- expect(subject.validate("MT645693679")).to eql(false)
174
- expect(subject.validate("MT6456936L")).to eql(false)
175
- end
176
-
177
- it "validates a NL VAT number" do
178
- expect(subject.validate("NL673739491B77")).to eql(true)
179
-
180
- expect(subject.validate("NL673739491977")).to eql(false)
181
- expect(subject.validate("NL673739491A77")).to eql(false)
182
- expect(subject.validate("NL673739491B771")).to eql(false)
183
- expect(subject.validate("NL673739491B7")).to eql(false)
184
- expect(subject.validate("NL6737394917B7")).to eql(false)
185
- end
186
-
187
- it "validates a PL VAT number" do
188
- expect(subject.validate("PL6784567284")).to eql(true)
189
-
190
- expect(subject.validate("PL678456728")).to eql(false)
191
- expect(subject.validate("PL67845672849")).to eql(false)
192
- expect(subject.validate("PL678456728K")).to eql(false)
193
- end
194
-
195
- it "validates a PT VAT number" do
196
- expect(subject.validate("PT346296476")).to eql(true)
197
-
198
- expect(subject.validate("PT34629647")).to eql(false)
199
- expect(subject.validate("PT3462964769")).to eql(false)
200
- end
201
-
202
- it "validates a GB VAT number" do
203
- expect(subject.validate("GB123456789")).to eql(true)
204
- expect(subject.validate("GB123456789012")).to eql(true)
205
- expect(subject.validate("GBGD123")).to eql(true)
206
- expect(subject.validate("GBHA123")).to eql(true)
207
-
208
- expect(subject.validate("GB12345678")).to eql(false)
209
- expect(subject.validate("GB1234567890")).to eql(false)
210
- expect(subject.validate("GB12345678901")).to eql(false)
211
- expect(subject.validate("GB1234567890123")).to eql(false)
212
- expect(subject.validate("GBAB123")).to eql(false)
213
- expect(subject.validate("GBAA123")).to eql(false)
214
- expect(subject.validate("GBHH123")).to eql(false)
215
- expect(subject.validate("GBGD1234")).to eql(false)
216
- expect(subject.validate("GBGD12")).to eql(false)
217
- end
218
-
219
- it "validates a RO VAT number" do
220
- expect(subject.validate("RO1234567890")).to eql(true)
221
- expect(subject.validate("RO123456789")).to eql(true)
222
- expect(subject.validate("RO12345678")).to eql(true)
223
- expect(subject.validate("RO1234567")).to eql(true)
224
- expect(subject.validate("RO123456")).to eql(true)
225
- expect(subject.validate("RO12345")).to eql(true)
226
- expect(subject.validate("RO1234")).to eql(true)
227
- expect(subject.validate("RO123")).to eql(true)
228
- expect(subject.validate("RO12")).to eql(true)
229
-
230
- expect(subject.validate("RO1")).to eql(false)
231
- expect(subject.validate("RO0234567890")).to eql(false)
232
- expect(subject.validate("RO023456789")).to eql(false)
233
- expect(subject.validate("RO02345678")).to eql(false)
234
- expect(subject.validate("RO0234567")).to eql(false)
235
- expect(subject.validate("RO023456")).to eql(false)
236
- expect(subject.validate("RO02345")).to eql(false)
237
- expect(subject.validate("RO0234")).to eql(false)
238
- expect(subject.validate("RO023")).to eql(false)
239
- expect(subject.validate("RO02")).to eql(false)
240
- expect(subject.validate("RO12345678901")).to eql(false)
241
- end
242
-
243
- it "validates a SK VAT number" do
244
- expect(subject.validate("SK5683075682")).to eql(true)
245
-
246
- expect(subject.validate("SK56830756821")).to eql(false)
247
- expect(subject.validate("SK568307568")).to eql(false)
248
- end
249
-
250
- it "validates a SI VAT number" do
251
- expect(subject.validate("SI74357893")).to eql(true)
252
-
253
- expect(subject.validate("SI743578931")).to eql(false)
254
- expect(subject.validate("SI7435789")).to eql(false)
255
- end
256
-
257
- it "validates a SE VAT number" do
258
- expect(subject.validate("SE567396352701")).to eql(true)
259
-
260
- expect(subject.validate("SE56739635201")).to eql(false)
261
- expect(subject.validate("SE5673963527701")).to eql(false)
262
- expect(subject.validate("SE567396352702")).to eql(false)
263
- expect(subject.validate("SE567396352711")).to eql(false)
264
- end
265
-
266
- it "validates a CZ VAT number" do
267
- expect(subject.validate("CZ56389267")).to eql(true)
268
- expect(subject.validate("CZ563892670")).to eql(true)
269
- expect(subject.validate("CZ5638926790")).to eql(true)
3
+ require 'spec_helper'
270
4
 
271
- expect(subject.validate("CZ5638926")).to eql(false)
272
- expect(subject.validate("CZ56389268901")).to eql(false)
5
+ def it_validates(valid_vats, invalid_vats)
6
+ valid_vats.each do |valid|
7
+ it "returns true for #{valid.inspect}" do
8
+ expect(described_class.validate(valid)).to be(true)
273
9
  end
10
+ end
274
11
 
275
- it "returns false on blank/non-sense VAT number" do
276
- expect(subject.validate("")).to eql(false)
277
- expect(subject.validate(" ")).to eql(false)
278
- expect(subject.validate("DE")).to eql(false)
279
- expect(subject.validate("atu123xyz")).to eql(false)
280
- expect(subject.validate("xxxxxxxxxx")).to eql(false)
281
- expect(subject.validate("BEFR")).to eql(false)
12
+ invalid_vats.each do |invalid|
13
+ it "returns false for #{invalid.inspect}" do
14
+ expect(described_class.validate(invalid)).to be(false)
282
15
  end
16
+ end
17
+ end
283
18
 
284
- it "allows Valvat instance as input" do
285
- expect(subject.validate(Valvat.new("DE345889003"))).to eql(true)
286
- expect(subject.validate(Valvat.new("DE34588900X"))).to eql(false)
19
+ describe Valvat::Syntax do
20
+ describe '#validate' do
21
+ it_validates(%w[ATU03458890], %w[ATU034588908 ATU0345908 ATU0345889Y])
22
+ it_validates(%w[BE0817331995], %w[BE081733199 BE08173319944 BE081733199H BE1817331999])
23
+ it_validates(%w[BG468134789 BG4681347897], %w[BG46813478979 BG4681347897C BG46813478G BG46813478])
24
+ it_validates(%w[CY36579347A CY36579347C], %w[CY36579347 CY365793478 CY365793478A CY365793G])
25
+ it_validates(%w[CZ56389267 CZ563892670 CZ5638926790], %w[CZ5638926 CZ56389268901])
26
+ it_validates(%w[DE345889003], %w[DE34588900 DE3458890090 DE34588900C])
27
+ it_validates(%w[DK67893463], %w[DK678934637 DK6789346 DK6789346H])
28
+ it_validates(%w[EE100207415], %w[EE1002074150 EE10020741 EE10020741 EE100207415K])
29
+ it_validates(%w[EL678456345], %w[EL67845634 EL6784563459 EL67845634P])
30
+ it_validates(%w[ESX67345987 ESA6734598B ES56734598C], %w[ES167345987 ESX6734598 ESX673459890])
31
+ it_validates(%w[FI67845638], %w[FI678456389 FI6784563 FI6784563K])
32
+ it_validates(%w[FR99123543267 FRBB123543267 FR9B123543267 FRB9123543267],
33
+ %w[FR99123543267B FRBB12354326 FR9B123543F67 FRB9123543])
34
+ it_validates(%w[GB123456789 GB123456789012 GBGD123 GBHA123],
35
+ %w[GB12345678 GB1234567890 GB12345678901 GB1234567890123 GBAB123 GBAA123 GBHH123 GBGD1234 GBGD12])
36
+ it_validates(%w[HR12345678912], %w[HR6789459 HR67894595L HR6789459J])
37
+ it_validates(%w[HU67894595], %w[HU6789459 HU67894595L HU6789459J])
38
+ it_validates(%w[IE1B12345J IE1234567B IE1234567XX], %w[IE1B123459 IE19123450 IEA9123450 IE1B12345XX IE1X34567XX])
39
+ it_validates(%w[IT45875359285 IT00146089990], %w[IT458753592859 IT4587535928G IT4587535928])
40
+ it_validates(%w[LT213179412 LT290061371314],
41
+ %w[LT21317942 LT213179422 LT2131794120 LT213179412K LT29006137132 LT290061371324 LT29006137131C
42
+ LT290061371314H])
43
+ it_validates(%w[LU45679456], %w[LU4567945 LU456794560 LU4567945J])
44
+ it_validates(%w[LV85678368906], %w[LV8567836890 LV856783689066 LV8567836890S])
45
+ it_validates(%w[MT64569367], %w[MT6456936 MT645693679 MT6456936L])
46
+ it_validates(%w[NL673739491B77], %w[NL673739491977 NL673739491A77 NL673739491B771 NL673739491B7 NL6737394917B7])
47
+ it_validates(%w[PL6784567284], %w[PL678456728 PL67845672849 PL678456728K])
48
+ it_validates(%w[PT346296476], %w[PT34629647 PT3462964769])
49
+ it_validates(%w[RO1234567890 RO123456789 RO12345678 RO1234567 RO123456 RO12345 RO1234 RO123 RO12],
50
+ %w[RO1 RO0234567890 RO023456789 RO02345678 RO0234567 RO023456 RO02345 RO0234 RO02 RO12345678901])
51
+ it_validates(%w[SE567396352701], %w[SE56739635201 SE5673963527701 SE567396352702 SE567396352711])
52
+ it_validates(%w[SI74357893], %w[SI743578931 SI7435789])
53
+ it_validates(%w[SK5683075682], %w[SK56830756821 SK568307568])
54
+ it_validates(%w[XI123456789 XI123456789012 XIGD123 XIHA123],
55
+ %w[XI12345678 XI12345678901234 XIGD1234 XIHA1234 XIGD12 XIHA12 XIHD123])
56
+
57
+ it 'returns false on blank/non-sense VAT number' do
58
+ ['', ' ', 'DE', 'atu123xyz', 'xxxxxxxxxx', 'BEFR'].each do |input|
59
+ expect(described_class.validate(input)).to be(false)
60
+ end
61
+ end
62
+
63
+ it 'allows Valvat instance as input' do
64
+ expect(described_class.validate(Valvat.new('DE345889003'))).to be(true)
65
+ expect(described_class.validate(Valvat.new('DE34588900X'))).to be(false)
287
66
  end
288
67
  end
289
68
  end
@@ -1,97 +1,114 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  describe Valvat::Utils do
5
- describe "#split" do
6
- it "returns country and rest on VAT number as array" do
7
- expect(Valvat::Utils.split("DE345889003")).to eql(["DE", "345889003"])
8
- expect(Valvat::Utils.split("ESX4588900X")).to eql(["ES", "X4588900X"])
6
+ describe '#split' do
7
+ it 'returns country and rest on VAT number as array' do
8
+ expect(described_class.split('DE345889003')).to eql(%w[DE 345889003])
9
+ expect(described_class.split('ESX4588900X')).to eql(%w[ES X4588900X])
10
+ end
11
+
12
+ it 'returns two nils on non-european iso codes as array' do
13
+ expect(described_class.split('US345889003')).to eql([nil, nil])
14
+ expect(described_class.split('RUX4588900X')).to eql([nil, nil])
9
15
  end
10
16
 
11
- it "returns two nils on non-european iso codes as array" do
12
- expect(Valvat::Utils.split("US345889003")).to eql([nil, nil])
13
- expect(Valvat::Utils.split("RUX4588900X")).to eql([nil, nil])
17
+ it 'returns two nils on non-sense input as array' do
18
+ expect(described_class.split('DE')).to eql([nil, nil])
19
+ expect(described_class.split('X345889003')).to eql([nil, nil])
20
+ expect(described_class.split('')).to eql([nil, nil])
21
+ expect(described_class.split('1234')).to eql([nil, nil])
22
+ expect(described_class.split(' ')).to eql([nil, nil]) # rubocop:disable Style/RedundantArgument
14
23
  end
15
24
 
16
- it "returns two nils on non-sense input as array" do
17
- expect(Valvat::Utils.split("DE")).to eql([nil, nil])
18
- expect(Valvat::Utils.split("X345889003")).to eql([nil, nil])
19
- expect(Valvat::Utils.split("")).to eql([nil, nil])
20
- expect(Valvat::Utils.split("1234")).to eql([nil, nil])
21
- expect(Valvat::Utils.split(" ")).to eql([nil, nil])
25
+ it 'returns EL (language iso code) on greek vat' do
26
+ expect(described_class.split('EL999999999')).to eql(%w[EL 999999999])
22
27
  end
23
28
 
24
- it "returns EL (language iso code) on greek vat" do
25
- expect(Valvat::Utils.split("EL999999999")).to eql(["EL", "999999999"])
29
+ it 'returns XI (vat number code) on northern ireland vat' do
30
+ expect(described_class.split('XI999999999')).to eql(%w[XI 999999999])
26
31
  end
27
32
  end
28
33
 
29
- describe "#normalize" do
30
- it "returns VAT number with upcase chars" do
31
- expect(Valvat::Utils.normalize("de345889003")).to eql("DE345889003")
32
- expect(Valvat::Utils.normalize("EsX4588900y")).to eql("ESX4588900Y")
34
+ describe '#normalize' do
35
+ it 'returns VAT number with upcase chars' do
36
+ expect(described_class.normalize('de345889003')).to eql('DE345889003')
37
+ expect(described_class.normalize('EsX4588900y')).to eql('ESX4588900Y')
33
38
  end
34
39
 
35
- it "returns trimmed VAT number" do
36
- expect(Valvat::Utils.normalize(" DE345889003")).to eql("DE345889003")
37
- expect(Valvat::Utils.normalize(" DE345889003 ")).to eql("DE345889003")
38
- expect(Valvat::Utils.normalize("DE345889003 ")).to eql("DE345889003")
40
+ it 'returns trimmed VAT number' do
41
+ expect(described_class.normalize(' DE345889003')).to eql('DE345889003')
42
+ expect(described_class.normalize(' DE345889003 ')).to eql('DE345889003')
43
+ expect(described_class.normalize('DE345889003 ')).to eql('DE345889003')
39
44
  end
40
45
 
41
- it "does not change already normalized VAT numbers" do
42
- expect(Valvat::Utils.normalize("DE345889003")).to eql("DE345889003")
43
- expect(Valvat::Utils.normalize("ESX4588900X")).to eql("ESX4588900X")
46
+ it 'does not change already normalized VAT numbers' do
47
+ expect(described_class.normalize('DE345889003')).to eql('DE345889003')
48
+ expect(described_class.normalize('ESX4588900X')).to eql('ESX4588900X')
44
49
  end
45
50
 
46
- it "removes spaces" do
47
- expect(Valvat::Utils.normalize("DE 345889003")).to eql("DE345889003")
48
- expect(Valvat::Utils.normalize("ESX 458 8900 X")).to eql("ESX4588900X")
51
+ it 'removes spaces' do
52
+ expect(described_class.normalize('DE 345889003')).to eql('DE345889003')
53
+ expect(described_class.normalize('ESX 458 8900 X')).to eql('ESX4588900X')
49
54
  end
50
55
 
51
- it "removes special chars" do
52
- expect(Valvat::Utils.normalize("DE.345-889_00:3,;")).to eql("DE345889003")
53
- expect(Valvat::Utils.normalize("→ DE·Ö34588 9003\0 ☺")).to eql("→DEÖ345889003☺")
56
+ it 'removes special chars' do
57
+ expect(described_class.normalize('DE.345-889_00:3,;')).to eql('DE345889003')
58
+ expect(described_class.normalize("→ DE·Ö34588 9003\0 ☺")).to eql(
59
+ RUBY_ENGINE == 'truffleruby' ? 'DEÖ345889003' : '→DEÖ345889003☺'
60
+ )
54
61
  end
55
62
  end
56
63
 
57
- describe "#vat_country_to_iso_country" do
64
+ describe '#vat_country_to_iso_country' do
58
65
  it "returns iso country code on greek iso language 'EL'" do
59
- expect(Valvat::Utils.vat_country_to_iso_country("EL")).to eql("GR")
66
+ expect(described_class.vat_country_to_iso_country('EL')).to eql('GR')
67
+ end
68
+
69
+ it "returns iso country code on northern ireland vat prefix 'XI'" do
70
+ expect(described_class.vat_country_to_iso_country('XI')).to eql('GB')
60
71
  end
61
72
 
62
73
  Valvat::Utils::EU_MEMBER_STATES.each do |iso|
63
74
  it "returns unchanged iso country code '#{iso}'" do
64
- expect(Valvat::Utils.vat_country_to_iso_country(iso)).to eql(iso)
75
+ expect(described_class.vat_country_to_iso_country(iso)).to eql(iso)
65
76
  end
66
77
  end
67
78
  end
68
79
 
69
- describe "#iso_country_to_vat_country" do
70
- it "returns VAT country on greek iso country code 'GR'" do
71
- expect(Valvat::Utils.iso_country_to_vat_country("GR")).to eql("EL")
80
+ describe '#iso_country_to_vat_country' do
81
+ it "returns VAT country EL on greek iso country code 'GR'" do
82
+ expect(described_class.iso_country_to_vat_country('GR')).to eql('EL')
83
+ end
84
+
85
+ it "returns VAT country XI on british iso country code 'GB'" do
86
+ expect(described_class.iso_country_to_vat_country('GB')).to eql('XI')
72
87
  end
73
88
 
74
89
  Valvat::Utils::EU_MEMBER_STATES.each do |c|
90
+ next if c == 'GR'
91
+
75
92
  it "returns unchanged VAT country code '#{c}'" do
76
- expect(Valvat::Utils.iso_country_to_vat_country(c)).to eql(c)
77
- end unless c == "GR"
93
+ expect(described_class.iso_country_to_vat_country(c)).to eql(c)
94
+ end
78
95
  end
79
96
  end
80
97
 
81
- describe "#country_is_supported?" do
98
+ describe '#country_is_supported?' do
82
99
  Valvat::Utils::EU_MEMBER_STATES.each do |code|
83
100
  it "returns true on #{code}" do
84
- expect(Valvat::Utils.country_is_supported?(code)).to eql(true)
101
+ expect(described_class.country_is_supported?(code)).to be(true)
85
102
  end
86
103
  end
87
104
 
88
- it "returns true on GB" do
89
- expect(Valvat::Utils.country_is_supported?("GB")).to eql(true)
105
+ it 'returns true on GB' do
106
+ expect(described_class.country_is_supported?('GB')).to be(true)
90
107
  end
91
108
 
92
- ["US", "AE", "CA", "CN", "BR", "AU", "NO", "ML"].each do |code|
109
+ %w[US AE CA CN BR AU NO ML].each do |code|
93
110
  it "returns false on #{code}" do
94
- expect(Valvat::Utils.country_is_supported?(code)).to eql(false)
111
+ expect(described_class.country_is_supported?(code)).to be(false)
95
112
  end
96
113
  end
97
114
  end