valvat 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc72697b0c9176fc5204b1434efb9acb303e70f37ba894518a92ef964e22111b
4
- data.tar.gz: 879918277a1fdee158ae2d45d5ba12c06ed9ce2f3a61143f8ae737cb079f4f8a
3
+ metadata.gz: 51672c127e1f949767059172b89bcadfc148888809889c8cd0b425031c002132
4
+ data.tar.gz: '04189c3b112baeff2001a6f5b6bdccb0de3052e66d05636e597fb6bde175e94c'
5
5
  SHA512:
6
- metadata.gz: fd117658d26b50836714888ddc58b0a1155b380d874887af56b299226120164a7730b44cf76599f281bc51ab87dc4ce535dada233dbf2a99b62f84502b418fe0
7
- data.tar.gz: 7c452101dc8994424f4e3af668834f16e7fe1297b71f634f42e0ea4f25fe2678cafb33b154ca9d3ffa9de9b578cb20869fcb251464393f67aec98ac24543273c
6
+ metadata.gz: f330e05a5c50652036ed2b445884e202c72708d10210fd09528b3f54d54afe5de3acf59d84af4bea66aba76d0f98ee4d7464ce9c0399c80644257368b4880472
7
+ data.tar.gz: b730f20e4c950324d99111cb73add8dc833d56587554bc62fd39e6576bd6a41a914c4e68e1666a6ed1ed7bdc2b36881fc6e69b48ca30d02a76bd9e01a6e8b446
checksums.yaml.gz.sig CHANGED
Binary file
@@ -17,7 +17,7 @@ jobs:
17
17
  BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
18
18
  strategy:
19
19
  matrix:
20
- ruby-version: ['2.6', '2.7', '3.0', '3.1', 'truffleruby-head', 'jruby-9.3.2.0']
20
+ ruby-version: ['2.6', '2.7', '3.0', '3.1', 'jruby-9.3.2.0']
21
21
  gemfile: [ 'standalone', 'activemodel-5', 'activemodel-6', 'activemodel-7' ]
22
22
  exclude:
23
23
  - ruby-version: '3.0'
data/.rubocop.yml CHANGED
@@ -12,4 +12,7 @@ Style/Documentation:
12
12
  Enabled: false
13
13
 
14
14
  RSpec/MultipleExpectations:
15
+ Enabled: false
16
+
17
+ Style/StringChars:
15
18
  Enabled: false
data/CHANGES.md CHANGED
@@ -1,7 +1,15 @@
1
1
 
2
2
  ### dev
3
3
 
