ibandit 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -3
- data/README.md +3 -0
- data/bin/build_structure_file.rb +41 -5
- data/data/raw/structure_additions.yml +43 -0
- data/data/structures.yml +157 -0
- data/ibandit.gemspec +1 -1
- data/lib/ibandit/iban.rb +147 -60
- data/lib/ibandit/iban_assembler.rb +117 -0
- data/lib/ibandit/iban_splitter.rb +66 -0
- data/lib/ibandit/local_details_cleaner.rb +298 -0
- data/lib/ibandit/version.rb +1 -1
- data/lib/ibandit.rb +9 -1
- data/spec/ibandit/iban_assembler_spec.rb +567 -0
- data/spec/ibandit/iban_spec.rb +294 -13
- data/spec/ibandit/iban_splitter_spec.rb +41 -0
- data/spec/ibandit/local_details_cleaner_spec.rb +688 -0
- metadata +10 -6
- data/lib/ibandit/iban_builder.rb +0 -539
- data/spec/ibandit/iban_builder_spec.rb +0 -892
data/spec/ibandit/iban_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ibandit::IBAN do
|
4
|
-
subject(:iban) { described_class.new(
|
4
|
+
subject(:iban) { described_class.new(arg) }
|
5
|
+
let(:arg) { iban_code }
|
5
6
|
let(:iban_code) { 'GB82WEST12345698765432' }
|
6
7
|
|
7
8
|
its(:iban) { is_expected.to eq(iban_code) }
|
@@ -12,8 +13,34 @@ describe Ibandit::IBAN do
|
|
12
13
|
end
|
13
14
|
|
14
15
|
context 'with nil' do
|
15
|
-
let(:
|
16
|
-
|
16
|
+
let(:arg) { nil }
|
17
|
+
specify { expect { iban }.to raise_error(TypeError) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with local details' do
|
21
|
+
let(:arg) do
|
22
|
+
{
|
23
|
+
country_code: 'GB',
|
24
|
+
bank_code: 'WEST',
|
25
|
+
branch_code: '123456',
|
26
|
+
account_number: '98765432'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
its(:iban) { is_expected.to eq('GB82WEST12345698765432') }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with nil local details' do
|
34
|
+
let(:arg) do
|
35
|
+
{
|
36
|
+
country_code: nil,
|
37
|
+
bank_code: nil,
|
38
|
+
branch_code: nil,
|
39
|
+
account_number: nil
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it { is_expected.to_not be_valid }
|
17
44
|
end
|
18
45
|
|
19
46
|
describe 'it decomposes the IBAN' do
|
@@ -23,19 +50,35 @@ describe Ibandit::IBAN do
|
|
23
50
|
its(:branch_code) { is_expected.to eq('123456') }
|
24
51
|
its(:account_number) { is_expected.to eq('98765432') }
|
25
52
|
its(:iban_national_id) { is_expected.to eq('WEST123456') }
|
26
|
-
its(:local_check_digits) { is_expected.to
|
53
|
+
its(:local_check_digits) { is_expected.to be_nil }
|
27
54
|
|
28
55
|
context 'when the IBAN is blank' do
|
29
56
|
let(:iban_code) { '' }
|
30
57
|
|
31
|
-
its(:country_code) { is_expected.to
|
32
|
-
its(:check_digits) { is_expected.to
|
33
|
-
its(:bank_code) { is_expected.to
|
34
|
-
its(:branch_code) { is_expected.to
|
35
|
-
its(:account_number) { is_expected.to
|
36
|
-
its(:iban_national_id) { is_expected.to
|
37
|
-
its(:bban) { is_expected.to
|
38
|
-
its(:local_check_digits) { is_expected.to
|
58
|
+
its(:country_code) { is_expected.to be_nil }
|
59
|
+
its(:check_digits) { is_expected.to be_nil }
|
60
|
+
its(:bank_code) { is_expected.to be_nil }
|
61
|
+
its(:branch_code) { is_expected.to be_nil }
|
62
|
+
its(:account_number) { is_expected.to be_nil }
|
63
|
+
its(:iban_national_id) { is_expected.to be_nil }
|
64
|
+
its(:bban) { is_expected.to be_nil }
|
65
|
+
its(:local_check_digits) { is_expected.to be_nil }
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when the IBAN was created with local details' do
|
69
|
+
let(:arg) do
|
70
|
+
{
|
71
|
+
country_code: 'GB',
|
72
|
+
bank_code: 'WES',
|
73
|
+
branch_code: '1234',
|
74
|
+
account_number: '5678'
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
its(:country_code) { is_expected.to eq(arg[:country_code]) }
|
79
|
+
its(:bank_code) { is_expected.to eq(arg[:bank_code]) }
|
80
|
+
its(:branch_code) { is_expected.to eq(arg[:branch_code]) }
|
81
|
+
its(:account_number) { is_expected.to eq(arg[:account_number]) }
|
39
82
|
end
|
40
83
|
end
|
41
84
|
|
@@ -48,6 +91,12 @@ describe Ibandit::IBAN do
|
|
48
91
|
end
|
49
92
|
|
50
93
|
specify { expect { iban.to_s(:russian) }.to raise_error ArgumentError }
|
94
|
+
|
95
|
+
context 'with the IBAN is nil' do
|
96
|
+
let(:arg) { { country_code: 'GB' } }
|
97
|
+
its(:to_s) { is_expected.to_not be_nil }
|
98
|
+
specify { expect(iban.to_s(:formatted)).to be_empty }
|
99
|
+
end
|
51
100
|
end
|
52
101
|
|
53
102
|
###############
|
@@ -120,7 +169,6 @@ describe Ibandit::IBAN do
|
|
120
169
|
subject { iban.valid_length? }
|
121
170
|
|
122
171
|
context 'with valid details' do
|
123
|
-
let(:iban_code) { 'GB82WEST12345698765432' }
|
124
172
|
it { is_expected.to eq(true) }
|
125
173
|
end
|
126
174
|
|
@@ -145,6 +193,100 @@ describe Ibandit::IBAN do
|
|
145
193
|
end
|
146
194
|
end
|
147
195
|
|
196
|
+
describe '#valid_bank_code_length?' do
|
197
|
+
subject { iban.valid_bank_code_length? }
|
198
|
+
|
199
|
+
context 'with valid details' do
|
200
|
+
it { is_expected.to eq(true) }
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'with invalid details' do
|
204
|
+
before { allow(iban).to receive(:bank_code).and_return('WES') }
|
205
|
+
it { is_expected.to eq(false) }
|
206
|
+
|
207
|
+
it 'sets errors on the IBAN' do
|
208
|
+
iban.valid_bank_code_length?
|
209
|
+
expect(iban.errors).to include(:bank_code)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'with an invalid country_code' do
|
214
|
+
before { allow(iban).to receive(:country_code).and_return('AA') }
|
215
|
+
it { is_expected.to be_nil }
|
216
|
+
|
217
|
+
it 'does not set errors on the IBAN' do
|
218
|
+
iban.valid_bank_code_length?
|
219
|
+
expect(iban.errors).to_not include(:bank_code)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe '#valid_branch_code_length?' do
|
225
|
+
subject { iban.valid_branch_code_length? }
|
226
|
+
|
227
|
+
context 'with valid details' do
|
228
|
+
it { is_expected.to eq(true) }
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'with invalid details' do
|
232
|
+
before { allow(iban).to receive(:branch_code).and_return('12345') }
|
233
|
+
it { is_expected.to eq(false) }
|
234
|
+
|
235
|
+
it 'sets errors on the IBAN' do
|
236
|
+
iban.valid_branch_code_length?
|
237
|
+
expect(iban.errors).to include(:branch_code)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'without a branch code' do
|
242
|
+
before { allow(iban).to receive(:branch_code).and_return(nil) }
|
243
|
+
it { is_expected.to eq(false) }
|
244
|
+
|
245
|
+
it 'sets errors on the IBAN' do
|
246
|
+
iban.valid_branch_code_length?
|
247
|
+
expect(iban.errors).to include(:branch_code)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'with an invalid country_code' do
|
252
|
+
before { allow(iban).to receive(:country_code).and_return('AA') }
|
253
|
+
it { is_expected.to be_nil }
|
254
|
+
|
255
|
+
it 'does not set errors on the IBAN' do
|
256
|
+
iban.valid_branch_code_length?
|
257
|
+
expect(iban.errors).to_not include(:branch_code)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe '#valid_account_number_length?' do
|
263
|
+
subject { iban.valid_account_number_length? }
|
264
|
+
|
265
|
+
context 'with valid details' do
|
266
|
+
it { is_expected.to eq(true) }
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'with an invalid account_number' do
|
270
|
+
before { allow(iban).to receive(:account_number).and_return('1234567') }
|
271
|
+
it { is_expected.to eq(false) }
|
272
|
+
|
273
|
+
it 'sets errors on the IBAN' do
|
274
|
+
iban.valid_account_number_length?
|
275
|
+
expect(iban.errors).to include(:account_number)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context 'with an invalid country_code' do
|
280
|
+
before { allow(iban).to receive(:country_code).and_return('AA') }
|
281
|
+
it { is_expected.to be_nil }
|
282
|
+
|
283
|
+
it 'does not set errors on the IBAN' do
|
284
|
+
iban.valid_account_number_length?
|
285
|
+
expect(iban.errors).to_not include(:account_number)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
148
290
|
describe '#valid_characters?' do
|
149
291
|
subject { iban.valid_characters? }
|
150
292
|
|
@@ -193,6 +335,127 @@ describe Ibandit::IBAN do
|
|
193
335
|
end
|
194
336
|
end
|
195
337
|
|
338
|
+
describe '#valid_bank_code_format?' do
|
339
|
+
subject { iban.valid_bank_code_format? }
|
340
|
+
|
341
|
+
context 'GB numeric bank code' do
|
342
|
+
let(:arg) do
|
343
|
+
{
|
344
|
+
country_code: 'GB',
|
345
|
+
bank_code: '1234',
|
346
|
+
branch_code: '200000',
|
347
|
+
account_number: '55779911'
|
348
|
+
}
|
349
|
+
end
|
350
|
+
|
351
|
+
it { is_expected.to eq(false) }
|
352
|
+
|
353
|
+
it 'sets errors on the IBAN' do
|
354
|
+
iban.valid_bank_code_format?
|
355
|
+
expect(iban.errors).to include(:bank_code)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context 'with an invalid country code' do
|
360
|
+
let(:iban_code) { 'AA821234BANK121234567B' }
|
361
|
+
|
362
|
+
it { is_expected.to be_nil }
|
363
|
+
end
|
364
|
+
|
365
|
+
context 'with a wrong-length bank code' do
|
366
|
+
let(:arg) do
|
367
|
+
{
|
368
|
+
country_code: 'FR',
|
369
|
+
bank_code: '1234',
|
370
|
+
branch_code: '12345',
|
371
|
+
account_number: '123456789123'
|
372
|
+
}
|
373
|
+
end
|
374
|
+
|
375
|
+
it { is_expected.to be_nil }
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
describe '#valid_branch_code_format?' do
|
380
|
+
subject { iban.valid_branch_code_format? }
|
381
|
+
|
382
|
+
context 'IT non-numeric branch code' do
|
383
|
+
let(:arg) do
|
384
|
+
{
|
385
|
+
country_code: 'IT',
|
386
|
+
bank_code: '12345',
|
387
|
+
branch_code: 'ABCDE',
|
388
|
+
account_number: '123456789012'
|
389
|
+
}
|
390
|
+
end
|
391
|
+
|
392
|
+
it { is_expected.to eq(false) }
|
393
|
+
|
394
|
+
it 'sets errors on the IBAN' do
|
395
|
+
iban.valid_branch_code_format?
|
396
|
+
expect(iban.errors).to include(:branch_code)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context 'with an invalid country code' do
|
401
|
+
let(:iban_code) { 'AA821234BANK121234567B' }
|
402
|
+
|
403
|
+
it { is_expected.to be_nil }
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'with a wrong-length branch code' do
|
407
|
+
let(:arg) do
|
408
|
+
{
|
409
|
+
country_code: 'PT',
|
410
|
+
bank_code: '1234',
|
411
|
+
branch_code: 'ABC',
|
412
|
+
account_number: '123456789123'
|
413
|
+
}
|
414
|
+
end
|
415
|
+
|
416
|
+
it { is_expected.to be_nil }
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe '#valid_account_number_format?' do
|
421
|
+
subject { iban.valid_account_number_format? }
|
422
|
+
|
423
|
+
context 'DE non-numeric account number' do
|
424
|
+
let(:arg) do
|
425
|
+
{
|
426
|
+
country_code: 'DE',
|
427
|
+
bank_code: '12345678',
|
428
|
+
account_number: '55779911AA'
|
429
|
+
}
|
430
|
+
end
|
431
|
+
|
432
|
+
it { is_expected.to eq(false) }
|
433
|
+
|
434
|
+
it 'sets errors on the IBAN' do
|
435
|
+
iban.valid_account_number_format?
|
436
|
+
expect(iban.errors).to include(:account_number)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
context 'with an invalid country code' do
|
441
|
+
let(:iban_code) { 'AA821234BANK121234567B' }
|
442
|
+
|
443
|
+
it { is_expected.to be_nil }
|
444
|
+
end
|
445
|
+
|
446
|
+
context 'with a wrong-length account number' do
|
447
|
+
let(:arg) do
|
448
|
+
{
|
449
|
+
country_code: 'NL',
|
450
|
+
bank_code: 'ABCD',
|
451
|
+
account_number: nil
|
452
|
+
}
|
453
|
+
end
|
454
|
+
|
455
|
+
it { is_expected.to be_nil }
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
196
459
|
describe '#valid?' do
|
197
460
|
describe 'validations called' do
|
198
461
|
after { iban.valid? }
|
@@ -201,7 +464,25 @@ describe Ibandit::IBAN do
|
|
201
464
|
specify { expect(iban).to receive(:valid_characters?).at_least(1) }
|
202
465
|
specify { expect(iban).to receive(:valid_check_digits?).at_least(1) }
|
203
466
|
specify { expect(iban).to receive(:valid_length?).at_least(1) }
|
467
|
+
specify { expect(iban).to receive(:valid_bank_code_length?).at_least(1) }
|
204
468
|
specify { expect(iban).to receive(:valid_format?).at_least(1) }
|
469
|
+
specify { expect(iban).to receive(:valid_bank_code_format?).at_least(1) }
|
470
|
+
|
471
|
+
it 'validates the branch code length' do
|
472
|
+
expect(iban).to receive(:valid_branch_code_length?).at_least(1)
|
473
|
+
end
|
474
|
+
|
475
|
+
it 'validates the account number length' do
|
476
|
+
expect(iban).to receive(:valid_account_number_length?).at_least(1)
|
477
|
+
end
|
478
|
+
|
479
|
+
it 'validates the branch code format' do
|
480
|
+
expect(iban).to receive(:valid_branch_code_format?).at_least(1)
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'validates the account number format' do
|
484
|
+
expect(iban).to receive(:valid_account_number_format?).at_least(1)
|
485
|
+
end
|
205
486
|
end
|
206
487
|
|
207
488
|
context 'for a valid Albanian IBAN' do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ibandit::IBANSplitter do
|
4
|
+
subject(:split) { described_class.split(iban_code) }
|
5
|
+
|
6
|
+
context 'with a valid IBAN' do
|
7
|
+
let(:iban_code) { 'GB82WEST12345698765432' }
|
8
|
+
its([:country_code]) { is_expected.to eq('GB') }
|
9
|
+
its([:check_digits]) { is_expected.to eq('82') }
|
10
|
+
its([:bank_code]) { is_expected.to eq('WEST') }
|
11
|
+
its([:branch_code]) { is_expected.to eq('123456') }
|
12
|
+
its([:account_number]) { is_expected.to eq('98765432') }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with nil' do
|
16
|
+
let(:iban_code) { nil }
|
17
|
+
its([:country_code]) { is_expected.to eq(nil) }
|
18
|
+
its([:check_digits]) { is_expected.to eq(nil) }
|
19
|
+
its([:bank_code]) { is_expected.to eq(nil) }
|
20
|
+
its([:branch_code]) { is_expected.to eq(nil) }
|
21
|
+
its([:account_number]) { is_expected.to eq(nil) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with an empty string' do
|
25
|
+
let(:iban_code) { '' }
|
26
|
+
its([:country_code]) { is_expected.to eq(nil) }
|
27
|
+
its([:check_digits]) { is_expected.to eq(nil) }
|
28
|
+
its([:bank_code]) { is_expected.to eq(nil) }
|
29
|
+
its([:branch_code]) { is_expected.to eq(nil) }
|
30
|
+
its([:account_number]) { is_expected.to eq(nil) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with an invalid length IBAN' do
|
34
|
+
let(:iban_code) { 'MC9320052222100112233M445' }
|
35
|
+
its([:country_code]) { is_expected.to eq('MC') }
|
36
|
+
its([:check_digits]) { is_expected.to eq(nil) }
|
37
|
+
its([:bank_code]) { is_expected.to eq(nil) }
|
38
|
+
its([:branch_code]) { is_expected.to eq(nil) }
|
39
|
+
its([:account_number]) { is_expected.to eq(nil) }
|
40
|
+
end
|
41
|
+
end
|