payment_dta 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +45 -0
  3. data/VERSION +1 -0
  4. data/generators/payment/USAGE +5 -0
  5. data/generators/payment/payment_generator.rb +76 -0
  6. data/generators/payment/templates/model.rb.erb +39 -0
  7. data/generators/payment/templates/spec.rb.erb +48 -0
  8. data/lib/payment_dta.rb +4 -0
  9. data/lib/payment_dta/character_conversion.rb +251 -0
  10. data/lib/payment_dta/dta_file.rb +55 -0
  11. data/lib/payment_dta/payment_sorting.rb +19 -0
  12. data/lib/payment_dta/payments/bank_cheque_payment.rb +60 -0
  13. data/lib/payment_dta/payments/base.rb +288 -0
  14. data/lib/payment_dta/payments/domestic_chf_payment.rb +67 -0
  15. data/lib/payment_dta/payments/esr_payment.rb +48 -0
  16. data/lib/payment_dta/payments/financial_institution_payment.rb +56 -0
  17. data/lib/payment_dta/payments/iban_payment.rb +76 -0
  18. data/lib/payment_dta/payments/special_financial_institution_payment.rb +64 -0
  19. data/lib/payment_dta/payments/total_record.rb +31 -0
  20. data/script/destroy +14 -0
  21. data/script/generate +14 -0
  22. data/spec/factory.rb +82 -0
  23. data/spec/lib/bank_cheque_payment_spec.rb +178 -0
  24. data/spec/lib/character_conversion_spec.rb +280 -0
  25. data/spec/lib/domestic_chf_payment_spec.rb +189 -0
  26. data/spec/lib/dta_file_spec.rb +81 -0
  27. data/spec/lib/esr_payment_spec.rb +157 -0
  28. data/spec/lib/financial_institution_payment_spec.rb +229 -0
  29. data/spec/lib/iban_payment_spec.rb +201 -0
  30. data/spec/lib/payment_header_spec.rb +221 -0
  31. data/spec/lib/payment_spec.rb +15 -0
  32. data/spec/lib/special_financial_institution_payment_spec.rb +238 -0
  33. data/spec/lib/total_record_spec.rb +20 -0
  34. data/spec/spec_helper.rb +9 -0
  35. metadata +107 -0
