aba 0.5.0 → 1.0.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 +14 -0
- data/README.md +10 -9
- data/aba.gemspec +2 -3
- data/lib/aba/batch.rb +9 -8
- data/lib/aba/entry.rb +2 -2
- data/lib/aba/return.rb +1 -2
- data/lib/aba/transaction.rb +4 -34
- data/lib/aba/validations.rb +7 -12
- data/lib/aba/version.rb +1 -1
- data/spec/lib/aba/batch_spec.rb +73 -41
- data/spec/lib/aba/return_spec.rb +34 -14
- data/spec/lib/aba/transaction_spec.rb +26 -13
- data/spec/lib/aba/validations_spec.rb +10 -14
- data/spec/spec_helper.rb +1 -0
- metadata +11 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b184fa383958c27a1a91ae83d9cee93318ac763928fbef9e9adbed2888ef122f
|
4
|
+
data.tar.gz: 663ac724030286eb6ee155b2e756c1a01f675549ee857eee9688b450a364ba9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64dadcc178a89b82eabcb89dcc3df12cdec4ecf4debea24714b45e25a8b8b9a7d711a2f12bd37746b902effd0aa347218f34545deb6b467b109faf5acaf0df1
|
7
|
+
data.tar.gz: 6d1b962350bd687c305668ab23d161878c9876f6560f2429c22cf204811d46b8c7f9c9b619bb6456c6c5a972c9d1f9b3e48ed7310cd270a83e9c9cdcea4503c7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
## v1.0.0, 12 July 2020
|
2
|
+
|
3
|
+
### BREAKING CHANGES
|
4
|
+
|
5
|
+
* Positive (`n`) and negative (`-n`) values are now treated the same.
|
6
|
+
e.g `5` and `-5` are both processed as `5`, without any signage.
|
7
|
+
To differentiate between a debit and credit, use the correct [Transaction Code](https://github.com/andrba/aba/blob/58446f5b0ef822e9792e9399b4af647319b13515/lib/aba/transaction.rb#L106-L112)
|
8
|
+
* Removed default values for transactions records to avoid generation of potentially incorrect records. Safety first!
|
9
|
+
* Minimum Ruby version is now 2.5
|
10
|
+
|
11
|
+
### NEW FEATURE
|
12
|
+
|
13
|
+
* You can now add a *return* record to be used when you'd like to return
|
14
|
+
a credit or a debit to another financial institution (OFI).
|
data/README.md
CHANGED
@@ -65,28 +65,29 @@ There are a few ways to create a complete set of ABA data:
|
|
65
65
|
```ruby
|
66
66
|
# Transactions added to the defined ABA object variable
|
67
67
|
aba = Aba.batch financial_institution: 'ANZ', user_name: 'Joe Blow', user_id: 123456, process_at: 200615
|
68
|
-
aba.add_transaction bsb: '123-456', account_number: '000-123-456', amount: 50000
|
69
|
-
aba.add_transaction bsb: '456-789', account_number: '123-456-789', amount:
|
68
|
+
aba.add_transaction bsb: '123-456', account_number: '000-123-456', amount: 50000, transaction_code: 50
|
69
|
+
aba.add_transaction bsb: '456-789', account_number: '123-456-789', amount: 10000, transaction_code: 13
|
70
70
|
|
71
71
|
# Transactions passed individually inside a block
|
72
72
|
aba = Aba.batch financial_institution: 'ANZ', user_name: 'Joe Blow', user_id: 123456, process_at: 200615 do |a|
|
73
|
-
a.add_transaction bsb: '123-456', account_number: '000-123-456', amount: 50000
|
74
|
-
a.add_transaction bsb: '456-789', account_number: '123-456-789', amount:
|
73
|
+
a.add_transaction bsb: '123-456', account_number: '000-123-456', amount: 50000, transaction_code: 50
|
74
|
+
a.add_transaction bsb: '456-789', account_number: '123-456-789', amount: 10000, transaction_code: 13
|
75
75
|
end
|
76
76
|
|
77
77
|
# Transactions as an array passed to the second param of Aba.batch
|
78
78
|
aba = Aba.batch(
|
79
79
|
{ financial_institution: 'ANZ', user_name: 'Joe Blow', user_id: 123456, process_at: 200615 },
|
80
80
|
[
|
81
|
-
{ bsb: '123-456', account_number: '000-123-456', amount: 50000 },
|
82
|
-
{ bsb: '456-789', account_number: '123-456-789', amount:
|
81
|
+
{ bsb: '123-456', account_number: '000-123-456', amount: 50000, transaction_code: 50 },
|
82
|
+
{ bsb: '456-789', account_number: '123-456-789', amount: 10000, transaction_code: 13 }
|
83
83
|
]
|
84
84
|
)
|
85
|
-
|
86
|
-
# NOTE: Be careful with negative transaction amounts! transaction_code will not
|
87
|
-
# be set to debit automatically!
|
88
85
|
```
|
89
86
|
|
87
|
+
> **Note:** Positive (`n`) and negative (`-n`) values are now treated the same.
|
88
|
+
> e.g `5` and `-5` are both processed as `5`, without any signage.
|
89
|
+
> To differentiate between a debit and credit, use the correct [Transaction Code](https://github.com/andrba/aba/blob/58446f5b0ef822e9792e9399b4af647319b13515/lib/aba/transaction.rb#L106-L112)
|
90
|
+
|
90
91
|
Validation errors can be caught in several ways:
|
91
92
|
|
92
93
|
```ruby
|
data/aba.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "
|
22
|
-
spec.add_development_dependency "
|
23
|
-
spec.add_development_dependency "pry"
|
21
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
22
|
+
spec.add_development_dependency "pry", "~> 0.13"
|
24
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
24
|
|
26
25
|
spec.required_ruby_version = '>= 2.5.0'
|
data/lib/aba/batch.rb
CHANGED
@@ -165,14 +165,15 @@ class Aba
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def batch_control_record
|
168
|
-
net_total_amount = 0
|
169
168
|
credit_total_amount = 0
|
170
169
|
debit_total_amount = 0
|
171
170
|
|
172
|
-
entries.each do |
|
173
|
-
|
174
|
-
|
175
|
-
|
171
|
+
entries.each do |entry|
|
172
|
+
if entry.debit?
|
173
|
+
debit_total_amount += Integer(entry.amount).abs
|
174
|
+
else
|
175
|
+
credit_total_amount += Integer(entry.amount).abs
|
176
|
+
end
|
176
177
|
end
|
177
178
|
|
178
179
|
# Record type
|
@@ -193,17 +194,17 @@ class Aba
|
|
193
194
|
# Net total
|
194
195
|
# Max: 10
|
195
196
|
# Char position: 21-30
|
196
|
-
output +=
|
197
|
+
output += (credit_total_amount - debit_total_amount).abs.to_s.rjust(10, "0")
|
197
198
|
|
198
199
|
# Credit Total Amount
|
199
200
|
# Max: 10
|
200
201
|
# Char position: 31-40
|
201
|
-
output += credit_total_amount.
|
202
|
+
output += credit_total_amount.to_s.rjust(10, "0")
|
202
203
|
|
203
204
|
# Debit Total Amount
|
204
205
|
# Max: 10
|
205
206
|
# Char position: 41-50
|
206
|
-
output += debit_total_amount.
|
207
|
+
output += debit_total_amount.to_s.rjust(10, "0")
|
207
208
|
|
208
209
|
# Reserved
|
209
210
|
# Max: 24
|
data/lib/aba/entry.rb
CHANGED
@@ -7,11 +7,11 @@ class Aba
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def credit?
|
10
|
-
|
10
|
+
Validations::CREDIT_TRANSACTION_CODES.include?(transaction_code.to_i)
|
11
11
|
end
|
12
12
|
|
13
13
|
def debit?
|
14
|
-
transaction_code.to_i
|
14
|
+
Validations::DEBIT_TRANSACTION_CODES.include?(transaction_code.to_i)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/aba/return.rb
CHANGED
@@ -20,7 +20,7 @@ class Aba
|
|
20
20
|
validates_transaction_code :transaction_code
|
21
21
|
|
22
22
|
# Amount
|
23
|
-
|
23
|
+
validates_integer :amount
|
24
24
|
|
25
25
|
# Original Day of Processing
|
26
26
|
validates_integer :original_processing_day, :unsigned
|
@@ -45,7 +45,6 @@ class Aba
|
|
45
45
|
validates_max_length :name_of_remitter, 16
|
46
46
|
validates_becs :name_of_remitter
|
47
47
|
|
48
|
-
|
49
48
|
# Allow dashes to be input, but remove them from output
|
50
49
|
def account_number
|
51
50
|
@account_number ? @account_number.to_s.delete('-') : nil
|
data/lib/aba/transaction.rb
CHANGED
@@ -19,7 +19,7 @@ class Aba
|
|
19
19
|
validates_transaction_code :transaction_code
|
20
20
|
|
21
21
|
# Amount
|
22
|
-
|
22
|
+
validates_integer :amount
|
23
23
|
|
24
24
|
# Account Name
|
25
25
|
validates_max_length :account_name, 32
|
@@ -37,51 +37,21 @@ class Aba
|
|
37
37
|
validates_max_length :name_of_remitter, 16
|
38
38
|
validates_becs :name_of_remitter
|
39
39
|
|
40
|
-
|
41
40
|
# Allow dashes to be input, but remove them from output
|
42
41
|
def account_number
|
43
42
|
@account_number ? @account_number.to_s.gsub('-', '') : nil
|
44
43
|
end
|
45
44
|
|
46
|
-
#
|
45
|
+
# Sane default for majority of use cases as per BECS
|
47
46
|
def indicator
|
48
|
-
@indicator ||
|
49
|
-
end
|
50
|
-
|
51
|
-
# Fall back to 50
|
52
|
-
def transaction_code
|
53
|
-
@transaction_code || 50
|
54
|
-
end
|
55
|
-
|
56
|
-
# Fall back to 0
|
57
|
-
def amount
|
58
|
-
@amount || 0
|
59
|
-
end
|
60
|
-
|
61
|
-
# Fall back to empty string
|
62
|
-
def account_name
|
63
|
-
@account_name || ''
|
47
|
+
@indicator || ' '
|
64
48
|
end
|
65
49
|
|
66
|
-
#
|
50
|
+
# Optional as per BECS
|
67
51
|
def lodgement_reference
|
68
52
|
@lodgement_reference || ''
|
69
53
|
end
|
70
54
|
|
71
|
-
# Fall back to BSB
|
72
|
-
def trace_bsb
|
73
|
-
@trace_bsb || bsb
|
74
|
-
end
|
75
|
-
|
76
|
-
# Fall back to Account Number
|
77
|
-
def trace_account_number
|
78
|
-
@trace_account_number ? @trace_account_number.to_s.gsub('-', '') : account_number
|
79
|
-
end
|
80
|
-
|
81
|
-
def name_of_remitter
|
82
|
-
@name_of_remitter || ''
|
83
|
-
end
|
84
|
-
|
85
55
|
def to_s
|
86
56
|
raise RuntimeError, 'Transaction data is invalid - check the contents of `errors`' unless valid?
|
87
57
|
|
data/lib/aba/validations.rb
CHANGED
@@ -4,6 +4,8 @@ class Aba
|
|
4
4
|
|
5
5
|
BECS_PATTERN = /\A[\w\+\-\@\ \$\!\%\&\(\)\*\.\/\#\=\:\;\?\,\'\[\]\_\^]*\Z/
|
6
6
|
INDICATORS = [' ', 'N', 'T', 'W', 'X', 'Y']
|
7
|
+
DEBIT_TRANSACTION_CODES = [13]
|
8
|
+
CREDIT_TRANSACTION_CODES = [50, 51, 52, 53, 54, 55, 56, 57]
|
7
9
|
|
8
10
|
def self.included(base)
|
9
11
|
base.instance_eval do
|
@@ -13,6 +15,10 @@ class Aba
|
|
13
15
|
base.send :extend, ClassMethods
|
14
16
|
end
|
15
17
|
|
18
|
+
def self.transaction_codes
|
19
|
+
DEBIT_TRANSACTION_CODES + CREDIT_TRANSACTION_CODES
|
20
|
+
end
|
21
|
+
|
16
22
|
def valid?
|
17
23
|
!has_errors?
|
18
24
|
end
|
@@ -46,12 +52,6 @@ class Aba
|
|
46
52
|
else
|
47
53
|
self.error_collection << "#{attribute} must be an unsigned number" unless value.to_s =~ /\A\d+\Z/
|
48
54
|
end
|
49
|
-
when :matches_transaction_code
|
50
|
-
if debit? && value.to_i > 0
|
51
|
-
self.error_collection << "#{attribute} is positive but the transaction type is a debit"
|
52
|
-
elsif credit? && value.to_i < 0
|
53
|
-
self.error_collection << "#{attribute} is negative but the transaction type is a credit"
|
54
|
-
end
|
55
55
|
when :account_number
|
56
56
|
if value.to_s =~ /\A[0\ ]+\Z/ || value.to_s !~ /\A[a-z\d\ ]{1,9}\Z/
|
57
57
|
self.error_collection << "#{attribute} must be a valid account number"
|
@@ -62,7 +62,7 @@ class Aba
|
|
62
62
|
list = INDICATORS.join('\', \'')
|
63
63
|
self.error_collection << "#{attribute} must be a one of '#{list}'" unless INDICATORS.include?(value.to_s)
|
64
64
|
when :transaction_code
|
65
|
-
self.error_collection << "#{attribute} must be
|
65
|
+
self.error_collection << "#{attribute} must be one of #{Validations.transaction_codes.join(', ')}" unless Validations.transaction_codes.include?(value.to_i)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -94,11 +94,6 @@ class Aba
|
|
94
94
|
add_validation_attribute(attribute, :integer, signed)
|
95
95
|
end
|
96
96
|
|
97
|
-
def validates_amount(attribute)
|
98
|
-
add_validation_attribute(attribute, :integer, true)
|
99
|
-
add_validation_attribute(attribute, :matches_transaction_code)
|
100
|
-
end
|
101
|
-
|
102
97
|
def validates_account_number(attribute)
|
103
98
|
add_validation_attribute(attribute, :account_number)
|
104
99
|
end
|
data/lib/aba/version.rb
CHANGED
data/spec/lib/aba/batch_spec.rb
CHANGED
@@ -3,38 +3,58 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe Aba::Batch do
|
6
|
-
subject(:batch)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
trace_account_number: '45656733', name_of_remitter: 'Remitter')
|
15
|
-
end
|
6
|
+
subject(:batch) do
|
7
|
+
Aba::Batch.new(
|
8
|
+
financial_institution: "WPC",
|
9
|
+
user_name: "John Doe",
|
10
|
+
user_id: "466364",
|
11
|
+
description: "Payroll",
|
12
|
+
process_at: "190615",
|
13
|
+
)
|
16
14
|
end
|
17
|
-
before { transactions.each { |trx| batch.add_transaction(trx) } }
|
18
|
-
|
19
|
-
let(:return_amounts) { [[53, 3], [13, -2]] }
|
20
|
-
let(:returns) do
|
21
|
-
return_amounts.map do |(transaction_code, amount)|
|
22
|
-
Aba::Return.new(bsb: '453-543', account_number: '45656733', amount: amount,
|
23
|
-
account_name: 'John Doe', transaction_code: transaction_code,
|
24
|
-
lodgement_reference: 'R435564', trace_bsb: '342-342',
|
25
|
-
trace_account_number: '3244654', name_of_remitter: 'Remitter',
|
26
|
-
return_code: 8, original_user_id: 654321,
|
27
|
-
original_processing_day: 12,
|
28
15
|
|
16
|
+
let(:transactions_attributes) { [{amount: 30, transaction_code: 50}, {amount: 20, transaction_code: 13}] }
|
17
|
+
let(:returns_attributes) { [{amount: 3, transaction_code: 50}, {amount: 2, transaction_code: 13}] }
|
18
|
+
|
19
|
+
before do
|
20
|
+
transactions_attributes.each do |attr|
|
21
|
+
transaction = Aba::Transaction.new(
|
22
|
+
bsb: '342-342',
|
23
|
+
account_number: '3244654',
|
24
|
+
amount: attr[:amount],
|
25
|
+
account_name: 'John Doe',
|
26
|
+
transaction_code: attr[:transaction_code],
|
27
|
+
lodgement_reference: 'R435564',
|
28
|
+
trace_bsb: '453-543',
|
29
|
+
trace_account_number: '45656733',
|
30
|
+
name_of_remitter: 'Remitter',
|
31
|
+
)
|
32
|
+
|
33
|
+
batch.add_transaction(transaction)
|
34
|
+
end
|
35
|
+
|
36
|
+
returns_attributes.map do |attr|
|
37
|
+
ret = Aba::Return.new(
|
38
|
+
bsb: '453-543',
|
39
|
+
account_number: '45656733',
|
40
|
+
amount: attr[:amount],
|
41
|
+
account_name: 'John Doe',
|
42
|
+
transaction_code: attr[:transaction_code],
|
43
|
+
lodgement_reference: 'R435564',
|
44
|
+
trace_bsb: '342-342',
|
45
|
+
trace_account_number: '3244654',
|
46
|
+
name_of_remitter: 'Remitter',
|
47
|
+
return_code: 8,
|
48
|
+
original_user_id: 654321,
|
49
|
+
original_processing_day: 12,
|
29
50
|
)
|
51
|
+
|
52
|
+
batch.add_return(ret)
|
30
53
|
end
|
31
54
|
end
|
32
|
-
before { returns.each { |trx| batch.add_return(trx) } }
|
33
55
|
|
34
56
|
describe "#to_s" do
|
35
|
-
|
36
57
|
context 'when descriptive record' do
|
37
|
-
|
38
58
|
context 'without bsb' do
|
39
59
|
it "should return a string containing the descriptive record without the bsb" do
|
40
60
|
expect(batch.to_s).to include("0 01WPC John Doe 466364Payroll 190615 \r\n")
|
@@ -43,6 +63,7 @@ describe Aba::Batch do
|
|
43
63
|
|
44
64
|
context 'with bsb' do
|
45
65
|
before { batch.bsb = "123-345" }
|
66
|
+
|
46
67
|
it "should return a string containing the descriptive record with the bsb" do
|
47
68
|
expect(batch.to_s).to include("0123-345 01WPC John Doe 466364Payroll 190615 \r\n")
|
48
69
|
end
|
@@ -51,50 +72,61 @@ describe Aba::Batch do
|
|
51
72
|
|
52
73
|
|
53
74
|
context 'when detail record' do
|
54
|
-
|
55
75
|
it "should contain transaction & return records" do
|
56
|
-
expect(batch.to_s).to include("1342-342 3244654
|
76
|
+
expect(batch.to_s).to include("1342-342 3244654 500000000030John Doe R435564 453-543 45656733Remitter 00000000\r\n")
|
57
77
|
expect(batch.to_s).to include("1342-342 3244654 130000000020John Doe R435564 453-543 45656733Remitter 00000000\r\n")
|
58
|
-
expect(batch.to_s).to include("2453-543
|
78
|
+
expect(batch.to_s).to include("2453-543 456567338500000000003John Doe R435564 342-342 3244654Remitter 12654321\r\n")
|
59
79
|
expect(batch.to_s).to include("2453-543 456567338130000000002John Doe R435564 342-342 3244654Remitter 12654321\r\n")
|
60
80
|
end
|
61
81
|
end
|
62
82
|
|
63
83
|
context 'when file total record' do
|
64
|
-
|
65
84
|
context 'with unbalanced transactions' do
|
66
85
|
it "should return a string where the net total is not zero" do
|
67
86
|
expect(batch.to_s).to include("7999-999 000000001100000000330000000022 000004 ")
|
87
|
+
# | Total || Credit || Debit |
|
68
88
|
end
|
69
89
|
end
|
70
90
|
|
71
91
|
context 'with balanced transactions' do
|
72
|
-
let(:
|
73
|
-
|
92
|
+
let(:transactions_attributes) do
|
93
|
+
[{amount: 30, transaction_code: 50}, {amount: 30, transaction_code: 13}, {amount: 30, transaction_code: 50}]
|
94
|
+
end
|
95
|
+
let(:returns_attributes) do
|
96
|
+
[{amount: 3, transaction_code: 50}, {amount: 3, transaction_code: 13}, {amount: 30, transaction_code: 13}]
|
97
|
+
end
|
98
|
+
|
74
99
|
it "should return a string where the net total is zero" do
|
75
|
-
expect(batch.to_s).to include("7999-999
|
100
|
+
expect(batch.to_s).to include("7999-999 000000000000000000630000000063 000006 ")
|
101
|
+
# | Total || Credit || Debit |
|
76
102
|
end
|
77
103
|
end
|
104
|
+
|
105
|
+
context 'with negative values supplied for the amounts' do
|
106
|
+
let(:transactions_attributes) { [{amount: -30, transaction_code: 50}, {amount: -20, transaction_code: 13}] }
|
107
|
+
let(:returns_attributes) { [{amount: -3, transaction_code: 50}, {amount: 2, transaction_code: 13}] }
|
108
|
+
|
109
|
+
it 'should return a string where the amount segments rely on the transaction code, not the amount sign' do
|
110
|
+
expect(batch.to_s).to include("7999-999 000000001100000000330000000022 000004 ")
|
111
|
+
# | Total || Credit || Debit |
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
78
115
|
end
|
79
116
|
end
|
80
117
|
|
81
118
|
describe "#errors" do
|
82
|
-
|
83
|
-
let(:errors) { subject.errors }
|
84
|
-
|
85
119
|
it "is empty" do
|
86
|
-
expect(errors).to be_nil
|
120
|
+
expect(batch.errors).to be_nil
|
87
121
|
end
|
88
122
|
|
89
123
|
context "with an invalid amount" do
|
90
|
-
let(:
|
91
|
-
[
|
124
|
+
let(:transactions_attributes) do
|
125
|
+
[{amount: 1, transaction_code: 50}, {amount: 'abc', transaction_code: 13}, {amount: 'def', transaction_code: 50}]
|
92
126
|
end
|
127
|
+
|
93
128
|
it "reports the errors" do
|
94
|
-
expect(errors).to eq(:entries => {
|
95
|
-
1 => ["amount is negative but the transaction type is a credit"],
|
96
|
-
2 => ["amount must be a number"]
|
97
|
-
})
|
129
|
+
expect(batch.errors).to eq(:entries => { 1 => ["amount must be a number"], 2 => ["amount must be a number"] })
|
98
130
|
end
|
99
131
|
end
|
100
132
|
end
|
data/spec/lib/aba/return_spec.rb
CHANGED
@@ -3,22 +3,26 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe Aba::Return do
|
6
|
-
let(:transaction_params) { {
|
7
|
-
:trace_account_number => 23432342,
|
8
|
-
:transaction_code => 53,
|
9
|
-
:amount => 50050,
|
10
|
-
:account_name => "John Doe",
|
11
|
-
:trace_bsb => "345-453",
|
12
|
-
:return_code => 8,
|
13
|
-
:lodgement_reference => "R45343",
|
14
|
-
:bsb => "123-234",
|
15
|
-
:account_number => "4647642",
|
16
|
-
:name_of_remitter => "Remitter",
|
17
|
-
:original_processing_day => "07",
|
18
|
-
:original_user_id => "054321",
|
19
|
-
} }
|
20
6
|
subject(:transaction) { Aba::Return.new(transaction_params) }
|
21
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
|
+
|
22
26
|
describe "#to_s" do
|
23
27
|
it "should create a transaction row" do
|
24
28
|
expect(subject.to_s).to include(
|
@@ -31,6 +35,22 @@ describe Aba::Return do
|
|
31
35
|
# | +-trace_bsb
|
32
36
|
# +-lodgement_reference
|
33
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
|
34
54
|
end
|
35
55
|
|
36
56
|
describe "#valid?" do
|
@@ -3,25 +3,38 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe Aba::Transaction do
|
6
|
-
let(:transaction_params) { {
|
7
|
-
:account_number => 23432342,
|
8
|
-
:transaction_code => 53,
|
9
|
-
:amount => 50050,
|
10
|
-
:account_name => "John Doe",
|
11
|
-
:bsb => "345-453",
|
12
|
-
:witholding_amount => 87,
|
13
|
-
:indicator => "W",
|
14
|
-
:lodgement_reference => "R45343",
|
15
|
-
:trace_bsb => "123-234",
|
16
|
-
:trace_account_number => "4647642",
|
17
|
-
:name_of_remitter => "Remitter"
|
18
|
-
} }
|
19
6
|
subject(:transaction) { Aba::Transaction.new(transaction_params) }
|
20
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
|
+
|
21
26
|
describe "#to_s" do
|
22
27
|
it "should create a transaction row" do
|
23
28
|
expect(subject.to_s).to include("1345-453 23432342W530000050050John Doe R45343 123-234 4647642Remitter 00000087")
|
24
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
|
25
38
|
end
|
26
39
|
|
27
40
|
describe "#valid?" do
|
@@ -180,35 +180,31 @@ describe Aba::Validations do
|
|
180
180
|
|
181
181
|
subject.attr1 = "$"
|
182
182
|
expect(subject.valid?).to eq false
|
183
|
-
list =
|
183
|
+
list = described_class::INDICATORS.join('\', \'')
|
184
184
|
expect(subject.errors).to eq ["attr1 must be a one of '#{list}'"]
|
185
185
|
|
186
|
-
subject.attr1 =
|
186
|
+
subject.attr1 = described_class::INDICATORS.sample
|
187
187
|
expect(subject.valid?).to eq true
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should validate transaction code" do
|
191
191
|
clean_room.instance_eval do
|
192
|
-
attr_accessor :
|
193
|
-
validates_transaction_code :
|
192
|
+
attr_accessor :transaction_code
|
193
|
+
validates_transaction_code :transaction_code
|
194
194
|
end
|
195
195
|
|
196
|
-
subject.
|
197
|
-
expect(subject.valid?).to eq false
|
198
|
-
expect(subject.errors).to eq ["attr1 must be a 2 digit number"]
|
199
|
-
|
200
|
-
subject.attr1 = "123"
|
196
|
+
subject.transaction_code = "AA"
|
201
197
|
expect(subject.valid?).to eq false
|
202
|
-
expect(subject.errors).to eq ["
|
198
|
+
expect(subject.errors).to eq ["transaction_code must be one of #{described_class::transaction_codes.join(', ')}"]
|
203
199
|
|
204
|
-
subject.
|
200
|
+
subject.transaction_code = "1"
|
205
201
|
expect(subject.valid?).to eq false
|
206
|
-
expect(subject.errors).to eq ["
|
202
|
+
expect(subject.errors).to eq ["transaction_code must be one of #{described_class::transaction_codes.join(', ')}"]
|
207
203
|
|
208
|
-
subject.
|
204
|
+
subject.transaction_code = "13"
|
209
205
|
expect(subject.valid?).to eq true
|
210
206
|
|
211
|
-
subject.
|
207
|
+
subject.transaction_code = 50
|
212
208
|
expect(subject.valid?).to eq true
|
213
209
|
end
|
214
210
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Bazhutkin
|
@@ -9,50 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-07-
|
12
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: rake
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
31
17
|
requirements:
|
32
|
-
- - "
|
18
|
+
- - "~>"
|
33
19
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
20
|
+
version: '13.0'
|
35
21
|
type: :development
|
36
22
|
prerelease: false
|
37
23
|
version_requirements: !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
|
-
- - "
|
25
|
+
- - "~>"
|
40
26
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
27
|
+
version: '13.0'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
29
|
name: pry
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
45
31
|
requirements:
|
46
|
-
- - "
|
32
|
+
- - "~>"
|
47
33
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
34
|
+
version: '0.13'
|
49
35
|
type: :development
|
50
36
|
prerelease: false
|
51
37
|
version_requirements: !ruby/object:Gem::Requirement
|
52
38
|
requirements:
|
53
|
-
- - "
|
39
|
+
- - "~>"
|
54
40
|
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
41
|
+
version: '0.13'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
43
|
name: rspec
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +64,7 @@ files:
|
|
78
64
|
- ".gitignore"
|
79
65
|
- ".rspec"
|
80
66
|
- ".travis.yml"
|
67
|
+
- CHANGELOG.md
|
81
68
|
- Gemfile
|
82
69
|
- LICENSE
|
83
70
|
- README.md
|