4
- [full changelog](http://github.com/yolk/valvat/compare/v1.1.4...master)
4
+ [full changelog](http://github.com/yolk/valvat/compare/v1.1.5...master)
5
+
6
+ ### 1.1.5 / 2022-09-14
7
+
8
+ [full changelog](http://github.com/yolk/valvat/compare/v1.1.4...v1.1.5)
9
+
10
+ * Fixed natural person VAT checksum validation for ES #114 (by [Thomas Scalise](https://github.com/KirtashW17))
11
+ * Better (ruby) code blocks in README #113
12
+ * Minor internal syntax changes / refactorings
5
13
 
6
14
  ### 1.1.4 / 2022-05-05
7
15
 
data/README.md CHANGED
@@ -20,17 +20,21 @@ Northern Ireland received its own VAT number prefix - XI which is supported by V
20
20
  * I18n locales for language specific error messages in English, German, French, Spanish, Italian, Portuguese, Polish, Swedish, Dutch, Danish, Czech, Slovakian, Hungarian, Bulgarian, Romanian, Latvian, Catalan, Norwegian, and Finnish.
21
21
  * *Experimental* checksum verification
22
22
 
23
- valvat is tested and works with ruby MRI 2.6/2.7/3.0/3.1, jruby, truffleruby-head and ActiveModel 5/6/7. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).
23
+ valvat is tested and works with ruby MRI 2.6/2.7/3.0/3.1, jruby and ActiveModel 5/6/7. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).
24
24
 
25
25
  ## Installation
26
26
 
27
27
  Add it to your Gemfile:
28
28
 
29
- gem 'valvat'
29
+ ```ruby
30
+ gem 'valvat'
31
+ ```
30
32
 
31
33
  To use less memory (~0.5 mb vs. ~3.5 mb) and load only the local verification functionality – and not the remote lookup with VIES – add it like this instead:
32
34
 
33
- gem 'valvat', require: 'valvat/local'
35
+ ```ruby
36
+ gem 'valvat', require: 'valvat/local'
37
+ ```
34
38
 
35
39
  In any case run:
36
40
 
@@ -44,25 +48,33 @@ Or install it yourself as:
44
48
 
45
49
  To verify the syntax of a vat number:
46
50
 
47
- Valvat.new("DE345789003").valid?
48
- => true or false
51
+ ```ruby
52
+ Valvat.new("DE345789003").valid?
53
+ # => true or false
54
+ ```
49
55
 
50
56
  It is also possible to bypass initializing a Valvat instance and check the syntax of a vat number string directly with:
51
57
 
52
- Valvat::Syntax.validate("DE345789003")
53
- => true or false
58
+ ```ruby
59
+ Valvat::Syntax.validate("DE345789003")
60
+ # => true or false
61
+ ```
54
62
 
55
- ## Validate agains the VIES web service
63
+ ## Validate against the VIES web service
56
64
 
57
65
  To check if the given vat number exists via the VIES web service:
58
66
 
59
- Valvat.new("DE345789003").exists?
60
- => true or false or nil
67
+ ```ruby
68
+ Valvat.new("DE345789003").exists?
69
+ # => true or false or nil
70
+ ```
61
71
 
62
72
  Or to lookup a vat number string directly via VIES web service:
63
73
 
64
- Valvat::Lookup.validate("DE345789003")
65
- => true or false or nil
74
+ ```ruby
75
+ Valvat::Lookup.validate("DE345789003")
76
+ # => true or false or nil
77
+ ```
66
78
 
67
79
  *IMPORTANT* Keep in mind that the VIES web service might be offline at some time for all or some member states. If this happens `exists?` or `Valvat::Lookup.validate` will return `nil`. See *Handling of VIES maintenance errors* for further details.
68
80
 
@@ -70,24 +82,28 @@ Or to lookup a vat number string directly via VIES web service:
70
82
 
71
83
  If you need all details and not only if the VAT is valid, pass {detail: true} as second parameter to the lookup call.
72
84
 
73
- Valvat.new("IE6388047V").exists?(detail: true)
74
- => {
75
- :country_code=>"IE", :vat_number => "6388047V", :valid => true,
76
- :request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
77
- :address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
78
- } or false or nil
85
+ ```ruby
86
+ Valvat.new("IE6388047V").exists?(detail: true)
87
+ => {
88
+ :country_code=>"IE", :vat_number => "6388047V", :valid => true,
89
+ :request_date => Date.today, :name=>"GOOGLE IRELAND LIMITED",
90
+ :address=>"1ST & 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4"
91
+ } or false or nil
92
+ ```
79
93
 
80
94
  According to EU law, or at least as Austria sees it, it's mandatory to verify the VAT number of every new customer, but also to check the VAT number periodicaly. To prove that you have checked the VAT number, the VIES Web service can return a `request_identifier`.
81
95
 
82
96
  To receive a `request_identifier` you need to pass your own VAT number in the options hash. In this example, Google (VAT IE6388047V) is checking the validity of eBays VAT number (LU21416127)
83
97
 
84
- Valvat.new("LU21416127").exists?(requester: "IE6388047V")
85
- => {
86
- :country_code=>"LU", :vat_number => "21416127", :valid => true,
87
- :request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
88
- :address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
89
- :company_type => nil, :request_identifier => "some_uniq_string"
90
- } or false or nil
98
+ ```ruby
99
+ Valvat.new("LU21416127").exists?(requester: "IE6388047V")
100
+ => {
101
+ :country_code=>"LU", :vat_number => "21416127", :valid => true,
102
+ :request_date => Date.today, :name=>"EBAY EUROPE S.A R.L.",
103
+ :address => "22, BOULEVARD ROYAL\nL-2449 LUXEMBOURG",
104
+ :company_type => nil, :request_identifier => "some_uniq_string"
105
+ } or false or nil
106
+ ```
91
107
 
92
108
  If the given `requester` is invalid, a `Valvat::InvalidRequester` error is thrown.
93
109
 
@@ -95,7 +111,9 @@ If the given `requester` is invalid, a `Valvat::InvalidRequester` error is throw
95
111
 
96
112
  From time to time the VIES web service for one or all member states is down for maintenance. To handle this kind of temporary errors, `Valvat::Lookup#validate` returns `nil` by default to indicate that there is no way at the moment to say if the given VAT is valid or not. You should revalidate the VAT later. If you prefer an error, use the `raise_error` option:
97
113
 
98
- Valvat.new("IE6388047V").exists?(raise_error: true)
114
+ ```ruby
115
+ Valvat.new("IE6388047V").exists?(raise_error: true)
116
+ ```
99
117
 
100
118
  This raises `Valvat::ServiceUnavailable` or `Valvat::MemberStateUnavailable` instead of returning `nil`.
101
119
 
@@ -113,7 +131,9 @@ All other errors accuring while validating against the VIES web service are rais
113
131
 
114
132
  If you want to suppress all known error cases. Pass in the `raise_error` option set to `false`:
115
133
 
116
- Valvat.new("IE6388047V").exists?(raise_error: false)
134
+ ```ruby
135
+ Valvat.new("IE6388047V").exists?(raise_error: false)
136
+ ```
117
137
 
118
138
  This will return `nil` instead of raising a known error.
119
139
 
@@ -121,11 +141,15 @@ This will return `nil` instead of raising a known error.
121
141
 
122
142
  Use the `:savon` key to set options for the used savon SOAP client. For example to log all requests:
123
143
 
124
- Valvat.new("IE6388047V").exists?(savon: {log: true})
144
+ ```ruby
145
+ Valvat.new("IE6388047V").exists?(savon: { log: true })
146
+ ```
125
147
 
126
148
  Or to use higher timeouts for the requests:
127
149
 
128
- Valvat.new("IE6388047V").exists?(savon: {open_timeout: 10, read_timeout: 10})
150
+ ```ruby
151
+ Valvat.new("IE6388047V").exists?(savon: {open_timeout: 10, read_timeout: 10})
152
+ ```
129
153
 
130
154
  ### Skip local validation before lookup
131
155
 
@@ -135,8 +159,10 @@ To prevent unnecessary requests, valvat performs a local syntax check before mak
135
159
 
136
160
  valvat allows to check vat numbers from AT, BE, BG, DE, DK, ES, FR, FI, GR, IE, IT, LU, NL, PL, PT, SE and SI against a checksum calculation. All other member states will fall back to a basic syntax check:
137
161
 
138
- Valvat.new("DE345789003").valid_checksum?
139
- => true or false
162
+ ```ruby
163
+ Valvat.new("DE345789003").valid_checksum?
164
+ # => true or false
165
+ ```
140
166
 
141
167
  These results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES.
142
168
 
@@ -144,8 +170,10 @@ These results are more valuable than a simple syntax check, but keep in mind: th
144
170
 
145
171
  To bypass initializing a Valvat instance:
146
172
 
147
- Valvat::Checksum.validate("DE345789003")
148
- => true or false
173
+ ```ruby
174
+ Valvat::Checksum.validate("DE345789003")
175
+ # => true or false
176
+ ```
149
177
 
150
178
  ## Usage with ActiveModel / Rails
151
179
 
@@ -153,7 +181,9 @@ To bypass initializing a Valvat instance:
153
181
 
154
182
  When the valvat gem is required and ActiveModel is already loaded, everything will work fine out of the box. If your load order differs just add
155
183
 
156
- require 'active_model/validations/valvat_validator'
184
+ ```ruby
185
+ require 'active_model/validations/valvat_validator'
186
+ ```
157
187
 
158
188
  after ActiveModel has been loaded.
159
189
 
@@ -161,35 +191,47 @@ after ActiveModel has been loaded.
161
191
 
162
192
  To validate the attribute `vat_number` add this to your model:
163
193
 
164
- class MyModel < ActiveRecord::Base
165
- validates :vat_number, valvat: true
166
- end
194
+ ```ruby
195
+ class MyModel < ActiveRecord::Base
196
+ validates :vat_number, valvat: true
197
+ end
198
+ ```
167
199
 
168
200
  ### Additional lookup validation
169
201
 
170
202
  To additionally perform a lookup via VIES:
171
203
 
172
- validates :vat_number, valvat: {lookup: true}
204
+ ```ruby
205
+ validates :vat_number, valvat: { lookup: true }
206
+ ```
173
207
 
174
208
  By default this will validate to true if the VIES web service is down. To fail in this case simply add the `:fail_if_down` option:
175
209
 
176
- validates :vat_number, valvat: {lookup: {fail_if_down: true}}
210
+ ```ruby
211
+ validates :vat_number, valvat: { lookup: { fail_if_down: true } }
212
+ ```
177
213
 
178
214
  You can pass in any options accepted by `Valvat::Lookup#validate`:
179
215
 
180
- validates :vat_number, valvat: {lookup: {raise_error: true, savon: {log: true}}}
216
+ ```ruby
217
+ validates :vat_number, valvat: { lookup: { raise_error: true, savon: { log: true } } }
218
+ ```
181
219
 
182
220
  ### Additional (and experimental) checksum validation
183
221
 
184
222
  To additionally perform a checksum validation:
185
223
 
186
- validates :vat_number, valvat: {checksum: true}
224
+ ```ruby
225
+ validates :vat_number, valvat: { checksum: true }
226
+ ```
187
227
 
188
228
  ### Additional ISO country code validation
189
229
 
190
230
  If you want the vat number’s (ISO) country to match another country attribute, use the _match_country_ option:
191
231
 
192
- validates :vat_number, valvat: {match_country: :country}
232
+ ```ruby
233
+ validates :vat_number, valvat: { match_country: :country }
234
+ ```
193
235
 
194
236
  where it is supposed that your model has a method named _country_ which returns the country ISO code you want to match.
195
237
 
@@ -197,48 +239,62 @@ where it is supposed that your model has a method named _country_ which returns
197
239
 
198
240
  By default blank vat numbers validate to false. To change this add the `:allow_blank` option:
199
241
 
200
- validates :vat_number, valvat: {allow_blank: true}
242
+ ```ruby
243
+ validates :vat_number, valvat: { allow_blank: true }
244
+ ```
201
245
 
202
246
  ### Allow vat numbers outside of europe
203
247
 
204
248
  To allow vat numbers from outside of europe, add something like this to your model (country_code should return a upcase ISO country code):
205
249
 
206
- class MyModel < ActiveRecord::Base
207
- validates :vat_number, valvat: true, if: :eu?
250
+ ```ruby
251
+ class MyModel < ActiveRecord::Base
252
+ validates :vat_number, valvat: true, if: :eu?
208
253
 
209
- def eu?
210
- Valvat::Utils::EU_MEMBER_STATES.include?(country_code)
211
- end
212
- end
254
+ def eu?
255
+ Valvat::Utils::EU_MEMBER_STATES.include?(country_code)
256
+ end
257
+ end
258
+ ```
213
259
 
214
260
  ## Utilities
215
261
 
216
262
  To split a vat number into the country code and the remaining chars:
217
263
 
218
- Valvat::Utils.split("ATU345789003")
219
- => ["AT", "U345789003"]
264
+ ```ruby
265
+ Valvat::Utils.split("ATU345789003")
266
+ # => ["AT", "U345789003"]
267
+ ```
220
268
 
221
269
  or
222
270
 
223
- Valvat.new("ATU345789003").to_a
224
- => ["AT", "U345789003"]
271
+ ```ruby
272
+ Valvat.new("ATU345789003").to_a
273
+ # => ["AT", "U345789003"]
274
+ ```
225
275
 
226
276
  Both methods always return an array. If it can not detect the country or the given country is located outside of europe it returns `[nil, nil]`. Please note that this does not strictly return the ISO country code: for greek vat numbers this returns the ISO language code 'EL' instead of the ISO country code 'GR'.
227
277
 
228
278
  To extract the ISO country code of a given vat number:
229
279
 
230
- Valvat.new("EL7345789003").iso_country_code
231
- => "GR"
280
+ ```ruby
281
+ Valvat.new("EL7345789003").iso_country_code
282
+ # => "GR"
283
+ ```
232
284
 
233
285
  To extract the vat country code (first two chars in every european vat number):
234
286
 
235
- Valvat.new("EL7345789003").vat_country_code
236
- => "EL"
287
+ ```ruby
288
+ Valvat.new("EL7345789003").vat_country_code
289
+ # => "EL"
290
+ ```
237
291
 
238
292
  To normalize a vat number:
239
293
 
240
- Valvat::Utils.normalize("atu345789003")
241
- => "ATU345789003"
294
+ ```ruby
295
+ Valvat::Utils.normalize("atu345789003")
296
+ # => "ATU345789003"
297
+ ```
242
298
 
243
299
  This basically just removes trailing spaces and ensures all chars are uppercase.
244
300
 
@@ -3,5 +3,8 @@ source "https://rubygems.org"
3
3
  gem "activemodel", "~> 6.0"
4
4
 
5
5
  gem 'rack'
6
+ gem 'net-smtp', require: false
7
+ gem 'net-imap', require: false
8
+ gem 'net-pop', require: false
6
9
 
7
10
  gemspec path: "../"
@@ -3,5 +3,8 @@ source "https://rubygems.org"
3
3
  gem "activemodel", "~> 7.0"
4
4
 
5
5
  gem 'rack'
6
+ gem 'net-smtp', require: false
7
+ gem 'net-imap', require: false
8
+ gem 'net-pop', require: false
6
9
 
7
10
  gemspec path: "../"
data/gemfiles/standalone CHANGED
@@ -1,5 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem 'rack', '< 2'
4
+ gem 'net-smtp', require: false
5
+ gem 'net-imap', require: false
6
+ gem 'net-pop', require: false
4
7
 
5
8
  gemspec path: "../"
@@ -74,7 +74,7 @@ module ActiveModel
74
74
  message: options[:message],
75
75
  country_adjective: I18n.translate(
76
76
  :"valvat.country_adjectives.#{iso_country_code.downcase}",
77
- default: [:"valvat.country_adjectives.eu", 'european']
77
+ default: [:'valvat.country_adjectives.eu', 'european']
78
78
  ))