@@ -0,0 +1,201 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'payments/iban_payment'
3
+
4
+ describe IBANPayment do
5
+ it "should have a total length of 640 characters" do
6
+ Factory.create_iban_payment.record.size.should == 640
7
+ end
8
+
9
+ describe 'segment1' do
10
+ it 'should set the segment field to 01' do
11
+ Factory.create_iban_payment.segment1[0,2].should == '01'
12
+ end
13
+
14
+ it 'should have a reference number' do
15
+ Factory.create_iban_payment(:issuer_identification => 'ABC01', :transaction_number => '00123478901').segment1[53,16].should == "ABC0100123478901"
16
+ end
17
+
18
+ it 'should have an account to be debited without IBAN justified left filled with blanks' do
19
+ Factory.create_iban_payment(:account_to_be_debited => '10235678').segment1[69,24].should == '10235678'.ljust(24)
20
+ end
21
+
22
+ it 'should have an account to be debited with IBAN' do
23
+ Factory.create_iban_payment(:account_to_be_debited => 'CH9300762011623852957').segment1[69,24].should == 'CH9300762011623852957 '
24
+ end
25
+
26
+ it 'should have a payment amount value date yymmdd' do
27
+ Factory.create_iban_payment(:payment_amount_value_date => '051031').segment1[93,6].should == '051031'
28
+ end
29
+
30
+ it 'should have a payment amount currency code' do
31
+ Factory.create_iban_payment(:payment_amount_currency => 'USD').segment1[99,3].should == 'USD'
32
+ end
33
+
34
+ it 'should have a payment amount justified left filled with blanks' do
35
+ Factory.create_iban_payment(:payment_amount => '3949.75').segment1[102,15].should == '3949.75'.ljust(15)
36
+ end
37
+
38
+ it 'should have a reserve field' do
39
+ Factory.create_iban_payment.segment1[117,11].should == ''.ljust(11)
40
+ end
41
+
42
+ it 'should have a total length of 128 characters' do
43
+ Factory.create_iban_payment.segment1.size.should == 128
44
+ end
45
+ end
46
+ describe 'segment2' do
47
+ it 'should set the segment field to 02' do
48
+ Factory.create_iban_payment.segment2[0,2].should == '02'
49
+ end
50
+
51
+ it 'should set the conversion rate if given' do
52
+ Factory.create_iban_payment(:convertion_rate => '0.9543').segment2[2,12].should == '0.9543'.ljust(12)
53
+ end
54
+
55
+ it 'should have an ordering partys address line 1' do
56
+ Factory.create_iban_payment(:ordering_partys_address_line1 => 'John Doe').segment2[14,35].should == 'John Doe'.ljust(35)
57
+ end
58
+
59
+ it 'should have an ordering partys address line 2' do
60
+ Factory.create_iban_payment(:ordering_partys_address_line2 => 'Bahnhofstrasse 1').segment2[49,35].should == 'Bahnhofstrasse 1'.ljust(35)
61
+ end
62
+
63
+ it 'should have an ordering partys address line 3' do
64
+ Factory.create_iban_payment(:ordering_partys_address_line3 => '8000 Zurich').segment2[84,35].should == '8000 Zurich'.ljust(35)
65
+ end
66
+
67
+ it 'should have a reserve field' do
68
+ Factory.create_iban_payment.segment2[114,9].should == ' '.ljust(9)
69
+ end
70
+
71
+ it 'should have a total length of 128 characters' do
72
+ Factory.create_iban_payment.segment2.size.should == 128
73
+ end
74
+ end
75
+
76
+ describe 'segment3' do
77
+ it 'should set the segment field to 03' do
78
+ Factory.create_iban_payment.segment3[0,2].should == '03'
79
+ end
80
+
81
+ it 'have an identification bank address' do
82
+ Factory.create_iban_payment(:identification_bank_address => 'D').segment3[2,1].should == 'D'
83
+ end
84
+
85
+ describe 'option A' do
86
+ it 'should must contain the 8- or 11-character BIC address (= SWIFT address) of the beneficiarys institution' do
87
+ Factory.create_iban_payment(:identification_bank_address => 'A', :beneficiarys_institution_swift_address_ => 'BBBBLLRRNL2').segment3[3,35].should == 'BBBBLLRRNL2'.ljust(35)
88
+ end
89
+
90
+ it 'should leave the next line blank' do
91
+ Factory.create_iban_payment(:identification_bank_address => 'A', :beneficiarys_institution_swift_address_ => 'BBBBLLRRNL2').segment3[38,35].should == ''.ljust(35)
92
+ end
93
+ end
94
+
95
+ describe 'option D' do
96
+ it 'should have an address line 1' do
97
+ Factory.create_iban_payment(:identification_bank_address => 'D',:beneficiary_institution_address_line1 => 'SPARKASSE OBERSEE').segment3[3,35].should == 'SPARKASSE OBERSEE'.ljust(35)
98
+ end
99
+
100
+ it 'should have a beneficiary institution address line 2' do
101
+ Factory.create_iban_payment(:identification_bank_address => 'D',:beneficiary_institution_address_line2 => 'ANYWHERE').segment3[38,35].should == 'ANYWHERE'.ljust(35)
102
+ end
103
+ end
104
+
105
+ it "should have a beneficiary IBAN number" do
106
+ Factory.create_iban_payment(:beneficiary_iban_number => 'CH3808888123456789012').segment3[73,34].should == 'CH3808888123456789012'.ljust(34)
107
+ end
108
+
109
+ it 'should have a reserve field' do
110
+ Factory.create_iban_payment.segment3[107,21].should == ' '.ljust(21)
111
+ end
112
+
113
+ it 'should have a total length of 128 characters' do
114
+ Factory.create_iban_payment.segment3.size.should == 128
115
+ end
116
+ end
117
+
118
+ describe 'segment4' do
119
+ it 'should set the segment field to 04' do
120
+ Factory.create_iban_payment.segment4[0,2].should == '04'
121
+ end
122
+
123
+ it 'should have a address line 1' do
124
+ Factory.create_iban_payment(:beneficiary_address_line1 => 'Michael Recipient').segment4[2,35].should == 'Michael Recipient'.ljust(35)
125
+ end
126
+
127
+ it 'should have a beneficiary address line 2' do
128
+ Factory.create_iban_payment(:beneficiary_address_line2 => 'Empfaengerstrasse 1').segment4[37,35].should == 'Empfaengerstrasse 1'.ljust(35)
129
+ end
130
+
131
+ it 'should have a beneficiary address line 3' do
132
+ Factory.create_iban_payment(:beneficiary_address_line3 => '8640 Rapperswil').segment4[72,35].should == '8640 Rapperswil'.ljust(35)
133
+ end
134
+
135
+ it 'should have a reserve field' do
136
+ Factory.create_iban_payment.segment4[107,21].should == ' '.ljust(21)
137
+ end
138
+
139
+ it 'should have a total length of 128 characters' do
140
+ Factory.create_iban_payment.segment4.size.should == 128
141
+ end
142
+ end
143
+
144
+ describe 'segment5' do
145
+ it 'should set the segment field to 05' do
146
+ Factory.create_iban_payment.segment5[0,2].should == '05'
147
+ end
148
+
149
+ it "should have an identification purpose" do
150
+ Factory.create_iban_payment(:identification_purpose => 'I', :purpose_structured_reference_number => 'i3or6cev1wog5ez5og8j').segment5[2,1].should == 'I'
151
+ end
152
+
153
+ describe 'identification purpose is I' do
154
+ it 'should have a structured reference number' do
155
+ Factory.create_iban_payment(:identification_purpose => 'I', :purpose_structured_reference_number => 'i3or6cev1wog5ez5og8j').segment5[3,105].should == 'i3or6cev1wog5ez5og8j'.ljust(105)
156
+ end
157
+ end
158
+
159
+ describe 'identification purpose is U' do
160
+ it 'should have a purpose text line 1' do
161
+ Factory.create_iban_payment(:identification_purpose => 'U', :purpose_line_1 => 'LINE 1').segment5[3,35].should == 'LINE 1'.ljust(35)
162
+ end
163
+
164
+ it 'should have a purpose text line 2' do
165
+ Factory.create_iban_payment(:identification_purpose => 'U', :purpose_line_2 => 'LINE 2').segment5[38,35].should == 'LINE 2'.ljust(35)
166
+ end
167
+
168
+ it 'should have a purpose text line 3' do
169
+ Factory.create_iban_payment(:identification_purpose => 'U', :purpose_line_3 => 'LINE 3').segment5[73,35].should == 'LINE 3'.ljust(35)
170
+ end
171
+ end
172
+
173
+ it "should have a rule of charge" do
174
+ Factory.create_iban_payment(:rule_of_charge => '2').segment5[108,1].should == '2'
175
+ end
176
+
177
+ it 'should have a reserve field' do
178
+ Factory.create_iban_payment.segment5[109,19].should == ' '.ljust(19)
179
+ end
180
+
181
+ it 'should have a total length of 128 characters' do
182
+ Factory.create_iban_payment.segment5.size.should == 128
183
+ end
184
+ end
185
+
186
+ describe 'comparison' do
187
+ it "should sort by issuer identification" do
188
+ @record1 = Factory.create_iban_payment(:issuer_identification => "AAAAA")
189
+ @record2 = Factory.create_iban_payment(:issuer_identification => "BBBBB")
190
+
191
+ (@record1 < @record2).should be_true
192
+ end
193
+
194
+ it "should sort by issuers clearing number when issuer identifications are equal" do
195
+ @record1 = Factory.create_iban_payment(:issuer_identification => "AAAAA", :ordering_party_bank_clearing_number => '253')
196
+ @record2 = Factory.create_iban_payment(:issuer_identification => "AAAAA", :ordering_party_bank_clearing_number => '254')
197
+
198
+ (@record1 < @record2).should be_true
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,221 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ %w(esr_payment domestic_chf_payment financial_institution_payment bank_cheque_payment iban_payment special_financial_institution_payment total_record).each do |payment_type|
3
+ require "payments/#{payment_type}"
4
+ end
5
+
6
+ shared_examples_for "all headers" do
7
+ it 'should have a total length of 51 characters' do
8
+ Factory.create_payment(@type).header.size.should == 51
9
+ end
10
+
11
+ it 'should fill out a blank output sequence number' do
12
+ Factory.create_payment(@type).header[18,5].should == '00000'
13
+ end
14
+
15
+ it 'should set the creation date' do
16
+ Factory.create_payment(@type).header[23,6].should == Date.today.strftime('%y%m%d')
17
+ end
18
+
19
+ it 'should set the data file sender identification' do
20
+ Factory.create_payment(@type,:data_file_sender_identification => 'ABC12').header[36,5].should == 'ABC12'
21
+ end
22
+
23
+ it 'should should set the entry sequence number' do
24
+ Factory.create_payment(@type,:entry_sequence_number => 1).header[41,5].should == '00001'
25
+ end
26
+
27
+ it 'should set the processing flag to 0' do
28
+ Factory.create_payment(@type).header[50,1].should == '0'
29
+ end
30
+ end
31
+
32
+ describe ESRPayment, 'header' do
33
+ before(:each) do
34
+ @type = :esr
35
+ end
36
+
37
+ it_should_behave_like 'all headers'
38
+
39
+ it 'should set a the correct processing date' do
40
+ Factory.create_esr_payment(:requested_processing_date => '051021').header[0,6].should == '051021'
41
+ end
42
+
43
+ it 'should fill the beneficiarys bank clearing number with blanks' do
44
+ Factory.create_esr_payment.header[6,12].should == ''.ljust(12,' ')
45
+ end
46
+
47
+ it 'should set the ordering party bank clearing number' do
48
+ Factory.create_esr_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
49
+ end
50
+
51
+ it 'should should set the transaction type to 826' do
52
+ Factory.create_esr_payment.header[46,3].should == '826'
53
+ end
54
+
55
+ it 'should set the payment type to 0' do
56
+ Factory.create_esr_payment.header[49,1].should == '0'
57
+ end
58
+ end
59
+
60
+ describe DomesticCHFPayment, 'header' do
61
+ before(:each) do
62
+ @type = :domestic_chf
63
+ end
64
+ it_should_behave_like 'all headers'
65
+
66
+ it 'should set a the correct processing date' do
67
+ Factory.create_domestic_chf_payment(:requested_processing_date => '051021').header[0,6].should == '051021'
68
+ end
69
+
70
+ it 'should fill the beneficiarys bank clearing number with blanks' do
71
+ Factory.create_domestic_chf_payment(:beneficiary_bank_clearing_number => "99999").header[6,12].should == '99999'.ljust(12,' ')
72
+ end
73
+
74
+ it 'should set the ordering party bank clearing number' do
75
+ Factory.create_domestic_chf_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
76
+ end
77
+
78
+ it 'should should set the transaction type to 827' do
79
+ Factory.create_domestic_chf_payment.header[46,3].should == '827'
80
+ end
81
+
82
+ it 'should set the payment type to 0' do
83
+ Factory.create_domestic_chf_payment.header[49,1].should == '0'
84
+ end
85
+ end
86
+
87
+ describe FinancialInstitutionPayment, 'header' do
88
+ before(:each) do
89
+ @type = :financial_institution
90
+ end
91
+
92
+ it_should_behave_like 'all headers'
93
+
94
+ it 'should fill the requested processing date with zeros' do
95
+ Factory.create_financial_institution_payment.header[0,6].should == '000000'
96
+ end
97
+
98
+ it 'should fill the beneficiarys bank clearing number with blanks' do
99
+ Factory.create_financial_institution_payment.header[6,12].should == ''.ljust(12,' ')
100
+ end
101
+
102
+ it 'should set the ordering party bank clearing number' do
103
+ Factory.create_financial_institution_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
104
+ end
105
+
106
+ it 'should should set the transaction type to 830' do
107
+ Factory.create_financial_institution_payment.header[46,3].should == '830'
108
+ end
109
+
110
+ it 'should set the payment type to 0' do
111
+ Factory.create_financial_institution_payment.header[49,1].should == '0'
112
+ end
113
+ end
114
+
115
+ describe BankChequePayment, 'header' do
116
+ before(:each) do
117
+ @type = :bank_cheque
118
+ end
119
+
120
+ it_should_behave_like 'all headers'
121
+
122
+ it 'should fill the requested processing date with zeros' do
123
+ Factory.create_bank_cheque_payment.header[0,6].should == '000000'
124
+ end
125
+
126
+ it 'should fill the beneficiarys bank clearing number with blanks' do
127
+ Factory.create_bank_cheque_payment.header[6,12].should == ''.ljust(12,' ')
128
+ end
129
+
130
+ it 'should set the ordering party bank clearing number' do
131
+ Factory.create_bank_cheque_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
132
+ end
133
+
134
+ it 'should should set the transaction type to 832' do
135
+ Factory.create_bank_cheque_payment.header[46,3].should == '832'
136
+ end
137
+
138
+ it 'should set the payment type to 0' do
139
+ Factory.create_bank_cheque_payment.header[49,1].should == '0'
140
+ end
141
+ end
142
+
143
+ describe IBANPayment, 'header' do
144
+ before(:each) do
145
+ @type = :iban
146
+ end
147
+
148
+ it_should_behave_like 'all headers'
149
+
150
+ it 'should fill the requested processing date with zeros' do
151
+ Factory.create_iban_payment.header[0,6].should == '000000'
152
+ end
153
+
154
+ it 'should fill the beneficiarys bank clearing number with blanks' do
155
+ Factory.create_iban_payment.header[6,12].should == ''.ljust(12,' ')
156
+ end
157
+
158
+ it 'should set the ordering party bank clearing number' do
159
+ Factory.create_iban_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
160
+ end
161
+
162
+ it 'should should set the transaction type to 836' do
163
+ Factory.create_iban_payment.header[46,3].should == '836'
164
+ end
165
+
166
+ it 'should set the payment type to 1' do
167
+ Factory.create_iban_payment.header[49,1].should == '1'
168
+ end
169
+ end
170
+
171
+ describe SpecialFinancialInstitutionPayment, 'header' do
172
+ before(:each) do
173
+ @type = :special_financial_institution
174
+ end
175
+
176
+ it_should_behave_like 'all headers'
177
+
178
+ it 'should fill the requested processing date with zeros' do
179
+ Factory.create_special_financial_institution_payment.header[0,6].should == '000000'
180
+ end
181
+
182
+ it 'should fill the beneficiarys bank clearing number with blanks' do
183
+ Factory.create_special_financial_institution_payment.header[6,12].should == ''.ljust(12,' ')
184
+ end
185
+
186
+ it 'should set the ordering party bank clearing number' do
187
+ Factory.create_special_financial_institution_payment(:ordering_party_bank_clearing_number => '254').header[29,7].should == '2540000'
188
+ end
189
+
190
+ it 'should should set the transaction type to 837' do
191
+ Factory.create_special_financial_institution_payment.header[46,3].should == '837'
192
+ end
193
+
194
+ it 'should set the payment type to 1' do
195
+ Factory.create_special_financial_institution_payment.header[49,1].should == '1'
196
+ end
197
+ end
198
+
199
+ describe TotalRecord, 'header' do
200
+ before(:each) do
201
+ @type = :total
202
+ end
203
+
204
+ it_should_behave_like 'all headers'
205
+
206
+ it 'should fill the ordering party bank clearing number with blanks' do
207
+ Factory.create_total_payment.header[29,7].should == ' '
208
+ end
209
+
210
+ it 'should should set the transaction type to 890' do
211
+ Factory.create_total_payment.header[46,3].should == '890'
212
+ end
213
+
214
+ it 'should set the payment type to 0' do
215
+ Factory.create_total_payment.header[49,1].should == '0'
216
+ end
217
+
218
+ it 'should set a the correct processing date' do
219
+ Factory.create_total_payment.header[0,6].should == '000000'
220
+ end
221
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'payments/esr_payment'
3
+ require 'payments/total_record'
4
+ require 'character_conversion'
5
+
6
+ class Test
7
+ extend DTA::CharacterConversion
8
+ end
9
+
10
+ describe "dta payments" do
11
+ it "should have a dta encoded representation" do
12
+ record = Factory.create_total_record(:data_file_sender_identification => 'ÄÜ2')
13
+ record.to_dta.should == Test.dta_string(record.record)
14
+ end
15
+ end
@@ -0,0 +1,238 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'payments/special_financial_institution_payment'
3
+
4
+ describe SpecialFinancialInstitutionPayment do
5
+ it "should have a total length of 640 characters" do
6
+ Factory.create_special_financial_institution_payment.record.size.should == 640
7
+ end
8
+
9
+ describe 'segment1' do
10
+ it 'should set the segment field to 01' do
11
+ Factory.create_special_financial_institution_payment.segment1[0,2].should == '01'
12
+ end
13
+
14
+ it 'should have a reference number' do
15
+ Factory.create_special_financial_institution_payment(:issuer_identification => 'ABC01', :transaction_number => '00123478901').segment1[53,16].should == "ABC0100123478901"
16
+ end
17
+
18
+ it 'should have an account to be debited without IBAN justified left filled with blanks' do
19
+ Factory.create_special_financial_institution_payment(:account_to_be_debited => '10235678').segment1[69,34].should == '10235678'.ljust(34)
20
+ end
21
+
22
+ it 'should have an account to be debited with IBAN' do
23
+ Factory.create_special_financial_institution_payment(:account_to_be_debited => 'CH9300762011623852957').segment1[69,34].should == 'CH9300762011623852957'.ljust(34)
24
+ end
25
+
26
+ it 'should have a payment amount value date yymmdd' do
27
+ Factory.create_special_financial_institution_payment(:payment_amount_value_date => '051031').segment1[103,6].should == '051031'
28
+ end
29
+
30
+ it 'should have a payment amount currency code' do
31
+ Factory.create_special_financial_institution_payment(:payment_amount_currency => 'CHF').segment1[109,3].should == 'CHF'
32
+ end
33
+
34
+ it 'should have a payment amount justified left filled with blanks' do
35
+ Factory.create_special_financial_institution_payment(:payment_amount => '3949.75').segment1[112,15].should == '3949.75'.ljust(15)
36
+ end
37
+
38
+ it 'should have a reserve field' do
39
+ Factory.create_special_financial_institution_payment.segment1[127,1].should == ' '.ljust(1)
40
+ end
41
+
42
+ it 'should have a total length of 128 characters' do
43
+ Factory.create_special_financial_institution_payment.segment1.size.should == 128
44
+ end
45
+ end
46
+
47
+ describe 'segment2' do
48
+ it 'should set the segment field to 02' do
49
+ Factory.create_special_financial_institution_payment.segment2[0,2].should == '02'
50
+ end
51
+
52
+ it 'should set the conversion rate if given' do
53
+ Factory.create_special_financial_institution_payment(:convertion_rate => '0.9543').segment2[2,12].should == '0.9543'.ljust(12)
54
+ end
55
+
56
+ it 'should have an ordering partys address line 1' do
57
+ Factory.create_special_financial_institution_payment(:ordering_partys_address_line1 => 'John Doe').segment2[14,24].should == 'John Doe'.ljust(24)
58
+ end
59
+
60
+ it 'should have an ordering partys address line 2' do
61
+ Factory.create_special_financial_institution_payment(:ordering_partys_address_line2 => 'Bahnhofstrasse 1').segment2[38,24].should == 'Bahnhofstrasse 1'.ljust(24)
62
+ end
63
+
64
+ it 'should have an ordering partys address line 3' do
65
+ Factory.create_special_financial_institution_payment(:ordering_partys_address_line3 => '8000 Zurich').segment2[62,24].should == '8000 Zurich'.ljust(24)
66
+ end
67
+
68
+ it 'should have an ordering partys address line 4' do
69
+ Factory.create_special_financial_institution_payment(:ordering_partys_address_line4 => 'Schweiz').segment2[86,24].should == 'Schweiz'.ljust(24)
70
+ end
71
+
72
+ it 'should have a reserve field' do
73
+ Factory.create_special_financial_institution_payment.segment2[110,18].should == ' '.ljust(18)
74
+ end
75
+
76
+ it 'should have a total length of 128 characters' do
77
+ Factory.create_special_financial_institution_payment.segment2.size.should == 128
78
+ end
79
+ end
80
+ describe 'segment3' do
81
+ it 'should set the segment field to 03' do
82
+ Factory.create_special_financial_institution_payment.segment3[0,2].should == '03'
83
+ end
84
+
85
+ it 'have an identification bank address' do
86
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'D').segment3[2,1].should == 'D'
87
+ end
88
+
89
+ it 'should have the beneficiarys bank account number' do
90
+ Factory.create_special_financial_institution_payment(:beneficiary_institution_bank_account_number =>'111222333').segment3[3,24].should == '/C/111222333'.ljust(24)
91
+ end
92
+
93
+ describe 'option A' do
94
+ it 'should must contain the 8- or 11-character BIC address (= SWIFT address) of the beneficiarys institution' do
95
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'A', :beneficiarys_institution_swift_address_ => 'BBBBLLRRNL2').segment3[27,24].should == 'BBBBLLRRNL2'.ljust(24)
96
+ end
97
+
98
+ it 'should leave lines 3 to 5 blank' do
99
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'A', :beneficiarys_institution_swift_address_ => 'BBBBLLRRNL2').segment3[51,72].should == ''.ljust(72)
100
+ end
101
+ end
102
+
103
+ describe 'option D' do
104
+ it 'should have a address line 1' do
105
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'D',:beneficiary_institution_address_line1 => 'Michael Recipient').segment3[27,24].should == 'Michael Recipient'.ljust(24)
106
+ end
107
+
108
+ it 'should have a beneficiary institution address line 2' do
109
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'D',:beneficiary_institution_address_line2 => 'Empfaengerstrasse 1').segment3[51,24].should == 'Empfaengerstrasse 1'.ljust(24)
110
+ end
111
+
112
+ it 'should have a beneficiary institution address line 3' do
113
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'D',:beneficiary_institution_address_line3 => '8640 Rapperswil').segment3[75,24].should == '8640 Rapperswil'.ljust(24)
114
+ end
115
+
116
+ it 'should have a beneficiary institution address line 4' do
117
+ Factory.create_special_financial_institution_payment(:identification_bank_address => 'D',:beneficiary_institution_address_line4 => 'Schweiz').segment3[99,24].should == 'Schweiz'.ljust(24)
118
+ end
119
+ end
120
+
121
+ it 'should have a reserve field' do
122
+ Factory.create_special_financial_institution_payment.segment3[123,5].should == ''.ljust(5)
123
+ end
124
+
125
+ it 'should have a total length of 128 characters' do
126
+ Factory.create_special_financial_institution_payment.segment3.size.should == 128
127
+ end
128
+ end
129
+ describe 'segment4' do
130
+ it 'should set the segment field to 04' do
131
+ Factory.create_special_financial_institution_payment.segment4[0,2].should == '04'
132
+ end
133
+
134
+ it 'should have the beneficiarys bank account number' do
135
+ Factory.create_special_financial_institution_payment(:beneficiary_bank_account_number =>'111222333').segment4[2,24].should == '/C/111222333'.ljust(24)
136
+ end
137
+
138
+ it 'should have a address line 1' do
139
+ Factory.create_special_financial_institution_payment(:beneficiary_address_line1 => 'Michael Recipient').segment4[26,24].should == 'Michael Recipient'.ljust(24)
140
+ end
141
+
142
+ it 'should have a beneficiary address line 2' do
143
+ Factory.create_special_financial_institution_payment(:beneficiary_address_line2 => 'Empfaengerstrasse 1').segment4[50,24].should == 'Empfaengerstrasse 1'.ljust(24)
144
+ end
145
+
146
+ it 'should have a beneficiary address line 3' do
147
+ Factory.create_special_financial_institution_payment(:beneficiary_address_line3 => '8640 Rapperswil').segment4[74,24].should == '8640 Rapperswil'.ljust(24)
148
+ end
149
+
150
+ it 'should have a beneficiary address line 4' do
151
+ Factory.create_special_financial_institution_payment(:beneficiary_address_line4 => 'Schweiz').segment4[98,24].should == 'Schweiz'.ljust(24)
152
+ end
153
+
154
+ it 'should have a reserve field' do
155
+ Factory.create_special_financial_institution_payment.segment4[122,6].should == ''.ljust(6)
156
+ end
157
+
158
+ it 'should have a total length of 128 characters' do
159
+ Factory.create_special_financial_institution_payment.segment4.size.should == 128
160
+ end
161
+ end
162
+
163
+ describe 'segment5' do
164
+ it 'should set the segment field to 05' do
165
+ Factory.create_special_financial_institution_payment.segment5[0,2].should == '05'
166
+ end
167
+
168
+ it "should have a beneficiary IBAN number" do
169
+ Factory.create_special_financial_institution_payment(:beneficiary_iban_number => 'CH3808888123456789012').segment5[2,34].should == 'CH3808888123456789012'.ljust(34)
170
+ end
171
+
172
+ it 'should have a reserve field' do
173
+ Factory.create_special_financial_institution_payment.segment5[36,92].should == ' '.ljust(92)
174
+ end
175
+
176
+ it 'should have a total length of 128 characters' do
177
+ Factory.create_special_financial_institution_payment.segment5.size.should == 128
178
+ end
179
+ end
180
+
181
+ describe 'segment6' do
182
+ it 'should set the segment field to 06' do
183
+ Factory.create_special_financial_institution_payment.segment6[0,2].should == '06'
184
+ end
185
+
186
+ it "should have an identification purpose" do
187
+ Factory.create_special_financial_institution_payment(:identification_purpose => 'I', :purpose_structured_reference_number => 'i3or6cev1wog5ez5og8j').segment6[2,1].should == 'I'
188
+ end
189
+
190
+ describe 'identification purpose is I' do
191
+ it 'should have a structured reference number' do
192
+ Factory.create_special_financial_institution_payment(:identification_purpose => 'I', :purpose_structured_reference_number => 'i3or6cev1wog5ez5og8j').segment6[3,105].should == 'i3or6cev1wog5ez5og8j'.ljust(105)
193
+ end
194
+ end
195
+
196
+ describe 'identification purpose is U' do
197
+ it 'should have a purpose text line 1' do
198
+ Factory.create_special_financial_institution_payment(:identification_purpose => 'U', :purpose_line_1 => 'LINE 1').segment6[3,35].should == 'LINE 1'.ljust(35)
199
+ end
200
+
201
+ it 'should have a purpose text line 2' do
202
+ Factory.create_special_financial_institution_payment(:identification_purpose => 'U', :purpose_line_2 => 'LINE 2').segment6[38,35].should == 'LINE 2'.ljust(35)
203
+ end
204
+
205
+ it 'should have a purpose text line 3' do
206
+ Factory.create_special_financial_institution_payment(:identification_purpose => 'U', :purpose_line_3 => 'LINE 3').segment6[73,35].should == 'LINE 3'.ljust(35)
207
+ end
208
+ end
209
+
210
+ it "should have a rule of charge" do
211
+ Factory.create_special_financial_institution_payment(:rule_of_charge => '2').segment6[108,1].should == '2'
212
+ end
213
+
214
+ it 'should have a reserve field' do
215
+ Factory.create_special_financial_institution_payment.segment6[114,11].should == ' '.ljust(11)
216
+ end
217
+
218
+ it 'should have a total length of 128 characters' do
219
+ Factory.create_special_financial_institution_payment.segment6.size.should == 128
220
+ end
221
+ end
222
+
223
+ describe 'comparison' do
224
+ it "should sort by issuer identification" do
225
+ @record1 = Factory.create_special_financial_institution_payment(:issuer_identification => "AAAAA")
226
+ @record2 = Factory.create_special_financial_institution_payment(:issuer_identification => "BBBBB")
227
+
228
+ (@record1 < @record2).should be_true
229
+ end
230
+
231
+ it "should sort by issuers clearing number when issuer identifications are equal" do
232
+ @record1 = Factory.create_special_financial_institution_payment(:issuer_identification => "AAAAA", :ordering_party_bank_clearing_number => '253')
233
+ @record2 = Factory.create_special_financial_institution_payment(:issuer_identification => "AAAAA", :ordering_party_bank_clearing_number => '254')
234
+
235
+ (@record1 < @record2).should be_true
236
+ end
237
+ end
238
+ end