valvat 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +2 -1
  5. data/.travis.yml +30 -16
  6. data/CHANGES.md +13 -0
  7. data/Gemfile +2 -3
  8. data/README.md +90 -44
  9. data/gemfiles/activemodel-3-2 +3 -4
  10. data/gemfiles/activemodel-4 +3 -4
  11. data/gemfiles/activemodel-5 +4 -5
  12. data/gemfiles/activemodel-6 +7 -0
  13. data/gemfiles/before-ruby21/activemodel-3-2 +3 -4
  14. data/gemfiles/before-ruby21/activemodel-4 +3 -4
  15. data/gemfiles/before-ruby21/standalone +3 -4
  16. data/gemfiles/standalone +3 -5
  17. data/lib/active_model/validations/valvat_validator.rb +20 -5
  18. data/lib/valvat.rb +3 -1
  19. data/lib/valvat/checksum/gb.rb +30 -13
  20. data/lib/valvat/checksum/ie.rb +1 -1
  21. data/lib/valvat/error.rb +28 -0
  22. data/lib/valvat/locales/en.yml +1 -1
  23. data/lib/valvat/lookup.rb +11 -43
  24. data/lib/valvat/lookup/fault.rb +30 -0
  25. data/lib/valvat/lookup/request.rb +33 -12
  26. data/lib/valvat/lookup/response.rb +36 -0
  27. data/lib/valvat/version.rb +1 -1
  28. data/spec/active_model/validations/valvat_validator_spec.rb +66 -66
  29. data/spec/valvat/checksum/at_spec.rb +2 -2
  30. data/spec/valvat/checksum/be_spec.rb +2 -2
  31. data/spec/valvat/checksum/bg_spec.rb +2 -2
  32. data/spec/valvat/checksum/cy_spec.rb +2 -2
  33. data/spec/valvat/checksum/de_spec.rb +2 -2
  34. data/spec/valvat/checksum/dk_spec.rb +2 -2
  35. data/spec/valvat/checksum/ee_spec.rb +2 -2
  36. data/spec/valvat/checksum/es_spec.rb +2 -2
  37. data/spec/valvat/checksum/fi_spec.rb +2 -2
  38. data/spec/valvat/checksum/fr_spec.rb +2 -2
  39. data/spec/valvat/checksum/gb_spec.rb +5 -3
  40. data/spec/valvat/checksum/gr_spec.rb +2 -2
  41. data/spec/valvat/checksum/hr_spec.rb +2 -2
  42. data/spec/valvat/checksum/hu_spec.rb +2 -2
  43. data/spec/valvat/checksum/ie_spec.rb +8 -2
  44. data/spec/valvat/checksum/it_spec.rb +4 -4
  45. data/spec/valvat/checksum/lt_spec.rb +2 -2
  46. data/spec/valvat/checksum/lu_spec.rb +2 -2
  47. data/spec/valvat/checksum/mt_spec.rb +2 -2
  48. data/spec/valvat/checksum/nl_spec.rb +2 -2
  49. data/spec/valvat/checksum/pl_spec.rb +3 -3
  50. data/spec/valvat/checksum/pt_spec.rb +2 -2
  51. data/spec/valvat/checksum/ro_spec.rb +2 -2
  52. data/spec/valvat/checksum/se_spec.rb +3 -3
  53. data/spec/valvat/checksum/si_spec.rb +4 -4
  54. data/spec/valvat/checksum_spec.rb +2 -2
  55. data/spec/valvat/lockup/fault_spec.rb +32 -0
  56. data/spec/valvat/lockup/request_spec.rb +15 -0
  57. data/spec/valvat/lockup/response_spec.rb +27 -0
  58. data/spec/valvat/lookup_spec.rb +168 -35
  59. data/spec/valvat/syntax_spec.rb +29 -29
  60. data/spec/valvat/utils_spec.rb +6 -6
  61. data/spec/valvat_spec.rb +18 -18
  62. data/valvat.gemspec +1 -0
  63. metadata +29 -6
  64. metadata.gz.sig +0 -0
  65. data/lib/valvat/lookup/request_with_id.rb +0 -31
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe Valvat::Utils do
5
5
  describe "#split" do
6
- it "returns country and rest on vat number as array" do
6
+ it "returns country and rest on VAT number as array" do
7
7
  expect(Valvat::Utils.split("DE345889003")).to eql(["DE", "345889003"])
8
8
  expect(Valvat::Utils.split("ESX4588900X")).to eql(["ES", "X4588900X"])
9
9
  end