79
79
  end
80
80
 
@@ -4,7 +4,7 @@ class Valvat
4
4
  module Checksum
5
5
  class ES < Base
6
6
  NATURAL_PERSON_CHARS = %w[T R W A G M Y F P D X B N J Z S Q V H L C K E].freeze
7
- NATURAL_PERSON_EXP = /\A(\d{8}[ABCDEFGHJKLMNPQRSTVWXYZ]|[KLMXYZ]\d{7}[ABCDEFGHJKLMNPQRSTVWXYZ])\Z/.freeze
7
+ NATURAL_PERSON_EXP = /\A([KLMXYZ\d])/.freeze
8
8
  LEGAL_PERSON_CHARS = [false] + %w[A B C D E F G H I J]
9
9
  LEGAL_PERSON_EXP = /\A[NPQRSW]\d{7}[ABCDEFGHIJ]\Z/.freeze
10
10
  NIE_DIGIT_BY_LETTER = %w[X Y Z].freeze
@@ -5,7 +5,7 @@ class Valvat
5
5
  class FR < Base
6
6
  def check_digit
7
7
  siren = str_wo_country[2..-1].to_i
8
- (12 + (3 * siren) % 97) % 97
8
+ (12 + ((3 * siren) % 97)) % 97
9
9
  end
