aba 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +3 -1
- data/.travis.yml +6 -0
- data/CHANGELOG.md +14 -0
- data/README.md +110 -18
- data/aba.gemspec +5 -5
- data/lib/aba.rb +6 -114
- data/lib/aba/batch.rb +225 -0
- data/lib/aba/entry.rb +17 -0
- data/lib/aba/return.rb +71 -0
- data/lib/aba/transaction.rb +69 -35
- data/lib/aba/validations.rb +79 -14
- data/lib/aba/version.rb +1 -1
- data/spec/lib/aba/batch_spec.rb +133 -0
- data/spec/lib/aba/return_spec.rb +67 -0
- data/spec/lib/aba/transaction_spec.rb +51 -0
- data/spec/lib/aba/validations_spec.rb +211 -0
- data/spec/lib/aba_spec.rb +21 -0
- data/spec/spec_helper.rb +3 -0
- metadata +29 -19
- data/spec/aba_spec.rb +0 -40
- data/spec/transaction_spec.rb +0 -37
- data/spec/validations_spec.rb +0 -47
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Aba::Return do
|
6
|
+
subject(:transaction) { Aba::Return.new(transaction_params) }
|
7
|
+
|
8
|
+
let(:transaction_attributes) { {amount: 50050, transaction_code: 53} }
|
9
|
+
let(:transaction_params) do
|
10
|
+
{
|
11
|
+
:trace_account_number => 23432342,
|
12
|
+
:transaction_code => transaction_attributes[:transaction_code],
|
13
|
+
:amount => transaction_attributes[:amount],
|
14
|
+
:account_name => "John Doe",
|
15
|
+
:trace_bsb => "345-453",
|
16
|
+
:return_code => 8,
|
17
|
+
:lodgement_reference => "R45343",
|
18
|
+
:bsb => "123-234",
|
19
|
+
:account_number => "4647642",
|
20
|
+
:name_of_remitter => "Remitter",
|
21
|
+
:original_processing_day => "07",
|
22
|
+
:original_user_id => "054321",
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#to_s" do
|
27
|
+
it "should create a transaction row" do
|
28
|
+
expect(subject.to_s).to include(
|
29
|
+
"2123-234 46476428530000050050John Doe R45343 345-453 23432342Remitter 07054321")
|
30
|
+
# | | || | | | | | | | |
|
31
|
+
# +-bsb | || +-amount +-account_name | | | | | +-original_user_id
|
32
|
+
# | |+-transaction_code | | | | +-original_processing_day
|
33
|
+
# | +-return_code | | | +-name_of_remitter
|
34
|
+
# +-account_number | | +-trace_account_number
|
35
|
+
# | +-trace_bsb
|
36
|
+
# +-lodgement_reference
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when supplied amount is negative' do
|
40
|
+
let(:transaction_attributes) { {amount: -50050, transaction_code: 53} }
|
41
|
+
|
42
|
+
it "should create a transaction row where the amount does not have a sign" do
|
43
|
+
expect(subject.to_s).to include(
|
44
|
+
"2123-234 46476428530000050050John Doe R45343 345-453 23432342Remitter 07054321")
|
45
|
+
# | | || | | | | | | | |
|
46
|
+
# +-bsb | || +-amount +-account_name | | | | | +-original_user_id
|
47
|
+
# | |+-transaction_code | | | | +-original_processing_day
|
48
|
+
# | +-return_code | | | +-name_of_remitter
|
49
|
+
# +-account_number | | +-trace_account_number
|
50
|
+
# | +-trace_bsb
|
51
|
+
# +-lodgement_reference
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#valid?" do
|
57
|
+
it "should be valid" do
|
58
|
+
expect(subject.valid?).to eq true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not be valid" do
|
62
|
+
transaction_params.delete(:bsb)
|
63
|
+
expect(subject.valid?).to eq false
|
64
|
+
expect(subject.errors).to eq ["bsb format is incorrect"]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Aba::Transaction do
|
6
|
+
subject(:transaction) { Aba::Transaction.new(transaction_params) }
|
7
|
+
|
8
|
+
let(:transaction_attributes) { {amount: 50050, transaction_code: 53} }
|
9
|
+
|
10
|
+
let(:transaction_params) do
|
11
|
+
{
|
12
|
+
:account_number => 23432342,
|
13
|
+
:transaction_code => transaction_attributes[:transaction_code],
|
14
|
+
:amount => transaction_attributes[:amount],
|
15
|
+
:account_name => "John Doe",
|
16
|
+
:bsb => "345-453",
|
17
|
+
:witholding_amount => 87,
|
18
|
+
:indicator => "W",
|
19
|
+
:lodgement_reference => "R45343",
|
20
|
+
:trace_bsb => "123-234",
|
21
|
+
:trace_account_number => "4647642",
|
22
|
+
:name_of_remitter => "Remitter",
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#to_s" do
|
27
|
+
it "should create a transaction row" do
|
28
|
+
expect(subject.to_s).to include("1345-453 23432342W530000050050John Doe R45343 123-234 4647642Remitter 00000087")
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when supplied amount is negative' do
|
32
|
+
let(:transaction_attributes) { {amount: -50050, transaction_code: 53} }
|
33
|
+
|
34
|
+
it "should create a transaction row where the amount does not have a sign" do
|
35
|
+
expect(subject.to_s).to include("1345-453 23432342W530000050050John Doe R45343 123-234 4647642Remitter 00000087")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#valid?" do
|
41
|
+
it "should be valid" do
|
42
|
+
expect(subject.valid?).to eq true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not be valid" do
|
46
|
+
transaction_params.delete(:bsb)
|
47
|
+
expect(subject.valid?).to eq false
|
48
|
+
expect(subject.errors).to eq ["bsb format is incorrect"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Aba::Validations do
|
6
|
+
let(:clean_room) do
|
7
|
+
Class.new(Object) do
|
8
|
+
include Aba::Validations
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
subject(:test_instance) { clean_room.new }
|
13
|
+
|
14
|
+
describe "#valid?" do
|
15
|
+
it "should validate presence of attrs" do
|
16
|
+
clean_room.instance_eval do
|
17
|
+
attr_accessor :attr1
|
18
|
+
validates_presence_of :attr1
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(subject.valid?).to eq false
|
22
|
+
expect(subject.errors).to eq ["attr1 is empty"]
|
23
|
+
|
24
|
+
subject.attr1 = "hello!"
|
25
|
+
expect(subject.valid?).to eq true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should validate bsb format" do
|
29
|
+
clean_room.instance_eval do
|
30
|
+
attr_accessor :attr1
|
31
|
+
validates_bsb :attr1
|
32
|
+
end
|
33
|
+
|
34
|
+
subject.attr1 = "234456"
|
35
|
+
expect(subject.valid?).to eq false
|
36
|
+
expect(subject.errors).to eq ["attr1 format is incorrect"]
|
37
|
+
|
38
|
+
subject.attr1 = "234-456"
|
39
|
+
expect(subject.valid?).to eq true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should validate max length" do
|
43
|
+
clean_room.instance_eval do
|
44
|
+
attr_accessor :attr1
|
45
|
+
validates_max_length :attr1, 5
|
46
|
+
end
|
47
|
+
|
48
|
+
subject.attr1 = "234456642"
|
49
|
+
expect(subject.valid?).to eq false
|
50
|
+
expect(subject.errors).to eq ["attr1 length must not exceed 5 characters"]
|
51
|
+
|
52
|
+
subject.attr1 = "23445"
|
53
|
+
expect(subject.valid?).to eq true
|
54
|
+
|
55
|
+
subject.attr1 = "2344"
|
56
|
+
expect(subject.valid?).to eq true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should validate length" do
|
60
|
+
clean_room.instance_eval do
|
61
|
+
attr_accessor :attr1
|
62
|
+
validates_length :attr1, 5
|
63
|
+
end
|
64
|
+
|
65
|
+
subject.attr1 = "234456642"
|
66
|
+
expect(subject.valid?).to eq false
|
67
|
+
expect(subject.errors).to eq ["attr1 length must be exactly 5 characters"]
|
68
|
+
|
69
|
+
subject.attr1 = "23445"
|
70
|
+
expect(subject.valid?).to eq true
|
71
|
+
|
72
|
+
subject.attr1 = "2344"
|
73
|
+
expect(subject.valid?).to eq false
|
74
|
+
expect(subject.errors).to eq ["attr1 length must be exactly 5 characters"]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should validate signed integer" do
|
78
|
+
clean_room.instance_eval do
|
79
|
+
attr_accessor :attr1
|
80
|
+
validates_integer :attr1
|
81
|
+
end
|
82
|
+
|
83
|
+
subject.attr1 = "+1234A"
|
84
|
+
expect(subject.valid?).to eq false
|
85
|
+
expect(subject.errors).to eq ["attr1 must be a number"]
|
86
|
+
|
87
|
+
subject.attr1 = "+1234"
|
88
|
+
expect(subject.valid?).to eq true
|
89
|
+
|
90
|
+
subject.attr1 = "-1234"
|
91
|
+
expect(subject.valid?).to eq true
|
92
|
+
|
93
|
+
subject.attr1 = "1234"
|
94
|
+
expect(subject.valid?).to eq true
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should validate unsigned integer" do
|
98
|
+
clean_room.instance_eval do
|
99
|
+
attr_accessor :attr1
|
100
|
+
validates_integer :attr1, false
|
101
|
+
end
|
102
|
+
|
103
|
+
subject.attr1 = "1234A"
|
104
|
+
expect(subject.valid?).to eq false
|
105
|
+
expect(subject.errors).to eq ["attr1 must be an unsigned number"]
|
106
|
+
|
107
|
+
subject.attr1 = "+1234"
|
108
|
+
expect(subject.valid?).to eq false
|
109
|
+
expect(subject.errors).to eq ["attr1 must be an unsigned number"]
|
110
|
+
|
111
|
+
subject.attr1 = "-1234"
|
112
|
+
expect(subject.valid?).to eq false
|
113
|
+
expect(subject.errors).to eq ["attr1 must be an unsigned number"]
|
114
|
+
|
115
|
+
subject.attr1 = "1234"
|
116
|
+
expect(subject.valid?).to eq true
|
117
|
+
|
118
|
+
subject.attr1 = 1234
|
119
|
+
expect(subject.valid?).to eq true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should validate account number" do
|
123
|
+
clean_room.instance_eval do
|
124
|
+
attr_accessor :attr1
|
125
|
+
validates_account_number :attr1
|
126
|
+
end
|
127
|
+
|
128
|
+
subject.attr1 = " "
|
129
|
+
expect(subject.valid?).to eq false
|
130
|
+
expect(subject.errors).to eq ["attr1 must be a valid account number"]
|
131
|
+
|
132
|
+
subject.attr1 = "000000"
|
133
|
+
expect(subject.valid?).to eq false
|
134
|
+
expect(subject.errors).to eq ["attr1 must be a valid account number"]
|
135
|
+
|
136
|
+
subject.attr1 = "00 0 0"
|
137
|
+
expect(subject.valid?).to eq false
|
138
|
+
expect(subject.errors).to eq ["attr1 must be a valid account number"]
|
139
|
+
|
140
|
+
subject.attr1 = "00 0A0"
|
141
|
+
expect(subject.valid?).to eq false
|
142
|
+
expect(subject.errors).to eq ["attr1 must be a valid account number"]
|
143
|
+
|
144
|
+
subject.attr1 = "00 111"
|
145
|
+
expect(subject.valid?).to eq true
|
146
|
+
|
147
|
+
subject.attr1 = "0a 111"
|
148
|
+
expect(subject.valid?).to eq true
|
149
|
+
|
150
|
+
subject.attr1 = "aaaaaa"
|
151
|
+
expect(subject.valid?).to eq true
|
152
|
+
|
153
|
+
subject.attr1 = "aa aaa"
|
154
|
+
expect(subject.valid?).to eq true
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should validate becs" do
|
158
|
+
clean_room.instance_eval do
|
159
|
+
attr_accessor :attr1
|
160
|
+
validates_becs :attr1
|
161
|
+
end
|
162
|
+
|
163
|
+
subject.attr1 = "abc123 é"
|
164
|
+
expect(subject.valid?).to eq false
|
165
|
+
expect(subject.errors).to eq ["attr1 must not contain invalid characters"]
|
166
|
+
|
167
|
+
subject.attr1 = "abc123 ~"
|
168
|
+
expect(subject.valid?).to eq false
|
169
|
+
expect(subject.errors).to eq ["attr1 must not contain invalid characters"]
|
170
|
+
|
171
|
+
subject.attr1 = "abc123"
|
172
|
+
expect(subject.valid?).to eq true
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should validate indicator" do
|
176
|
+
clean_room.instance_eval do
|
177
|
+
attr_accessor :attr1
|
178
|
+
validates_indicator :attr1
|
179
|
+
end
|
180
|
+
|
181
|
+
subject.attr1 = "$"
|
182
|
+
expect(subject.valid?).to eq false
|
183
|
+
list = described_class::INDICATORS.join('\', \'')
|
184
|
+
expect(subject.errors).to eq ["attr1 must be a one of '#{list}'"]
|
185
|
+
|
186
|
+
subject.attr1 = described_class::INDICATORS.sample
|
187
|
+
expect(subject.valid?).to eq true
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should validate transaction code" do
|
191
|
+
clean_room.instance_eval do
|
192
|
+
attr_accessor :transaction_code
|
193
|
+
validates_transaction_code :transaction_code
|
194
|
+
end
|
195
|
+
|
196
|
+
subject.transaction_code = "AA"
|
197
|
+
expect(subject.valid?).to eq false
|
198
|
+
expect(subject.errors).to eq ["transaction_code must be one of #{described_class::transaction_codes.join(', ')}"]
|
199
|
+
|
200
|
+
subject.transaction_code = "1"
|
201
|
+
expect(subject.valid?).to eq false
|
202
|
+
expect(subject.errors).to eq ["transaction_code must be one of #{described_class::transaction_codes.join(', ')}"]
|
203
|
+
|
204
|
+
subject.transaction_code = "13"
|
205
|
+
expect(subject.valid?).to eq true
|
206
|
+
|
207
|
+
subject.transaction_code = 50
|
208
|
+
expect(subject.valid?).to eq true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Aba do
|
6
|
+
describe ".batch" do
|
7
|
+
it "initialize instance of Aba::Batch with passed arguments" do
|
8
|
+
attributes = double.as_null_object
|
9
|
+
transactions = double.as_null_object
|
10
|
+
|
11
|
+
expect(Aba::Batch).to receive(:new).with(attributes, transactions)
|
12
|
+
described_class.batch(attributes, transactions)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns instance of Aba::Batch" do
|
16
|
+
obj = described_class.batch(double.as_null_object, double.as_null_object)
|
17
|
+
|
18
|
+
expect(obj).to be_a(Aba::Batch)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Bazhutkin
|
8
|
+
- Trevor Wistaff
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '13.0'
|
20
21
|
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '13.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: pry
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
+
version: '0.13'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
+
version: '0.13'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rspec
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,25 +56,33 @@ dependencies:
|
|
55
56
|
description: ABA (Australian Bankers Association) File Generator
|
56
57
|
email:
|
57
58
|
- andrey.bazhutkin@gmail.com
|
59
|
+
- trev@a07.com.au
|
58
60
|
executables: []
|
59
61
|
extensions: []
|
60
62
|
extra_rdoc_files: []
|
61
63
|
files:
|
62
64
|
- ".gitignore"
|
63
65
|
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CHANGELOG.md
|
64
68
|
- Gemfile
|
65
69
|
- LICENSE
|
66
70
|
- README.md
|
67
71
|
- Rakefile
|
68
72
|
- aba.gemspec
|
69
73
|
- lib/aba.rb
|
74
|
+
- lib/aba/batch.rb
|
75
|
+
- lib/aba/entry.rb
|
76
|
+
- lib/aba/return.rb
|
70
77
|
- lib/aba/transaction.rb
|
71
78
|
- lib/aba/validations.rb
|
72
79
|
- lib/aba/version.rb
|
73
|
-
- spec/
|
80
|
+
- spec/lib/aba/batch_spec.rb
|
81
|
+
- spec/lib/aba/return_spec.rb
|
82
|
+
- spec/lib/aba/transaction_spec.rb
|
83
|
+
- spec/lib/aba/validations_spec.rb
|
84
|
+
- spec/lib/aba_spec.rb
|
74
85
|
- spec/spec_helper.rb
|
75
|
-
- spec/transaction_spec.rb
|
76
|
-
- spec/validations_spec.rb
|
77
86
|
homepage: https://github.com/andrba/aba
|
78
87
|
licenses:
|
79
88
|
- MIT
|
@@ -86,20 +95,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
95
|
requirements:
|
87
96
|
- - ">="
|
88
97
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
98
|
+
version: 2.5.0
|
90
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
100
|
requirements:
|
92
101
|
- - ">="
|
93
102
|
- !ruby/object:Gem::Version
|
94
103
|
version: '0'
|
95
104
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.4.4
|
105
|
+
rubygems_version: 3.0.3
|
98
106
|
signing_key:
|
99
107
|
specification_version: 4
|
100
108
|
summary: ABA File Generator
|
101
109
|
test_files:
|
102
|
-
- spec/
|
110
|
+
- spec/lib/aba/batch_spec.rb
|
111
|
+
- spec/lib/aba/return_spec.rb
|
112
|
+
- spec/lib/aba/transaction_spec.rb
|
113
|
+
- spec/lib/aba/validations_spec.rb
|
114
|
+
- spec/lib/aba_spec.rb
|
103
115
|
- spec/spec_helper.rb
|
104
|
-
- spec/transaction_spec.rb
|
105
|
-
- spec/validations_spec.rb
|