valvat 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -6
  3. data/lib/valvat/version.rb +1 -1
  4. data.tar.gz.sig +0 -0
  5. metadata +34 -102
  6. metadata.gz.sig +0 -0
  7. data/.editorconfig +0 -15
  8. data/.github/workflows/rubocop.yml +0 -17
  9. data/.github/workflows/specs.yml +0 -47
  10. data/.gitignore +0 -9
  11. data/.rubocop.yml +0 -24
  12. data/CHANGES.md +0 -419
  13. data/Gemfile +0 -14
  14. data/Guardfile +0 -7
  15. data/MIT-LICENSE +0 -20
  16. data/README.md +0 -350
  17. data/Rakefile +0 -10
  18. data/certs/mite.pem +0 -26
  19. data/gemfiles/activemodel-5 +0 -8
  20. data/gemfiles/activemodel-6 +0 -8
  21. data/gemfiles/activemodel-7 +0 -8
  22. data/gemfiles/standalone +0 -7
  23. data/lib/valvat/locales/bg.yml +0 -34
  24. data/lib/valvat/locales/ca.yml +0 -34
  25. data/lib/valvat/locales/cs.yml +0 -34
  26. data/lib/valvat/locales/da.yml +0 -34
  27. data/lib/valvat/locales/de.yml +0 -35
  28. data/lib/valvat/locales/en.yml +0 -35
  29. data/lib/valvat/locales/es.yml +0 -35
  30. data/lib/valvat/locales/fi.yml +0 -34
  31. data/lib/valvat/locales/fr.yml +0 -34
  32. data/lib/valvat/locales/hu.yml +0 -35
  33. data/lib/valvat/locales/it.yml +0 -34
  34. data/lib/valvat/locales/lv.yml +0 -34
  35. data/lib/valvat/locales/nb.yml +0 -34
  36. data/lib/valvat/locales/nl.yml +0 -35
  37. data/lib/valvat/locales/pl.yml +0 -35
  38. data/lib/valvat/locales/pt.yml +0 -34
  39. data/lib/valvat/locales/ro.yml +0 -34
  40. data/lib/valvat/locales/sk.yml +0 -34
  41. data/lib/valvat/locales/sv.yml +0 -34
  42. data/lib/valvat/locales/tr.yml +0 -34
  43. data/spec/active_model/validations/valvat_validator_spec.rb +0 -274
  44. data/spec/spec_helper.rb +0 -37
  45. data/spec/valvat/checksum/at_spec.rb +0 -17
  46. data/spec/valvat/checksum/be_spec.rb +0 -17
  47. data/spec/valvat/checksum/bg_spec.rb +0 -18
  48. data/spec/valvat/checksum/cy_spec.rb +0 -17
  49. data/spec/valvat/checksum/de_spec.rb +0 -17
  50. data/spec/valvat/checksum/dk_spec.rb +0 -17
  51. data/spec/valvat/checksum/ee_spec.rb +0 -17
  52. data/spec/valvat/checksum/es_spec.rb +0 -65
  53. data/spec/valvat/checksum/fi_spec.rb +0 -17
  54. data/spec/valvat/checksum/fr_spec.rb +0 -17
  55. data/spec/valvat/checksum/gb_spec.rb +0 -34
  56. data/spec/valvat/checksum/gr_spec.rb +0 -17
  57. data/spec/valvat/checksum/hr_spec.rb +0 -17
  58. data/spec/valvat/checksum/hu_spec.rb +0 -17
  59. data/spec/valvat/checksum/ie_spec.rb +0 -24
  60. data/spec/valvat/checksum/it_spec.rb +0 -25
  61. data/spec/valvat/checksum/lt_spec.rb +0 -17
  62. data/spec/valvat/checksum/lu_spec.rb +0 -17
  63. data/spec/valvat/checksum/mt_spec.rb +0 -17
  64. data/spec/valvat/checksum/nl_spec.rb +0 -17
  65. data/spec/valvat/checksum/pl_spec.rb +0 -21
  66. data/spec/valvat/checksum/pt_spec.rb +0 -30
  67. data/spec/valvat/checksum/ro_spec.rb +0 -17
  68. data/spec/valvat/checksum/se_spec.rb +0 -21
  69. data/spec/valvat/checksum/si_spec.rb +0 -25
  70. data/spec/valvat/checksum_spec.rb +0 -40
  71. data/spec/valvat/lookup/hmrc_spec.rb +0 -58
  72. data/spec/valvat/lookup/vies_spec.rb +0 -25
  73. data/spec/valvat/lookup_spec.rb +0 -493
  74. data/spec/valvat/options_spec.rb +0 -23
  75. data/spec/valvat/syntax_spec.rb +0 -68
  76. data/spec/valvat/utils_spec.rb +0 -125
  77. data/spec/valvat_spec.rb +0 -276
  78. data/valvat.gemspec +0 -24
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Valvat::Utils do
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])
15
- end
16
-
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
23
- end
24
-
25
- it 'returns EL (language iso code) on greek vat' do
26
- expect(described_class.split('EL999999999')).to eql(%w[EL 999999999])
27
- end
28
-
29
- it 'returns XI (vat number code) on northern ireland vat' do
30
- expect(described_class.split('XI999999999')).to eql(%w[XI 999999999])
31
- end
32
- end
33
-
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')
38
- end
39
-
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')
44
- end
45
-
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')
49
- end
50
-
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')
54
- end
55
-
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
- '→DEÖ345889003☺'
60
- )
61
- end
62
- end
63
-
64
- describe '#vat_country_to_iso_country' do
65
- it "returns iso country code on greek iso language 'EL'" do
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')
71
- end
72
-
73
- Valvat::Utils::EU_MEMBER_STATES.each do |iso|
74
- it "returns unchanged iso country code '#{iso}'" do
75
- expect(described_class.vat_country_to_iso_country(iso)).to eql(iso)
76
- end
77
- end
78
- end
79
-
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')
87
- end
88
-
89
- Valvat::Utils::EU_MEMBER_STATES.each do |c|
90
- next if c == 'GR'
91
-
92
- it "returns unchanged VAT country code '#{c}'" do
93
- expect(described_class.iso_country_to_vat_country(c)).to eql(c)
94
- end
95
- end
96
- end
97
-
98
- describe '#country_is_supported?' do
99
- Valvat::Utils::EU_MEMBER_STATES.each do |code|
100
- it "returns true on #{code}" do
101
- expect(described_class.country_is_supported?(code)).to be(true)
102
- end
103
- end
104
-
105
- it 'returns true on GB' do
106
- expect(described_class.country_is_supported?('GB')).to be(true)
107
- end
108
-
109
- %w[US AE CA CN BR AU NO ML].each do |code|
110
- it "returns false on #{code}" do
111
- expect(described_class.country_is_supported?(code)).to be(false)
112
- end
113
- end
114
- end
115
-
116
- describe '#deep_symbolize_keys' do
117
- it 'symbolizes keys of flat hash' do
118
- expect(described_class.deep_symbolize_keys({ 'a' => 1, :b => 2 })).to eql({ a: 1, b: 2 })
119
- end
120
-
121
- it 'symbolizes all hashes' do
122
- expect(described_class.deep_symbolize_keys({ 'a' => 1, :b => { 'c' => 3 } })).to eql({ a: 1, b: { c: 3 } })
123
- end
124
- end
125
- end
data/spec/valvat_spec.rb DELETED
@@ -1,276 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Valvat do
6
- describe '#new' do
7
- it 'demands one and only one argument' do
8
- expect { described_class.new }.to raise_error(ArgumentError)
9
- expect { described_class.new('a', 'b') }.to raise_error(ArgumentError)
10
- expect { described_class.new('a') }.not_to raise_error
11
- end
12
-
13
- it 'normalizes input string' do
14
- expect(described_class.new('de25.9597,69 7').to_s).to eql('DE259597697')
15
- expect(described_class.new('de25.9597,69 7').iso_country_code).to eql('DE')
16
- end
17
- end
18
-
19
- describe 'Valvat()' do
20
- it 'initializes new Valvat instance on string' do
21
- expect(Valvat('abc')).to be_a(described_class)
22
- end
23
-
24
- it 'returns same Valvat instance on Valvat instance' do
25
- vat = described_class.new('abc')
26
- expect(Valvat(vat)).to be_a(described_class)
27
- expect(Valvat(vat).object_id).to eql(vat.object_id)
28
- end
29
- end
30
-
31
- describe '#blank?' do
32
- it 'returns true when when initialized with nil' do
33
- expect(described_class.new(nil)).to be_blank
34
- end
35
-
36
- it 'returns true when when initialized with an empty string' do
37
- expect(described_class.new(' ')).to be_blank
38
- end
39
-
40
- it 'returns false when initialized with a value' do
41
- expect(described_class.new('DE259597697')).not_to be_blank
42
- end
43
- end
44
-
45
- describe 'object equality' do
46
- it 'returns true when the underlying number are the same' do
47
- first = 'DE259597697'
48
- second = 'DE259597697'
49
-
50
- expect(described_class.new(first)).to eql(described_class.new(second))
51
- end
52
-
53
- it 'returns true when the underlying number are the same when normalized' do
54
- first = 'DE259597697'
55
- second = 'DE 2595 9 7697 '
56
-
57
- expect(described_class.new(first)).to eql(described_class.new(second))
58
- end
59
-
60
- it 'returns false when the underlying number are different' do
61
- first = 'DE259597697'
62
- second = 'ATU458890031'
63
-
64
- expect(described_class.new(first)).not_to eql(described_class.new(second))
65
- end
66
- end
67
-
68
- context 'with european VAT number' do
69
- let(:de_vat) { described_class.new('DE259597697') } # valid & exists
70
- let(:invalid_checksum) { described_class.new('DE259597687') } # valid & invalid checksum
71
- let(:at_vat) { described_class.new('ATU458890031') } # invalid
72
- let(:gr_vat) { described_class.new('EL999943280') } # valid & exists
73
-
74
- describe '#valid?' do
75
- it 'returns true on valid numbers' do
76
- expect(de_vat).to be_valid
77
- expect(gr_vat).to be_valid
78
- end
79
-
80
- it 'returns false on invalid numbers' do
81
- expect(at_vat).not_to be_valid
82
- end
83
- end
84
-
85
- describe '#valid_checksum?' do
86
- it 'returns true on valid numbers' do
87
- expect(de_vat).to be_valid_checksum
88
- expect(gr_vat).to be_valid_checksum
89
- end
90
-
91
- it 'returns false on invalid numbers' do
92
- expect(at_vat).not_to be_valid_checksum
93
- expect(invalid_checksum).not_to be_valid_checksum
94
- end
95
- end
96
-
97
- describe '#exist(s)?' do
98
- it 'returns true with existing VAT numbers' do
99
- allow(Valvat::Lookup).to receive_messages(validate: true)
100
- expect(de_vat.exists?).to be(true)
101
- expect(gr_vat.exists?).to be(true)
102
- expect(de_vat.exist?).to be(true)
103
- expect(gr_vat.exist?).to be(true)
104
- end
105
-
106
- it 'returns false with not existing VAT numbers' do
107
- allow(Valvat::Lookup).to receive_messages(validate: false)
108
- expect(at_vat.exists?).to be(false)
109
- expect(at_vat.exist?).to be(false)
110
- end
111
-
112
- it 'calls Valvat::Lookup.validate with options' do
113
- allow(Valvat::Lookup).to receive_messages(validate: true)
114
- expect(de_vat.exists?(detail: true, bla: 'blupp')).to be(true)
115
- expect(Valvat::Lookup).to have_received(:validate).once.with(
116
- de_vat, detail: true, bla: 'blupp'
117
- )
118
- end
119
- end
120
-
121
- describe '#iso_country_code' do
122
- it 'returns iso country code on iso_country_code' do
123
- expect(de_vat.iso_country_code).to eql('DE')
124
- expect(at_vat.iso_country_code).to eql('AT')
125
- end
126
-
127
- it 'returns GR iso country code on greek VAT number' do
128
- expect(gr_vat.iso_country_code).to eql('GR')
129
- end
130
- end
131
-
132
- describe '#vat_country_code' do
133
- it 'returns iso country code on iso_country_code' do
134
- expect(de_vat.vat_country_code).to eql('DE')
135
- expect(at_vat.vat_country_code).to eql('AT')
136
- end
137
-
138
- it 'returns EL iso language code on greek VAT number' do
139
- expect(gr_vat.vat_country_code).to eql('EL')
140
- end
141
- end
142
-
143
- describe '#to_s' do
144
- it 'returns full VAT number' do
145
- expect(de_vat.to_s).to eql('DE259597697')
146
- expect(at_vat.to_s).to eql('ATU458890031')
147
- expect(gr_vat.to_s).to eql('EL999943280')
148
- end
149
- end
150
-
151
- describe '#inspect' do
152
- it 'returns VAT number with iso country code' do
153
- expect(de_vat.inspect).to eql('#<Valvat DE259597697 DE>')
154
- expect(at_vat.inspect).to eql('#<Valvat ATU458890031 AT>')
155
- expect(gr_vat.inspect).to eql('#<Valvat EL999943280 GR>')
156
- end
157
- end
158
-
159
- describe '#to_a' do
160
- it 'calls Valvat::Utils.split with raw VAT number and returns result' do
161
- allow(Valvat::Utils).to receive(:split).and_return(%w[a b])
162
- de_vat # initialize
163
- expect(Valvat::Utils).to have_received(:split).once.with('DE259597697')
164
- expect(de_vat.to_a).to eql(%w[a b])
165
- end
166
- end
167
- end
168
-
169
- context 'with VAT number from outside of europe' do
170
- let(:us_vat) { described_class.new('US345889003') }
171
- let(:ch_vat) { described_class.new('CH445889003') }
172
-
173
- describe '#valid?' do
174
- it 'returns false' do
175
- expect(us_vat).not_to be_valid
176
- expect(ch_vat).not_to be_valid
177
- end
178
- end
179
-
180
- describe '#exist?' do
181
- it 'returns false' do
182
- expect(us_vat).not_to be_exist
183
- expect(ch_vat).not_to be_exist
184
- end
185
- end
186
-
187
- describe '#iso_country_code' do
188
- it 'returns nil' do
189
- expect(us_vat.iso_country_code).to be_nil
190
- expect(ch_vat.iso_country_code).to be_nil
191
- end
192
- end
193
-
194
- describe '#vat_country_code' do
195
- it 'returns nil' do
196
- expect(us_vat.vat_country_code).to be_nil
197
- expect(ch_vat.vat_country_code).to be_nil
198
- end
199
- end
200
-
201
- describe '#to_s' do
202
- it 'returns full given VAT number' do
203
- expect(us_vat.to_s).to eql('US345889003')
204
- expect(ch_vat.to_s).to eql('CH445889003')
205
- end
206
- end
207
-
208
- describe '#inspect' do
209
- it 'returns VAT number without iso country code' do
210
- expect(us_vat.inspect).to eql('#<Valvat US345889003>')
211
- expect(ch_vat.inspect).to eql('#<Valvat CH445889003>')
212
- end
213
- end
214
- end
215
-
216
- context 'with non-sense/empty VAT number' do
217
- let(:only_iso_vat) { described_class.new('DE') }
218
- let(:num_vat) { described_class.new('12445889003') }
219
- let(:empty_vat) { described_class.new('') }
220
- let(:nil_vat) { described_class.new('') }
221
-
222
- describe '#valid?' do
223
- it 'returns false' do
224
- expect(only_iso_vat).not_to be_valid
225
- expect(num_vat).not_to be_valid
226
- expect(empty_vat).not_to be_valid
227
- expect(nil_vat).not_to be_valid
228
- end
229
- end
230
-
231
- describe '#exist?' do
232
- it 'returns false' do
233
- expect(only_iso_vat).not_to be_exist
234
- expect(num_vat).not_to be_exist
235
- expect(empty_vat).not_to be_exist
236
- expect(nil_vat).not_to be_exist
237
- end
238
- end
239
-
240
- describe '#iso_country_code' do
241
- it 'returns nil' do
242
- expect(only_iso_vat.iso_country_code).to be_nil
243
- expect(num_vat.iso_country_code).to be_nil
244
- expect(empty_vat.iso_country_code).to be_nil
245
- expect(nil_vat.iso_country_code).to be_nil
246
- end
247
- end
248
-
249
- describe '#vat_country_code' do
250
- it 'returns nil' do
251
- expect(only_iso_vat.vat_country_code).to be_nil
252
- expect(num_vat.vat_country_code).to be_nil
253
- expect(empty_vat.vat_country_code).to be_nil
254
- expect(nil_vat.vat_country_code).to be_nil
255
- end
256
- end
257
-
258
- describe '#to_s' do
259
- it 'returns full given VAT number' do
260
- expect(only_iso_vat.to_s).to eql('DE')
261
- expect(num_vat.to_s).to eql('12445889003')
262
- expect(empty_vat.to_s).to eql('')
263
- expect(nil_vat.to_s).to eql('')
264
- end
265
- end
266
-
267
- describe '#inspect' do
268
- it 'returns VAT number without iso country code' do
269
- expect(only_iso_vat.inspect).to eql('#<Valvat DE>')
270
- expect(num_vat.inspect).to eql('#<Valvat 12445889003>')
271
- expect(empty_vat.inspect).to eql('#<Valvat >')
272
- expect(nil_vat.inspect).to eql('#<Valvat >')
273
- end
274
- end
275
- end
276
- end
data/valvat.gemspec DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.push File.expand_path('lib', __dir__)
4
- require 'valvat/version'
5
-
6
- Gem::Specification.new do |s|
7
- s.name = 'valvat'
8
- s.version = Valvat::VERSION
9
- s.platform = Gem::Platform::RUBY
10
- s.license = 'MIT'
11
- s.authors = ['Sebastian Munz']
12
- s.email = ['sebastian@mite.de']
13
- s.homepage = 'https://github.com/yolk/valvat'
14
- s.summary = 'Validates european vat numbers. Standalone or as a ActiveModel validator.'
15
- s.description = 'Validates european vat numbers. Standalone or as a ActiveModel validator.'
16
- s.files = `git ls-files`.split("\n")
17
- s.require_paths = ['lib']
18
- s.cert_chain = ['certs/mite.pem']
19
- s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
20
- s.metadata['rubygems_mfa_required'] = 'true'
21
- s.required_ruby_version = '>= 2.6.0'
22
-
23
- s.add_runtime_dependency('rexml', '>= 3.2', '< 4.0')
24
- end