10
10
 
11
11
  def given_check_digit
@@ -13,7 +13,7 @@ class Valvat
13
13
  product = (2 * sum) % 11
14
14
  end
15
15
 
16
- (10 - (product - 1) % 10) % 10
16
+ (10 - ((product - 1) % 10)) % 10
17
17
  end
18
18
  end
19
19
  end
@@ -10,7 +10,7 @@ class Valvat
10
10
  digit * multipliers[index]
11
11
  end
12
12
 
13
- (10 - sum % 10) % 10
13
+ (10 - (sum % 10)) % 10
14
14
  end
15
15
  end
16
16
  end
@@ -5,20 +5,13 @@ class Valvat
5
5
  class Fault < Response
6
6
  def to_hash
7
7
  @to_hash ||= case @raw
8
- when Savon::HTTPError
9
- { error: HTTPError.new(nil, @raw) }
10
- when Savon::UnknownOperationError
11
- { error: OperationUnknown.new(nil, @raw) }
12
- else
13
- fault = @raw.to_hash[:fault][:faultstring]
14
-
15
- if fault == 'INVALID_INPUT'
16
- { valid: false }
17
- else
18
- error = (FAULTS[fault] || UnknownViesError).new(fault)
19
- { error: error }
20
- end
21
- end
8
+ when Savon::HTTPError
9
+ { error: HTTPError.new(nil, @raw) }
10
+ when Savon::UnknownOperationError
11
+ { error: OperationUnknown.new(nil, @raw) }
12
+ else
13
+ soap_fault
14
+ end
22
15
  end