@@ -27,18 +27,18 @@ describe Valvat::Utils do
27
27
  end
28
28
 
29
29
  describe "#normalize" do
30
- it "returns vat number with upcase chars" do
30
+ it "returns VAT number with upcase chars" do
31
31
  expect(Valvat::Utils.normalize("de345889003")).to eql("DE345889003")
32
32
  expect(Valvat::Utils.normalize("EsX4588900y")).to eql("ESX4588900Y")
33
33
  end
34
34
 
35
- it "returns trimmed vat number" do
35
+ it "returns trimmed VAT number" do
36
36
  expect(Valvat::Utils.normalize(" DE345889003")).to eql("DE345889003")
37
37
  expect(Valvat::Utils.normalize(" DE345889003 ")).to eql("DE345889003")
38
38
  expect(Valvat::Utils.normalize("DE345889003 ")).to eql("DE345889003")
39
39
  end
40
40
 
41
- it "does not change already normalized vat numbers" do
41
+ it "does not change already normalized VAT numbers" do
42
42
  expect(Valvat::Utils.normalize("DE345889003")).to eql("DE345889003")
43
43
  expect(Valvat::Utils.normalize("ESX4588900X")).to eql("ESX4588900X")
44
44
  end
@@ -67,12 +67,12 @@ describe Valvat::Utils do
67
67
  end
68
68
 
69
69
  describe "#iso_country_to_vat_country" do
70
- it "returns vat country on greek iso country code 'GR'" do
70
+ it "returns VAT country on greek iso country code 'GR'" do
71
71
  expect(Valvat::Utils.iso_country_to_vat_country("GR")).to eql("EL")
72
72
  end
73
73
 
74
74
  Valvat::Utils::EU_COUNTRIES.reject{|c| c == "GR"}.each do |c|
75
- it "returns unchanged vat country code '#{c}'" do
75
+ it "returns unchanged VAT country code '#{c}'" do
76
76
  expect(Valvat::Utils.iso_country_to_vat_country(c)).to eql(c)
77
77
  end
78
78
  end
@@ -44,7 +44,7 @@ describe Valvat do
44
44
  end
45
45
  end
46
46
 
47
- context "on european vat number" do
47
+ context "on european VAT number" do
48
48
  let(:de_vat) { Valvat.new("DE259597697") } # valid & exists
49
49
  let(:invalid_checksum) { Valvat.new("DE259597687") } # valid & invalid checksum
50
50
  let(:at_vat) { Valvat.new("ATU458890031") } # invalid
@@ -74,9 +74,9 @@ describe Valvat do
74
74
  end
75
75
 
76
76
  describe "#exist(s)?" do
77
- context "on existing vat numbers" do
77
+ context "on existing VAT numbers" do
78
78
  before do
79
- allow(Valvat::Lookup).to receive_messages(:validate => true)
79
+ allow(Valvat::Lookup).to receive_messages(validate: true)
80
80
  end
81
81
 
82
82
  it "returns true" do
@@ -87,9 +87,9 @@ describe Valvat do
87
87
  end
88
88
  end
89
89
 
90
- context "on not existing vat numbers" do
90
+ context "on not existing VAT numbers" do
91
91
  before do
92
- allow(Valvat::Lookup).to receive_messages(:validate => false)
92
+ allow(Valvat::Lookup).to receive_messages(validate: false)
93
93
  end
94
94
 
95
95
  it "returns false" do
@@ -100,8 +100,8 @@ describe Valvat do
100
100
 
101
101
  context "with options" do
102
102
  it "calls Valvat::Lookup.validate with options" do
103
- expect(Valvat::Lookup).to receive(:validate).once.with(de_vat, :detail => true, :bla => 'blupp').and_return(true)
104
- expect(de_vat.exists?(:detail => true, :bla => 'blupp')).to eql(true)
103
+ expect(Valvat::Lookup).to receive(:validate).once.with(de_vat, detail: true, bla: 'blupp').and_return(true)
104
+ expect(de_vat.exists?(detail: true, bla: 'blupp')).to eql(true)
105
105
  end
106
106
  end
107
107
  end
@@ -112,7 +112,7 @@ describe Valvat do
112
112
  expect(at_vat.iso_country_code).to eql("AT")
113
113
  end
114
114
 
115
- it "returns GR iso country code on greek vat number" do
115
+ it "returns GR iso country code on greek VAT number" do
116
116
  expect(gr_vat.iso_country_code).to eql("GR")
117
117
  end
118
118
  end
