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
@@ -1,892 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Ibandit::IBANBuilder do
|
4
|
-
shared_examples_for 'allows round trips' do |iban_code|
|
5
|
-
let(:iban) { Ibandit::IBAN.new(iban_code) }
|
6
|
-
let(:args) do
|
7
|
-
{
|
8
|
-
country_code: iban.country_code,
|
9
|
-
account_number: iban.account_number,
|
10
|
-
branch_code: iban.branch_code,
|
11
|
-
bank_code: iban.bank_code
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'successfully reconstructs the IBAN' do
|
16
|
-
expect(described_class.build(args).iban).to eq(iban.iban)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '.build' do
|
21
|
-
subject(:build) { described_class.build(args) }
|
22
|
-
let(:args) { { country_code: 'ES' } }
|
23
|
-
|
24
|
-
context 'without a country_code' do
|
25
|
-
let(:args) { { bank_code: 1 } }
|
26
|
-
|
27
|
-
it 'raises a helpful error message' do
|
28
|
-
expect { build }.to raise_error(ArgumentError, /provide a country_code/)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with an unsupported country_code' do
|
33
|
-
let(:args) { { country_code: 'FU' } }
|
34
|
-
|
35
|
-
it 'raises a helpful error message' do
|
36
|
-
expect { build }.to raise_error(Ibandit::UnsupportedCountryError)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with AT as the country_code' do
|
41
|
-
let(:args) do
|
42
|
-
{
|
43
|
-
country_code: 'AT',
|
44
|
-
account_number: '00234573201',
|
45
|
-
bank_code: '19043'
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
its(:iban) { is_expected.to eq('AT611904300234573201') }
|
50
|
-
|
51
|
-
it_behaves_like 'allows round trips', 'AT61 1904 3002 3457 3201'
|
52
|
-
|
53
|
-
context "with an account number that hasn't been zero-padded" do
|
54
|
-
before { args[:account_number] = '234573201' }
|
55
|
-
its(:iban) { is_expected.to eq('AT611904300234573201') }
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'without an account_number' do
|
59
|
-
before { args.delete(:account_number) }
|
60
|
-
|
61
|
-
it 'raises a helpful error message' do
|
62
|
-
expect { build }.
|
63
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'without an bank_code' do
|
68
|
-
before { args.delete(:bank_code) }
|
69
|
-
|
70
|
-
it 'raises a helpful error message' do
|
71
|
-
expect { build }.
|
72
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'with BE as the country_code' do
|
78
|
-
let(:args) { { country_code: 'BE', account_number: '510007547061' } }
|
79
|
-
|
80
|
-
its(:iban) { is_expected.to eq('BE62510007547061') }
|
81
|
-
|
82
|
-
it_behaves_like 'allows round trips', 'BE62 5100 0754 7061'
|
83
|
-
|
84
|
-
context 'with dashes' do
|
85
|
-
before { args[:account_number] = '510-0075470-61' }
|
86
|
-
its(:iban) { is_expected.to eq('BE62510007547061') }
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'without an account_number' do
|
90
|
-
before { args.delete(:account_number) }
|
91
|
-
|
92
|
-
it 'raises a helpful error message' do
|
93
|
-
expect { build }.
|
94
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'with CY as the country_code' do
|
100
|
-
let(:args) do
|
101
|
-
{
|
102
|
-
country_code: 'CY',
|
103
|
-
account_number: '0000001200527600',
|
104
|
-
bank_code: '002',
|
105
|
-
branch_code: '00128'
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
its(:iban) { is_expected.to eq('CY17002001280000001200527600') }
|
110
|
-
|
111
|
-
it_behaves_like 'allows round trips', 'CY17 0020 0128 0000 0012 0052 7600'
|
112
|
-
|
113
|
-
context "with an account number that hasn't been zero-padded" do
|
114
|
-
before { args[:account_number] = '1200527600' }
|
115
|
-
its(:iban) { is_expected.to eq('CY17002001280000001200527600') }
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'without an branch_code' do
|
119
|
-
before { args.delete(:branch_code) }
|
120
|
-
its(:iban) { is_expected.to eq('CY040020000001200527600') }
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'without an account_number' do
|
124
|
-
before { args.delete(:account_number) }
|
125
|
-
|
126
|
-
it 'raises a helpful error message' do
|
127
|
-
expect { build }.
|
128
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context 'without an bank_code' do
|
133
|
-
before { args.delete(:bank_code) }
|
134
|
-
|
135
|
-
it 'raises a helpful error message' do
|
136
|
-
expect { build }.
|
137
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context 'with DE as the country_code' do
|
143
|
-
let(:args) do
|
144
|
-
{ country_code: 'DE',
|
145
|
-
bank_code: '37040044',
|
146
|
-
account_number: '0532013000' }
|
147
|
-
end
|
148
|
-
|
149
|
-
its(:iban) { is_expected.to eq('DE89370400440532013000') }
|
150
|
-
|
151
|
-
it_behaves_like 'allows round trips', 'DE89 3704 0044 0532 0130 00'
|
152
|
-
|
153
|
-
context 'without a bank_code' do
|
154
|
-
before { args.delete(:bank_code) }
|
155
|
-
|
156
|
-
specify do
|
157
|
-
expect { build }.
|
158
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'without an account_number' do
|
163
|
-
before { args.delete(:account_number) }
|
164
|
-
|
165
|
-
specify do
|
166
|
-
expect { build }.
|
167
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'with a pseudo account number' do
|
172
|
-
before { args[:bank_code] = '37080040' }
|
173
|
-
before { args[:account_number] = '111' }
|
174
|
-
|
175
|
-
its(:iban) { is_expected.to eq('DE69370800400215022000') }
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'with EE as the country_code' do
|
180
|
-
let(:args) { { country_code: 'EE', account_number: '0221020145685' } }
|
181
|
-
|
182
|
-
its(:iban) { is_expected.to eq('EE382200221020145685') }
|
183
|
-
|
184
|
-
it_behaves_like 'allows round trips', 'EE38 2200 2210 2014 5685'
|
185
|
-
|
186
|
-
context 'with an account number that needs translating' do
|
187
|
-
before { args[:account_number] = '111020145685' }
|
188
|
-
its(:iban) { is_expected.to eq('EE412200111020145685') }
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'without an account_number' do
|
192
|
-
before { args.delete(:account_number) }
|
193
|
-
|
194
|
-
it 'raises a helpful error message' do
|
195
|
-
expect { build }.
|
196
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'with ES as the country_code' do
|
202
|
-
let(:args) do
|
203
|
-
{
|
204
|
-
country_code: 'ES',
|
205
|
-
bank_code: '2310',
|
206
|
-
branch_code: '0001',
|
207
|
-
account_number: '180000012345'
|
208
|
-
}
|
209
|
-
end
|
210
|
-
|
211
|
-
its(:iban) { is_expected.to eq('ES8023100001180000012345') }
|
212
|
-
|
213
|
-
it_behaves_like 'allows round trips', 'ES80 2310 0001 1800 0001 2345'
|
214
|
-
|
215
|
-
context 'without a bank_code or branch code' do
|
216
|
-
before { args.delete(:bank_code) }
|
217
|
-
before { args.delete(:branch_code) }
|
218
|
-
before { args[:account_number] = '23100001180000012345' }
|
219
|
-
|
220
|
-
its(:iban) { is_expected.to eq('ES8023100001180000012345') }
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'without an account_number' do
|
224
|
-
before { args.delete(:account_number) }
|
225
|
-
|
226
|
-
it 'raises a helpful error message' do
|
227
|
-
expect { build }.
|
228
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'with FI as the country_code' do
|
234
|
-
let(:args) do
|
235
|
-
{ country_code: 'FI', bank_code: '123456', account_number: '785' }
|
236
|
-
end
|
237
|
-
|
238
|
-
its(:iban) { is_expected.to eq('FI2112345600000785') }
|
239
|
-
|
240
|
-
it_behaves_like 'allows round trips', 'FI21 1234 5600 0007 85'
|
241
|
-
|
242
|
-
context 'with a savings bank account_number in traditional format' do
|
243
|
-
before { args[:account_number] = '78510' }
|
244
|
-
before { args[:bank_code] = '423456' }
|
245
|
-
|
246
|
-
its(:iban) { is_expected.to eq('FI3442345670008510') }
|
247
|
-
end
|
248
|
-
|
249
|
-
context 'without an account_number' do
|
250
|
-
before { args.delete(:account_number) }
|
251
|
-
|
252
|
-
it 'raises a helpful error message' do
|
253
|
-
expect { build }.
|
254
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
context 'without a bank_code' do
|
259
|
-
before { args.delete(:bank_code) }
|
260
|
-
|
261
|
-
it 'raises a helpful error message' do
|
262
|
-
expect { build }.
|
263
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
context 'with FR as the country_code' do
|
269
|
-
let(:args) do
|
270
|
-
{
|
271
|
-
country_code: 'FR',
|
272
|
-
bank_code: '20041',
|
273
|
-
branch_code: '01005',
|
274
|
-
account_number: '0500013M02606'
|
275
|
-
}
|
276
|
-
end
|
277
|
-
|
278
|
-
its(:iban) { is_expected.to eq('FR1420041010050500013M02606') }
|
279
|
-
|
280
|
-
it_behaves_like 'allows round trips', 'FR14 2004 1010 0505 0001 3M02 606'
|
281
|
-
|
282
|
-
context 'without the rib key in the account number' do
|
283
|
-
before { args[:account_number] = '0500013M026' }
|
284
|
-
its(:valid?) { is_expected.to be_falsey }
|
285
|
-
end
|
286
|
-
|
287
|
-
context 'without a bank_code' do
|
288
|
-
before { args.delete(:bank_code) }
|
289
|
-
|
290
|
-
it 'raises a helpful error message' do
|
291
|
-
expect { build }.
|
292
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
context 'without a branch_code' do
|
297
|
-
before { args.delete(:branch_code) }
|
298
|
-
|
299
|
-
it 'raises a helpful error message' do
|
300
|
-
expect { build }.
|
301
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
context 'without an account_number' do
|
306
|
-
before { args.delete(:account_number) }
|
307
|
-
|
308
|
-
it 'raises a helpful error message' do
|
309
|
-
expect { build }.
|
310
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
context 'with GB as the country_code' do
|
316
|
-
let(:args) do
|
317
|
-
{ country_code: 'GB',
|
318
|
-
bank_code: 'BARC',
|
319
|
-
branch_code: '200000',
|
320
|
-
account_number: '579135' }
|
321
|
-
end
|
322
|
-
|
323
|
-
its(:iban) { is_expected.to eq('GB07BARC20000000579135') }
|
324
|
-
|
325
|
-
it_behaves_like 'allows round trips', 'GB07 BARC 2000 0000 5791 35'
|
326
|
-
|
327
|
-
context 'when the sort code is hyphenated' do
|
328
|
-
before { args[:branch_code] = '20-00-00' }
|
329
|
-
its(:iban) { is_expected.to eq('GB07BARC20000000579135') }
|
330
|
-
end
|
331
|
-
|
332
|
-
context 'when the sort code is spaced' do
|
333
|
-
before { args[:branch_code] = '20 00 00' }
|
334
|
-
its(:iban) { is_expected.to eq('GB07BARC20000000579135') }
|
335
|
-
end
|
336
|
-
|
337
|
-
context 'when the account number is spaced' do
|
338
|
-
before { args[:account_number] = '579 135' }
|
339
|
-
its(:iban) { is_expected.to eq('GB07BARC20000000579135') }
|
340
|
-
end
|
341
|
-
|
342
|
-
context 'when the account number is hyphenated' do
|
343
|
-
before { args[:account_number] = '5577-9911' }
|
344
|
-
its(:iban) { is_expected.to eq('GB60BARC20000055779911') }
|
345
|
-
end
|
346
|
-
|
347
|
-
context 'with the bank_code supplied manually' do
|
348
|
-
before { args.merge!(bank_code: 'BARC') }
|
349
|
-
its(:iban) { is_expected.to eq('GB07BARC20000000579135') }
|
350
|
-
end
|
351
|
-
|
352
|
-
context 'without a branch_code' do
|
353
|
-
before { args.delete(:branch_code) }
|
354
|
-
|
355
|
-
specify do
|
356
|
-
expect { build }.
|
357
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
context 'without an account_number' do
|
362
|
-
before { args.delete(:account_number) }
|
363
|
-
|
364
|
-
specify do
|
365
|
-
expect { build }.
|
366
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
context 'without a bank_code' do
|
371
|
-
before { args.delete(:bank_code) }
|
372
|
-
|
373
|
-
context 'when a bic_finder is not defined' do
|
374
|
-
specify do
|
375
|
-
expect { build }.
|
376
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
context 'with a bic_finder' do
|
381
|
-
let(:bic_finder) { double }
|
382
|
-
before do
|
383
|
-
allow(bic_finder).to receive(:find).with('GB', '200000').
|
384
|
-
and_return('BARCGB22XXX')
|
385
|
-
Ibandit.bic_finder = ->(cc, id) { bic_finder.find(cc, id) }
|
386
|
-
end
|
387
|
-
after { Ibandit.bic_finder = nil }
|
388
|
-
|
389
|
-
its(:iban) { is_expected.to eq('GB07BARC20000000579135') }
|
390
|
-
|
391
|
-
context "when the BIC can't be found" do
|
392
|
-
before { Ibandit.bic_finder = ->(_cc, _id) { nil } }
|
393
|
-
|
394
|
-
it 'raises an Ibandit::BicNotFoundError' do
|
395
|
-
expect { build }.to raise_error(Ibandit::BicNotFoundError)
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
context 'with both a bank_code and a bic_finder' do
|
402
|
-
let(:bic_finder) { double }
|
403
|
-
before do
|
404
|
-
allow(bic_finder).to receive(:find).with('GB', '200000').
|
405
|
-
and_return('BANKGB22XXX')
|
406
|
-
Ibandit.bic_finder = ->(cc, id) { bic_finder.find(cc, id) }
|
407
|
-
end
|
408
|
-
after { Ibandit.bic_finder = nil }
|
409
|
-
|
410
|
-
it 'uses the explicitly provided bank_code' do
|
411
|
-
expect(subject.iban).to eq('GB07BARC20000000579135')
|
412
|
-
end
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
context 'with IE as the country_code' do
|
417
|
-
let(:args) do
|
418
|
-
{ country_code: 'IE',
|
419
|
-
bank_code: 'AIBK',
|
420
|
-
branch_code: '931152',
|
421
|
-
account_number: '12345678' }
|
422
|
-
end
|
423
|
-
|
424
|
-
its(:iban) { is_expected.to eq('IE29AIBK93115212345678') }
|
425
|
-
|
426
|
-
it_behaves_like 'allows round trips', 'IE29 AIBK 9311 5212 3456 78'
|
427
|
-
|
428
|
-
context 'with hyphens in the sort code' do
|
429
|
-
before { args[:branch_code] = '93-11-52' }
|
430
|
-
its(:iban) { is_expected.to eq('IE29AIBK93115212345678') }
|
431
|
-
end
|
432
|
-
|
433
|
-
context 'without a branch_code' do
|
434
|
-
before { args.delete(:branch_code) }
|
435
|
-
|
436
|
-
it 'raises a helpful error message' do
|
437
|
-
expect { build }.
|
438
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
context 'without an account_number' do
|
443
|
-
before { args.delete(:account_number) }
|
444
|
-
|
445
|
-
it 'raises a helpful error message' do
|
446
|
-
expect { build }.
|
447
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
448
|
-
end
|
449
|
-
end
|
450
|
-
|
451
|
-
context 'without a bank_code' do
|
452
|
-
before { args.delete(:bank_code) }
|
453
|
-
|
454
|
-
context 'when a bic_finder is not defined' do
|
455
|
-
specify do
|
456
|
-
expect { build }.
|
457
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
context 'with a bic_finder' do
|
462
|
-
let(:bic_finder) { double }
|
463
|
-
before do
|
464
|
-
allow(bic_finder).to receive(:find).with('IE', '931152').
|
465
|
-
and_return('AIBK1234XXX')
|
466
|
-
Ibandit.bic_finder = ->(cc, id) { bic_finder.find(cc, id) }
|
467
|
-
end
|
468
|
-
after { Ibandit.bic_finder = nil }
|
469
|
-
|
470
|
-
its(:iban) { is_expected.to eq('IE29AIBK93115212345678') }
|
471
|
-
|
472
|
-
context "when the BIC can't be found" do
|
473
|
-
before { Ibandit.bic_finder = ->(_cc, _id) { nil } }
|
474
|
-
|
475
|
-
it 'raises an Ibandit::BicNotFoundError' do
|
476
|
-
expect { build }.to raise_error(Ibandit::BicNotFoundError)
|
477
|
-
end
|
478
|
-
end
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
context 'with both a bank_code and a bic_finder' do
|
483
|
-
let(:bic_finder) { double }
|
484
|
-
before do
|
485
|
-
allow(bic_finder).to receive(:find).with('IE', '931152').
|
486
|
-
and_return('BANK1234XXX')
|
487
|
-
Ibandit.bic_finder = ->(cc, id) { bic_finder.find(cc, id) }
|
488
|
-
end
|
489
|
-
after { Ibandit.bic_finder = nil }
|
490
|
-
|
491
|
-
it 'uses the explicitly provided bank_code' do
|
492
|
-
expect(subject.iban).to eq('IE29AIBK93115212345678')
|
493
|
-
end
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
|
-
context 'with IT as the country_code' do
|
498
|
-
let(:args) do
|
499
|
-
{
|
500
|
-
country_code: 'IT',
|
501
|
-
bank_code: '05428',
|
502
|
-
branch_code: '11101',
|
503
|
-
account_number: '0000123456'
|
504
|
-
}
|
505
|
-
end
|
506
|
-
|
507
|
-
its(:iban) { is_expected.to eq('IT60X0542811101000000123456') }
|
508
|
-
|
509
|
-
it_behaves_like 'allows round trips', 'IT60 X054 2811 1010 0000 0123 456'
|
510
|
-
|
511
|
-
context 'with an explicitly passed check digit' do
|
512
|
-
before { args[:check_digit] = 'Y' }
|
513
|
-
its(:iban) { is_expected.to eq('IT64Y0542811101000000123456') }
|
514
|
-
end
|
515
|
-
|
516
|
-
context 'without a bank_code' do
|
517
|
-
before { args.delete(:bank_code) }
|
518
|
-
|
519
|
-
it 'raises a helpful error message' do
|
520
|
-
expect { build }.
|
521
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
context 'without a branch_code' do
|
526
|
-
before { args.delete(:branch_code) }
|
527
|
-
|
528
|
-
it 'raises a helpful error message' do
|
529
|
-
expect { build }.
|
530
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
531
|
-
end
|
532
|
-
end
|
533
|
-
|
534
|
-
context 'without an account_number' do
|
535
|
-
before { args.delete(:account_number) }
|
536
|
-
|
537
|
-
it 'raises a helpful error message' do
|
538
|
-
expect { build }.
|
539
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
540
|
-
end
|
541
|
-
end
|
542
|
-
end
|
543
|
-
|
544
|
-
context 'with LT as the country_code' do
|
545
|
-
let(:args) do
|
546
|
-
{
|
547
|
-
country_code: 'LT',
|
548
|
-
account_number: '11101001000',
|
549
|
-
bank_code: '10000'
|
550
|
-
}
|
551
|
-
end
|
552
|
-
|
553
|
-
its(:iban) { is_expected.to eq('LT121000011101001000') }
|
554
|
-
|
555
|
-
it_behaves_like 'allows round trips', 'LT12 1000 0111 0100 1000'
|
556
|
-
|
557
|
-
context 'without an account_number' do
|
558
|
-
before { args.delete(:account_number) }
|
559
|
-
|
560
|
-
it 'raises a helpful error message' do
|
561
|
-
expect { build }.
|
562
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
context 'without a bank_code' do
|
567
|
-
before { args.delete(:bank_code) }
|
568
|
-
|
569
|
-
it 'raises a helpful error message' do
|
570
|
-
expect { build }.
|
571
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
572
|
-
end
|
573
|
-
end
|
574
|
-
end
|
575
|
-
|
576
|
-
context 'with LU as the country_code' do
|
577
|
-
let(:args) do
|
578
|
-
{
|
579
|
-
country_code: 'LU',
|
580
|
-
account_number: '9400644750000',
|
581
|
-
bank_code: '001'
|
582
|
-
}
|
583
|
-
end
|
584
|
-
|
585
|
-
its(:iban) { is_expected.to eq('LU280019400644750000') }
|
586
|
-
|
587
|
-
it_behaves_like 'allows round trips', 'LU28 0019 4006 4475 0000'
|
588
|
-
|
589
|
-
context 'without an account_number' do
|
590
|
-
before { args.delete(:account_number) }
|
591
|
-
|
592
|
-
it 'raises a helpful error message' do
|
593
|
-
expect { build }.
|
594
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
595
|
-
end
|
596
|
-
end
|
597
|
-
|
598
|
-
context 'without a bank_code' do
|
599
|
-
before { args.delete(:bank_code) }
|
600
|
-
|
601
|
-
it 'raises a helpful error message' do
|
602
|
-
expect { build }.
|
603
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
604
|
-
end
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
context 'with LV as the country_code' do
|
609
|
-
let(:args) do
|
610
|
-
{
|
611
|
-
country_code: 'LV',
|
612
|
-
account_number: '1234567890123',
|
613
|
-
bank_code: 'BANK'
|
614
|
-
}
|
615
|
-
end
|
616
|
-
|
617
|
-
its(:iban) { is_expected.to eq('LV72BANK1234567890123') }
|
618
|
-
|
619
|
-
it_behaves_like 'allows round trips', 'LV72 BANK 1234 5678 9012 3'
|
620
|
-
|
621
|
-
context 'without an account_number' do
|
622
|
-
before { args.delete(:account_number) }
|
623
|
-
|
624
|
-
it 'raises a helpful error message' do
|
625
|
-
expect { build }.
|
626
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
627
|
-
end
|
628
|
-
end
|
629
|
-
|
630
|
-
context 'without a bank_code' do
|
631
|
-
before { args.delete(:bank_code) }
|
632
|
-
|
633
|
-
it 'raises a helpful error message' do
|
634
|
-
expect { build }.
|
635
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
636
|
-
end
|
637
|
-
end
|
638
|
-
end
|
639
|
-
|
640
|
-
context 'with MC as the country_code' do
|
641
|
-
let(:args) do
|
642
|
-
{
|
643
|
-
country_code: 'MC',
|
644
|
-
bank_code: '20041',
|
645
|
-
branch_code: '01005',
|
646
|
-
account_number: '0500013M02606'
|
647
|
-
}
|
648
|
-
end
|
649
|
-
|
650
|
-
its(:iban) { is_expected.to eq('MC9320041010050500013M02606') }
|
651
|
-
|
652
|
-
it_behaves_like 'allows round trips', 'MC93 2004 1010 0505 0001 3M02 606'
|
653
|
-
|
654
|
-
context 'without the rib key in the account number' do
|
655
|
-
before { args[:account_number] = '0500013M026' }
|
656
|
-
its(:valid?) { is_expected.to be_falsey }
|
657
|
-
end
|
658
|
-
|
659
|
-
context 'without a bank_code' do
|
660
|
-
before { args.delete(:bank_code) }
|
661
|
-
|
662
|
-
it 'raises a helpful error message' do
|
663
|
-
expect { build }.
|
664
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
665
|
-
end
|
666
|
-
end
|
667
|
-
|
668
|
-
context 'without a branch_code' do
|
669
|
-
before { args.delete(:branch_code) }
|
670
|
-
|
671
|
-
it 'raises a helpful error message' do
|
672
|
-
expect { build }.
|
673
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
674
|
-
end
|
675
|
-
end
|
676
|
-
|
677
|
-
context 'without an account_number' do
|
678
|
-
before { args.delete(:account_number) }
|
679
|
-
|
680
|
-
it 'raises a helpful error message' do
|
681
|
-
expect { build }.
|
682
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
683
|
-
end
|
684
|
-
end
|
685
|
-
end
|
686
|
-
|
687
|
-
context 'with NL as the country_code' do
|
688
|
-
let(:args) do
|
689
|
-
{
|
690
|
-
country_code: 'NL',
|
691
|
-
account_number: '0417164300',
|
692
|
-
bank_code: 'ABNA'
|
693
|
-
}
|
694
|
-
end
|
695
|
-
|
696
|
-
its(:iban) { is_expected.to eq('NL91ABNA0417164300') }
|
697
|
-
|
698
|
-
it_behaves_like 'allows round trips', 'NL91 ABNA 0417 1643 00'
|
699
|
-
|
700
|
-
context "with an account number that hasn't been zero-padded" do
|
701
|
-
before { args[:account_number] = '417164300' }
|
702
|
-
its(:iban) { is_expected.to eq('NL91ABNA0417164300') }
|
703
|
-
end
|
704
|
-
|
705
|
-
context 'without an account_number' do
|
706
|
-
before { args.delete(:account_number) }
|
707
|
-
|
708
|
-
it 'raises a helpful error message' do
|
709
|
-
expect { build }.
|
710
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
711
|
-
end
|
712
|
-
end
|
713
|
-
|
714
|
-
context 'without an bank_code' do
|
715
|
-
before { args.delete(:bank_code) }
|
716
|
-
|
717
|
-
it 'raises a helpful error message' do
|
718
|
-
expect { build }.
|
719
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
720
|
-
end
|
721
|
-
end
|
722
|
-
end
|
723
|
-
|
724
|
-
context 'with PT as the country_code' do
|
725
|
-
let(:args) do
|
726
|
-
{
|
727
|
-
country_code: 'PT',
|
728
|
-
bank_code: '0002',
|
729
|
-
branch_code: '0023',
|
730
|
-
account_number: '0023843000578'
|
731
|
-
}
|
732
|
-
end
|
733
|
-
|
734
|
-
its(:iban) { is_expected.to eq('PT50000200230023843000578') }
|
735
|
-
|
736
|
-
it_behaves_like 'allows round trips', 'PT50 0002 0023 0023 8430 0057 8'
|
737
|
-
|
738
|
-
context 'without a bank_code' do
|
739
|
-
before { args.delete(:bank_code) }
|
740
|
-
|
741
|
-
it 'raises a helpful error message' do
|
742
|
-
expect { build }.
|
743
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
744
|
-
end
|
745
|
-
end
|
746
|
-
|
747
|
-
context 'without a branch_code' do
|
748
|
-
before { args.delete(:branch_code) }
|
749
|
-
|
750
|
-
it 'raises a helpful error message' do
|
751
|
-
expect { build }.
|
752
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
753
|
-
end
|
754
|
-
end
|
755
|
-
|
756
|
-
context 'without an account_number' do
|
757
|
-
before { args.delete(:account_number) }
|
758
|
-
|
759
|
-
it 'raises a helpful error message' do
|
760
|
-
expect { build }.
|
761
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
762
|
-
end
|
763
|
-
end
|
764
|
-
end
|
765
|
-
|
766
|
-
context 'with SI as the country_code' do
|
767
|
-
let(:args) do
|
768
|
-
{
|
769
|
-
country_code: 'SI',
|
770
|
-
bank_code: '19100',
|
771
|
-
account_number: '0000123438'
|
772
|
-
}
|
773
|
-
end
|
774
|
-
|
775
|
-
its(:iban) { is_expected.to eq('SI56191000000123438') }
|
776
|
-
|
777
|
-
it_behaves_like 'allows round trips', 'SI56 1910 0000 0123 438'
|
778
|
-
|
779
|
-
context 'with an account number that needs padding' do
|
780
|
-
before { args[:account_number] = '123438' }
|
781
|
-
its(:iban) { is_expected.to eq('SI56191000000123438') }
|
782
|
-
end
|
783
|
-
|
784
|
-
context 'without a bank_code' do
|
785
|
-
before { args.delete(:bank_code) }
|
786
|
-
|
787
|
-
it 'raises a helpful error message' do
|
788
|
-
expect { build }.
|
789
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
790
|
-
end
|
791
|
-
end
|
792
|
-
|
793
|
-
context 'without an account_number' do
|
794
|
-
before { args.delete(:account_number) }
|
795
|
-
|
796
|
-
it 'raises a helpful error message' do
|
797
|
-
expect { build }.
|
798
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
799
|
-
end
|
800
|
-
end
|
801
|
-
end
|
802
|
-
|
803
|
-
context 'with SK as the country_code' do
|
804
|
-
let(:args) do
|
805
|
-
{
|
806
|
-
country_code: 'SK',
|
807
|
-
bank_code: '1200',
|
808
|
-
account_number_prefix: '000019',
|
809
|
-
account_number: '8742637541'
|
810
|
-
}
|
811
|
-
end
|
812
|
-
|
813
|
-
its(:iban) { is_expected.to eq('SK3112000000198742637541') }
|
814
|
-
|
815
|
-
it_behaves_like 'allows round trips', 'SK31 1200 0000 1987 4263 7541'
|
816
|
-
|
817
|
-
context 'with an account number prefix that needs padding' do
|
818
|
-
before { args[:account_number_prefix] = '19' }
|
819
|
-
its(:iban) { is_expected.to eq('SK3112000000198742637541') }
|
820
|
-
end
|
821
|
-
|
822
|
-
context 'without a bank_code' do
|
823
|
-
before { args.delete(:bank_code) }
|
824
|
-
|
825
|
-
it 'raises a helpful error message' do
|
826
|
-
expect { build }.
|
827
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
828
|
-
end
|
829
|
-
end
|
830
|
-
|
831
|
-
context 'without an account_number' do
|
832
|
-
before { args.delete(:account_number) }
|
833
|
-
|
834
|
-
it 'raises a helpful error message' do
|
835
|
-
expect { build }.
|
836
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
837
|
-
end
|
838
|
-
end
|
839
|
-
|
840
|
-
context 'without an account_number_prefix' do
|
841
|
-
before { args.delete(:account_number) }
|
842
|
-
|
843
|
-
it 'raises a helpful error message' do
|
844
|
-
expect { build }.
|
845
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
846
|
-
end
|
847
|
-
end
|
848
|
-
end
|
849
|
-
|
850
|
-
context 'with SM as the country_code' do
|
851
|
-
let(:args) do
|
852
|
-
{
|
853
|
-
country_code: 'SM',
|
854
|
-
bank_code: '05428',
|
855
|
-
branch_code: '11101',
|
856
|
-
account_number: '000000123456'
|
857
|
-
}
|
858
|
-
end
|
859
|
-
|
860
|
-
its(:iban) { is_expected.to eq('SM88X0542811101000000123456') }
|
861
|
-
|
862
|
-
it_behaves_like 'allows round trips', 'SM88 X054 2811 1010 0000 0123 456'
|
863
|
-
|
864
|
-
context 'without a bank_code' do
|
865
|
-
before { args.delete(:bank_code) }
|
866
|
-
|
867
|
-
it 'raises a helpful error message' do
|
868
|
-
expect { build }.
|
869
|
-
to raise_error(ArgumentError, /bank_code is a required field/)
|
870
|
-
end
|
871
|
-
end
|
872
|
-
|
873
|
-
context 'without a branch_code' do
|
874
|
-
before { args.delete(:branch_code) }
|
875
|
-
|
876
|
-
it 'raises a helpful error message' do
|
877
|
-
expect { build }.
|
878
|
-
to raise_error(ArgumentError, /branch_code is a required field/)
|
879
|
-
end
|
880
|
-
end
|
881
|
-
|
882
|
-
context 'without an account_number' do
|
883
|
-
before { args.delete(:account_number) }
|
884
|
-
|
885
|
-
it 'raises a helpful error message' do
|
886
|
-
expect { build }.
|
887
|
-
to raise_error(ArgumentError, /account_number is a required field/)
|
888
|
-
end
|
889
|
-
end
|
890
|
-
end
|
891
|
-
end
|
892
|
-
end
|