23
16
 
24
17
  FAULTS = {
@@ -33,6 +26,19 @@ class Valvat
33
26
  'MS_MAX_CONCURRENT_REQ' => RateLimitError,
34
27
  'MS_MAX_CONCURRENT_REQ_TIME' => RateLimitError
35
28
  }.freeze
29
+
30
+ private
31
+
32
+ def soap_fault
33
+ fault = @raw.to_hash[:fault][:faultstring]
34
+
35
+ if fault == 'INVALID_INPUT'
36
+ { valid: false }
37
+ else
38
+ error = (FAULTS[fault] || UnknownViesError).new(fault)
39
+ { error: error }
40
+ end
41
+ end
36
42
  end
37
43
  end
38
44
  end
@@ -19,7 +19,7 @@ class Valvat
19
19
  (
20
20
  hash[:check_vat_approx_response] || hash[:check_vat_response] || {}
21
21
  ).each_with_object({}) do |(key, value), result|
22
- result[cleanup_key(key)] = cleanup_value(value) unless key == :"@xmlns"
22
+ result[cleanup_key(key)] = cleanup_value(value) unless key == :@xmlns
23
23
  end
24
24
  end
25
25
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Valvat
4
- VERSION = '1.1.4'
4
+ VERSION = '1.1.5'
5
5
  end