@@ -123,7 +123,7 @@ describe Valvat do
123
123
  expect(at_vat.vat_country_code).to eql("AT")
124
124
  end
125
125
 
126
- it "returns EL iso language code on greek vat number" do
126
+ it "returns EL iso language code on greek VAT number" do
127
127
  expect(gr_vat.vat_country_code).to eql("EL")
128
128
  end
129
129
  end
@@ -137,7 +137,7 @@ describe Valvat do
137
137
  end
138
138
 
139
139
  describe "#to_s" do
140
- it "returns full vat number" do
140
+ it "returns full VAT number" do
141
141
  expect(de_vat.to_s).to eql("DE259597697")
142
142
  expect(at_vat.to_s).to eql("ATU458890031")
143
143
  expect(gr_vat.to_s).to eql("EL999943280")
@@ -145,7 +145,7 @@ describe Valvat do
145
145
  end
146
146
 
147
147
  describe "#inspect" do
148
- it "returns vat number with iso country code" do
148
+ it "returns VAT number with iso country code" do
149
149
  expect(de_vat.inspect).to eql("#<Valvat DE259597697 DE>")
150
150
  expect(at_vat.inspect).to eql("#<Valvat ATU458890031 AT>")
151
151
  expect(gr_vat.inspect).to eql("#<Valvat EL999943280 GR>")
@@ -153,7 +153,7 @@ describe Valvat do
153
153
  end
154
154
 
155
155
  describe "#to_a" do
156
- it "calls Valvat::Utils.split with raw vat number and returns result" do
156
+ it "calls Valvat::Utils.split with raw VAT number and returns result" do
157
157
  de_vat # initialize
158
158
  expect(Valvat::Utils).to receive(:split).once.with("DE259597697").and_return(["a", "b"])
159
159
  expect(de_vat.to_a).to eql(["a", "b"])
@@ -161,7 +161,7 @@ describe Valvat do
161
161
  end
162
162
  end
163
163
 
164
- context "on vat number from outside of europe" do
164
+ context "on VAT number from outside of europe" do
165
165
  let(:us_vat) { Valvat.new("US345889003") }
166
166
  let(:ch_vat) { Valvat.new("CH445889003") }
167
167
 
@@ -201,14 +201,14 @@ describe Valvat do
201
201
  end
202
202
 
203
203
  describe "#to_s" do
204
- it "returns full given vat number" do
204
+ it "returns full given VAT number" do
205
205
  expect(us_vat.to_s).to eql("US345889003")
206
206
  expect(ch_vat.to_s).to eql("CH445889003")
207
207
  end
208
208
  end
209
209
 
210
210
  describe "#inspect" do
211
- it "returns vat number without iso country code" do
211
+ it "returns VAT number without iso country code" do
212
212
  expect(us_vat.inspect).to eql("#<Valvat US345889003>")
213
213
  expect(ch_vat.inspect).to eql("#<Valvat CH445889003>")
214
214
  end
@@ -216,7 +216,7 @@ describe Valvat do
216
216
 
217
217
  end
218
218
 
219
- context "on non-sense/empty vat number" do
219
+ context "on non-sense/empty VAT number" do
220
220
  let(:only_iso_vat) { Valvat.new("DE") }
221
221
  let(:num_vat) { Valvat.new("12445889003") }
222
222
  let(:empty_vat) { Valvat.new("") }
@@ -268,7 +268,7 @@ describe Valvat do
268
268
  end
269
269
 
270
270
  describe "#to_s" do
271
- it "returns full given vat number" do
271
+ it "returns full given VAT number" do
272
272
  expect(only_iso_vat.to_s).to eql("DE")
273
273
  expect(num_vat.to_s).to eql("12445889003")
274
274
  expect(empty_vat.to_s).to eql("")
@@ -277,7 +277,7 @@ describe Valvat do
277
277
  end
278
278
 
279
279
  describe "#inspect" do
280
- it "returns vat number without iso country code" do
280
+ it "returns VAT number without iso country code" do
281
281
  expect(only_iso_vat.inspect).to eql("#<Valvat DE>")
282
282
  expect(num_vat.inspect).to eql("#<Valvat 12445889003>")
283
283
  expect(empty_vat.inspect).to eql("#<Valvat >")
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency 'savon', '>= 2.3.0'
24
24
 
25
+ s.add_development_dependency 'rake'
25
26
  s.add_development_dependency 'rspec', '~> 3.0'
26
27
  s.add_development_dependency 'activemodel', '>= 3.0'
