/
ach_file_spec.rb
130 lines (105 loc) · 3.29 KB
/
ach_file_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require 'spec_helper'
describe ACH::ACHFile do
subject :ach_file do
# Create ACH file
ach = ACH::ACHFile.new
# File Header
fh = ach.header
fh.immediate_destination = '000000000'
fh.immediate_destination_name = 'BANK NAME'
fh.immediate_origin = '000000000'
fh.immediate_origin_name = 'BANK NAME'
ach
end
def add_batch ach, entry_details = 0
batch = ACH::Batch.new
bh = batch.header
bh.company_name = 'Company Name'
bh.company_identification = '123456789'
bh.standard_entry_class_code = 'PPD'
bh.company_entry_description = 'DESCRIPTION'
bh.company_descriptive_date = Date.today
bh.effective_entry_date =
ACH::NextFederalReserveEffectiveDate.new(Date.today).result
bh.originating_dfi_identification = '00000000'
entry_details.times { add_detail(batch) }
ach.batches << batch
end
def add_detail batch
ed = ACH::EntryDetail.new
ed.transaction_code = ACH::CHECKING_CREDIT
ed.routing_number = '000000000'
ed.account_number = '00000000000'
ed.amount = 100 # In cents
ed.individual_id_number = 'Employee Name'
ed.individual_name = 'Employee Name'
ed.originating_dfi_identification = '00000000'
ed.trace_number = 1
batch.entries << ed
end
describe '#to_s' do
describe 'incrementing batch numbers' do
before(:each) do
add_batch ach_file, 1
add_batch ach_file, 1
add_batch ach_file, 1
end
context 'batch numbers not set' do
it 'increments batch numbers' do
lines = ach_file.to_s.split("\r\n")
expect(lines[1][-1]).to eq('1')
expect(lines[3][-1]).to eq('1')
expect(lines[4][-1]).to eq('2')
expect(lines[6][-1]).to eq('2')
expect(lines[7][-1]).to eq('3')
expect(lines[9][-1]).to eq('3')
end
end
end
describe 'padding with 9s' do
let(:nines) { '9' * 94 }
context 'number of records mod 10 is not 0' do
before(:each) do
add_batch ach_file, 3 # 7 records total
end
it 'pads with 9s' do
lines = ach_file.to_s.split("\r\n")
expect(lines.length).to eq(10)
lines[0..6].each do |line|
expect(line).to_not eq(nines)
end
lines[7..9].each do |line|
expect(line).to eq(nines)
end
add_batch ach_file, 5 # add 7 => 14 records total
lines = ach_file.to_s.split("\r\n")
expect(lines.length).to eq(20)
lines[0..13].each do |line|
expect(line).to_not eq(nines)
end
lines[14..19].each do |line|
expect(line).to eq(nines)
end
end
end
context 'number of records mod 10 is 0' do
before(:each) do
add_batch ach_file, 6 # 7 records total
end
it 'does not pad with 9s' do
lines = ach_file.to_s.split("\r\n")
expect(lines.length).to eq(10)
lines.each do |line|
expect(line).to_not eq(nines)
end
add_batch ach_file, 8 # plus batch header and footer
lines = ach_file.to_s.split("\r\n")
expect(lines.length).to eq(20)
lines.each do |line|
expect(line).to_not eq(nines)
end
end
end
end
end
end