@@ -15,4 +15,11 @@ describe Valvat::Checksum::ES do
15
15
  expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
16
16
  end
17
17
  end
18
+
19
+ describe 'if starts with [KLMXYZ\\d], is always a natural person' do
20
+ invalid_vat = 'ESX65474207'
21
+ it "returns false on invalid VAT #{invalid_vat}" do
22
+ expect(Valvat::Checksum.validate(invalid_vat)).to be(false)
23
+ end
24
+ end
18
25
  end
@@ -19,12 +19,12 @@ describe Valvat::Lookup::Request do
19
19
 
20
20
  context 'when Savon::UnknownOperationError is (wrongly) thrown' do
21
21
  before do
22
- dbl = double(Savon::Client)
22
+ dbl = instance_double(Savon::Client)
23
23
  allow(Savon::Client).to receive(:new).and_return(dbl)
24
24
  allow(dbl).to receive(:call).and_raise(Savon::UnknownOperationError.new('from stub'))
25
25
  end
26
26
 
27
- it "does handle it like vies down" do
27
+ it 'does handle it like vies down' do
28
28
  response = described_class.new('IE6388047V', {}).perform
29
29
  expect(response.to_hash[:error]).to be_a(Valvat::OperationUnknown)
30
30
  end
@@ -36,6 +36,7 @@ describe Valvat::Lookup do
36
36
  context 'with details' do
37
37
  let(:details) do