27
28
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valvat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Munz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -34,7 +34,7 @@ cert_chain:
34
34
  rAFNAD1QEGN6elQdy1MRuXwjcUhM8P8ofLDEaE225TSZvAI+XoCxW2PSsQj5cGER
35
35
  9vbf6JSKzQPa/HeBoU0s1Q==
36
36
  -----END CERTIFICATE-----
37
- date: 2020-03-19 00:00:00.000000000 Z
37
+ date: 2020-11-06 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: savon
@@ -50,6 +50,20 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 2.3.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
53
67
  - !ruby/object:Gem::Dependency
54
68
  name: rspec
55
69
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +112,7 @@ files:
98
112
  - gemfiles/activemodel-3-2
99
113
  - gemfiles/activemodel-4
100
114
  - gemfiles/activemodel-5
115
+ - gemfiles/activemodel-6
101
116
  - gemfiles/before-ruby21/activemodel-3-2
102
117
  - gemfiles/before-ruby21/activemodel-4
103
118
  - gemfiles/before-ruby21/standalone
@@ -130,6 +145,7 @@ files:
130
145
  - lib/valvat/checksum/ro.rb
131
146
  - lib/valvat/checksum/se.rb
132
147
  - lib/valvat/checksum/si.rb
148
+ - lib/valvat/error.rb
133
149
  - lib/valvat/local.rb
134
150
  - lib/valvat/locales/bg.yml
135
151
  - lib/valvat/locales/ca.yml
@@ -152,8 +168,9 @@ files:
152
168
  - lib/valvat/locales/sv.yml
153
169
  - lib/valvat/locales/tr.yml
154
170
  - lib/valvat/lookup.rb
171
+ - lib/valvat/lookup/fault.rb
155
172
  - lib/valvat/lookup/request.rb
156
- - lib/valvat/lookup/request_with_id.rb
173
+ - lib/valvat/lookup/response.rb
157
174
  - lib/valvat/syntax.rb
158
175
  - lib/valvat/utils.rb
159
176
  - lib/valvat/version.rb
@@ -185,6 +202,9 @@ files:
185
202
  - spec/valvat/checksum/se_spec.rb
186
203
  - spec/valvat/checksum/si_spec.rb
187
204
  - spec/valvat/checksum_spec.rb
205
+ - spec/valvat/lockup/fault_spec.rb
206
+ - spec/valvat/lockup/request_spec.rb
207
+ - spec/valvat/lockup/response_spec.rb
188
208
  - spec/valvat/lookup_spec.rb
189
209
  - spec/valvat/syntax_spec.rb
190
210
  - spec/valvat/utils_spec.rb
@@ -194,7 +214,7 @@ homepage: https://github.com/yolk/valvat
194
214
  licenses:
195
215
  - MIT
196
216
  metadata: {}
197
- post_install_message:
217
+ post_install_message:
198
218
  rdoc_options: []
199
219
  require_paths:
200
220
  - lib
@@ -210,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
230
  version: '0'
211
231
  requirements: []
212
232
  rubygems_version: 3.0.3
213
- signing_key:
233
+ signing_key:
214
234
  specification_version: 4
215
235
  summary: Validates european vat numbers. Standalone or as a ActiveModel validator.
216
236
  test_files:
@@ -242,6 +262,9 @@ test_files:
242
262
  - spec/valvat/checksum/se_spec.rb
243
263
  - spec/valvat/checksum/si_spec.rb
244
264
  - spec/valvat/checksum_spec.rb
265
+ - spec/valvat/lockup/fault_spec.rb
266
+ - spec/valvat/lockup/request_spec.rb
267
+ - spec/valvat/lockup/response_spec.rb
245
268
  - spec/valvat/lookup_spec.rb
246
269
  - spec/valvat/syntax_spec.rb
247
270
  - spec/valvat/utils_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,31 +0,0 @@
1
- class Valvat
2
- class Lookup
3
- class RequestWithId < Request
4
- def initialize(vat, requester_vat)
5
- @vat = vat
6
- @requester_vat = requester_vat
7
- end
8
-
9
- private
10
-
11
- def body
12
- super.merge(
13
- :requester_country_code => @requester_vat.vat_country_code,
14
- :requester_vat_number => @requester_vat.to_s_wo_country
15
- )
16
- end
17
-
18
- def message_tag
19
- :checkVatApprox
20
- end
21
-
22
- def action
23
- :check_vat_approx
24
- end
25
-
26
- def response_key
27
- :check_vat_approx_response
28
- end
29
- end
30
- end
31
- end