38
38
  {
39
+ '@xmlns:ns2': 'urn:ec.europa.eu:taxud:vies:services:checkVat:types',
39
40
  country_code: 'IE',
40
41
  vat_number: '6388047V',
41
42
  name: 'GOOGLE IRELAND LIMITED',
@@ -64,6 +65,7 @@ describe Valvat::Lookup do
64
65
  let(:response) { described_class.validate('IE6388047V', requester: 'IE6388047V') }
65
66
  let(:details) do
66
67
  {
68
+ '@xmlns:ns2': 'urn:ec.europa.eu:taxud:vies:services:checkVat:types',
67
69
  country_code: 'IE',
68
70
  vat_number: '6388047V',
69
71
  name: 'GOOGLE IRELAND LIMITED',
@@ -132,7 +134,7 @@ describe Valvat::Lookup do
132
134
  subject(:result) { described_class.validate('DE300', options) }
133
135
 
134
136
  it 'returns nil' do
135
- expect(result).to be(nil)
137
+ expect(result).to be_nil
136
138
  end
137
139
 
138
140
  it 'raises error with raise_error: true' do
@@ -146,7 +148,7 @@ describe Valvat::Lookup do
146
148
  subject(:result) { described_class.validate('DE301', options) }
147
149
 
148
150
  it 'returns nil' do
149
- expect(result).to be(nil)
151
+ expect(result).to be_nil
150
152
  end
151
153
 
152
154
  it 'raises error with raise_error: true' do
@@ -164,7 +166,7 @@ describe Valvat::Lookup do
164
166
  end
165
167
 
166
168
  it 'returns nil with raise_error set to false' do
167
- expect(described_class.validate('DE302', options.merge(raise_error: false))).to be(nil)
169
+ expect(described_class.validate('DE302', options.merge(raise_error: false))).to be_nil
168
170
  end
169
171
  end
170
172
 
@@ -176,7 +178,7 @@ describe Valvat::Lookup do
176
178
  end
177
179
 
178
180
  it 'returns nil with raise_error set to false' do
179
- expect(described_class.validate('DE400', options.merge(raise_error: false))).to be(nil)
181
+ expect(described_class.validate('DE400', options.merge(raise_error: false))).to be_nil
180
182
  end
181
183
  end
182
184
 
@@ -188,7 +190,7 @@ describe Valvat::Lookup do
188
190
  end
189
191
 
190
192
  it 'returns nil with raise_error set to false' do
191
- expect(described_class.validate('DE401', options.merge(raise_error: false))).to be(nil)
193
+ expect(described_class.validate('DE401', options.merge(raise_error: false))).to be_nil
192
194
  end
193
195
  end
194
196
 
@@ -200,7 +202,7 @@ describe Valvat::Lookup do
200
202
  end
201
203
 
202
204
  it 'returns nil with raise_error set to false' do
203
- expect(described_class.validate('DE500', options.merge(raise_error: false))).to be(nil)
205
+ expect(described_class.validate('DE500', options.merge(raise_error: false))).to be_nil
204
206
  end
205
207
  end
206
208
 
@@ -212,7 +214,7 @@ describe Valvat::Lookup do
212
214
  end
213
215
 
214
216
  it 'returns nil with raise_error set to false' do
215
- expect(described_class.validate('DE501', options.merge(raise_error: false))).to be(nil)
217
+ expect(described_class.validate('DE501', options.merge(raise_error: false))).to be_nil
216
218
  end
217
219
  end
218
220
 
@@ -224,7 +226,7 @@ describe Valvat::Lookup do
224
226
  end
225
227
 
226
228
  it 'returns nil with raise_error set to false' do
227
- expect(described_class.validate('DE600', options.merge(raise_error: false))).to be(nil)
229
+ expect(described_class.validate('DE600', options.merge(raise_error: false))).to be_nil
228
230
  end
229
231
  end
230
232
 
@@ -236,41 +238,43 @@ describe Valvat::Lookup do
236
238
  end
237
239
 
238
240
  it 'returns nil with raise_error set to false' do
239
- expect(described_class.validate('DE601', options.merge(raise_error: false))).to be(nil)
241
+ expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
240
242
  end
241
243
  end
242
244
 
243
245
  describe 'Error : Savon::UnknownOperationError' do
246
+ subject(:result) { described_class.validate('DE601', options) }
247
+
244
248
  before do
245
- dbl = double(Savon::Client)
249
+ dbl = instance_double(Savon::Client)
246
250
  allow(Savon::Client).to receive(:new).and_return(dbl)
247
251
  allow(dbl).to receive(:call).and_raise(Savon::UnknownOperationError.new('from stub'))
248
252
  end
249
- subject(:result) { described_class.validate('DE601', options) }
250
253
 
251
254
  it 'raises error' do
252
255
  expect { result }.to raise_error(Valvat::OperationUnknown, /#<Savon::UnknownOperationError: from stub>/)
253
256
  end
254
257
 
255
258
  it 'returns nil with raise_error set to false' do
256
- expect(described_class.validate('DE601', options.merge(raise_error: false))).to be(nil)
259
+ expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
257
260
  end
258
261
  end
259
262
 
260
263
  describe 'Error : Savon::HTTPError' do
264
+ subject(:result) { described_class.validate('DE601', options) }
265
+
261
266
  before do
262
- dbl = double(Savon::Client)
267
+ dbl = instance_double(Savon::Client)
263
268
  allow(Savon::Client).to receive(:new).and_return(dbl)
264
269
  allow(dbl).to receive(:call).and_raise(Savon::HTTPError.new(Struct.new(:code, :body).new(403, 'from stub')))
265
270
  end
266
- subject(:result) { described_class.validate('DE601', options) }
267
271
 
268
272
  it 'raises error' do
269
273
  expect { result }.to raise_error(Valvat::HTTPError, /#<Savon::HTTPError: HTTP error \(403\): from stub>/)
270
274
  end
271
275
 
272
276
  it 'returns nil with raise_error set to false' do
273
- expect(described_class.validate('DE601', options.merge(raise_error: false))).to be(nil)
277
+ expect(described_class.validate('DE601', options.merge(raise_error: false))).to be_nil
274
278
  end
275
279
  end
276
280
  end
@@ -56,7 +56,7 @@ describe Valvat::Utils do
56
56
  it 'removes special chars' do
57
57
  expect(described_class.normalize('DE.345-889_00:3,;')).to eql('DE345889003')
58
58
  expect(described_class.normalize("→ DE·Ö34588 9003\0 ☺")).to eql(
59
- RUBY_ENGINE == 'truffleruby' ? 'DEÖ345889003' : '→DEÖ345889003☺'
59
+ '→DEÖ345889003☺'
60
60
  )
61
61
  end
62
62
  end
data/spec/valvat_spec.rb CHANGED
@@ -171,15 +171,15 @@ describe Valvat do
171
171
 
172
172
  describe '#iso_country_code' do
173
173
  it 'returns nil' do
174
- expect(us_vat.iso_country_code).to be(nil)
175
- expect(ch_vat.iso_country_code).to be(nil)
174
+ expect(us_vat.iso_country_code).to be_nil
175
+ expect(ch_vat.iso_country_code).to be_nil
176
176
  end
177
177
  end
178
178
 
179
179
  describe '#vat_country_code' do
180
180
  it 'returns nil' do
181
- expect(us_vat.vat_country_code).to be(nil)
182
- expect(ch_vat.vat_country_code).to be(nil)
181
+ expect(us_vat.vat_country_code).to be_nil
182
+ expect(ch_vat.vat_country_code).to be_nil
183
183
  end
184
184
  end
185
185
 
@@ -231,19 +231,19 @@ describe Valvat do
231
231
 
232
232
  describe '#iso_country_code' do
233
233
  it 'returns nil' do
234
- expect(only_iso_vat.iso_country_code).to be(nil)
235
- expect(num_vat.iso_country_code).to be(nil)
236
- expect(empty_vat.iso_country_code).to be(nil)
237
- expect(nil_vat.iso_country_code).to be(nil)
234
+ expect(only_iso_vat.iso_country_code).to be_nil
235
+ expect(num_vat.iso_country_code).to be_nil
236
+ expect(empty_vat.iso_country_code).to be_nil
237
+ expect(nil_vat.iso_country_code).to be_nil
238
238
  end
239
239
  end
240
240
 
241
241
  describe '#vat_country_code' do
242
242
  it 'returns nil' do
243
- expect(only_iso_vat.vat_country_code).to be(nil)
244
- expect(num_vat.vat_country_code).to be(nil)
245
- expect(empty_vat.vat_country_code).to be(nil)
246
- expect(nil_vat.vat_country_code).to be(nil)
243
+ expect(only_iso_vat.vat_country_code).to be_nil
244
+ expect(num_vat.vat_country_code).to be_nil
245
+ expect(empty_vat.vat_country_code).to be_nil
246
+ expect(nil_vat.vat_country_code).to be_nil
247
247
  end
248
248
  end
249
249
 
data/valvat.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency 'activemodel', '>= 5.0'
26
26
  s.add_development_dependency 'rake'
27
27
  s.add_development_dependency 'rspec', '~> 3.0'
28
+ s.metadata['rubygems_mfa_required'] = 'true'
28
29
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valvat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Munz
@@ -35,7 +35,7 @@ cert_chain:
35
35
  BUdT7mtr41GgvWnIjaGWAldSuabxx5H+PKS5FzjNDMHThRZWuvYp/nP2RXDh4gIa
36
36
  7hV09P+XxvS96G+petG5KmC/lev8VqKu
37
37
  -----END CERTIFICATE-----
38
- date: 2022-05-05 00:00:00.000000000 Z
38
+ date: 2022-09-14 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: savon
@@ -211,7 +211,8 @@ files:
211
211
  homepage: https://github.com/yolk/valvat
212
212
  licenses:
213
213
  - MIT
214
- metadata: {}
214
+ metadata:
215
+ rubygems_mfa_required: 'true'
215
216
  post_install_message:
216
217
  rdoc_options: []
217
218
  require_paths:
metadata.gz.sig CHANGED
Binary file