aba 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2156c80e41e17a9df07891a515adff66f0b41412dd83897067a5faa1a598e956
4
- data.tar.gz: 853deb00316a156169fd1dbc81b5cea3b666122ff538fc61646fedb5bf44d15a
3
+ metadata.gz: c71962d082a5f069278f49f74ebeba542179be98dfe151ba74f6d348bee4b1f9
4
+ data.tar.gz: db6ce6a6b139f5ace5c1f386c779d629937c563e26dc541f97dc2f11734bf12e
5
5
  SHA512:
6
- metadata.gz: ccb0516b85f0b70af8374f8ef4a3f3effe157dcd19296283a2c274359926e567a9bf7120aad3cf784b4ae027f8bf9e4835edc3c02805d10ebca50d6feec4639e
7
- data.tar.gz: fbce1803cff67a9bbff99f6c91720b05e20fc62837e39f6d170438b3f6e3d47972b2f24dcf969788487b65078b0822570f488541091847ae8238d8e9eb7542fd
6
+ metadata.gz: 0c8bd0f8e21b4a911a439870df82b5663721d696a1d31a7e33fab9b8477c9d254202560c72952d8effc6df8b275653cf64b1b28daac1123f2ed0ac04b8749f1a
7
+ data.tar.gz: 204e6e3aa265fce388428b9ead10b510a1094d1030af3c19e1b75016fb00c78c510d31af782c24b9e13fabc0658ec28d42eee931f87ebfde3e92b58d18c30976
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- ## V1.0.1, 11 January 2021
1
+ # Changelog
2
+
3
+ ## v1.0.2, 25 July 2022
4
+
5
+ ### Added
6
+
7
+ - Enforce ABA validation:
8
+ - Amount (in cents) cannot exceed 10 characters.
9
+ - Total debit amount (in cents) cannot exceed 10 characters.
10
+ - Total credit amount (in cents) cannot exceed 10 characters.
11
+
12
+ ## v1.0.1, 11 January 2021
2
13
 
3
14
  ### BUG FIX
4
15
 
@@ -8,13 +19,15 @@ Account numbers/alphas validation should be case insensitive
8
19
 
9
20
  ### BREAKING CHANGES
10
21
 
11
- * Positive (`n`) and negative (`-n`) values are now treated the same.
12
- e.g `5` and `-5` are both processed as `5`, without any signage.
13
- 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)
14
- * Removed default values for transactions records to avoid generation of potentially incorrect records. Safety first!
15
- * Minimum Ruby version is now 2.5
22
+ - Positive (`n`) and negative (`-n`) values are now treated the same. e.g `5`
23
+ and `-5` are both processed as `5`, without any signage. To differentiate
24
+ between a debit and credit, use the correct [Transaction
25
+ Code](https://github.com/andrba/aba/blob/58446f5b0ef822e9792e9399b4af647319b13515/lib/aba/transaction.rb#L106-L112)
26
+ - Removed default values for transactions records to avoid generation of
27
+ potentially incorrect records. Safety first!
28
+ - Minimum Ruby version is now 2.5
16
29
 
17
30
  ### NEW FEATURE
18
31
 
19
- * You can now add a *return* record to be used when you'd like to return
20
- a credit or a debit to another financial institution (OFI).
32
+ - You can now add a *return* record to be used when you'd like to return a
33
+ credit or a debit to another financial institution (OFI).
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in aba.gemspec
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
data/aba.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
data/lib/aba/batch.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aba
2
4
  class Batch
3
5
  include Aba::Validations
@@ -28,6 +30,9 @@ class Aba
28
30
  validates_length :process_at, 6
29
31
  validates_integer :process_at, false
30
32
 
33
+ # Totals
34
+ validates_max_length :debit_total_amount, 10
35
+ validates_max_length :credit_total_amount, 10
31
36
 
32
37
  def initialize(attrs = {}, transactions = [])
33
38
  attrs.each do |key, value|
@@ -87,7 +92,10 @@ class Aba
87
92
  # Build errors
88
93
  all_errors = {}
89
94
  all_errors[:aba] = self.error_collection unless self.error_collection.empty?
90
- entry_error_collection = entries.each_with_index.map { |t, i| [i, t.error_collection] }.reject { |e| e[1].nil? || e[1].empty? }.to_h
95
+ entry_error_collection = entries.each_with_index
96
+ .map { |t, i| [i, t.error_collection] }
97
+ .reject { |e| e[1].nil? || e[1].empty? }
98
+ .to_h
91
99
  all_errors[:entries] = entry_error_collection unless entry_error_collection.empty?
92
100
 
93
101
  all_errors unless all_errors.empty?
@@ -165,16 +173,8 @@ class Aba
165
173
  end
166
174
 
167
175
  def batch_control_record
168
- credit_total_amount = 0
169
- debit_total_amount = 0
170
-
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
177
- end
176
+ cached_credit_total_amount = credit_total_amount
177
+ cached_debit_total_amount = debit_total_amount
178
178
 
179
179
  # Record type
180
180
  # Max: 1
@@ -194,17 +194,17 @@ class Aba
194
194
  # Net total
195
195
  # Max: 10
196
196
  # Char position: 21-30
197
- output += (credit_total_amount - debit_total_amount).abs.to_s.rjust(10, "0")
197
+ output += (cached_credit_total_amount - cached_debit_total_amount).abs.to_s.rjust(10, "0")
198
198
 
199
199
  # Credit Total Amount
200
200
  # Max: 10
201
201
  # Char position: 31-40
202
- output += credit_total_amount.to_s.rjust(10, "0")
202
+ output += cached_credit_total_amount.to_s.rjust(10, "0")
203
203
 
204
204
  # Debit Total Amount
205
205
  # Max: 10
206
206
  # Char position: 41-50
207
- output += debit_total_amount.to_s.rjust(10, "0")
207
+ output += cached_debit_total_amount.to_s.rjust(10, "0")
208
208
 
209
209
  # Reserved
210
210
  # Max: 24
@@ -221,5 +221,17 @@ class Aba
221
221
  # Char position: 81-120
222
222
  output += " " * 40
223
223
  end
224
+
225
+ def credit_total_amount
226
+ credit_total_amount ||= entries.reject(&:debit?).sum(&method(:entry_amount))
227
+ end
228
+
229
+ def debit_total_amount
230
+ entries.select(&:debit?).sum(&method(:entry_amount))
231
+ end
232
+
233
+ def entry_amount(entry)
234
+ entry.amount.to_s[/\A\-?\d+\z/] ? Integer(entry.amount).abs : 0
235
+ end
224
236
  end
225
237
  end
data/lib/aba/entry.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aba
2
4
  class Entry
3
5
  def initialize(attrs = {})
data/lib/aba/return.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aba
2
4
  class Return < Entry
3
5
  include Aba::Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aba
2
4
  class Transaction < Entry
3
5
  include Aba::Validations
@@ -20,6 +22,7 @@ class Aba
20
22
 
21
23
  # Amount
22
24
  validates_integer :amount
25
+ validates_max_length :amount, 10
23
26
 
24
27
  # Account Name
25
28
  validates_max_length :account_name, 32
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aba
2
4
  module Validations
3
5
  attr_accessor :error_collection
data/lib/aba/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Aba
2
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
3
5
  end
data/lib/aba.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "aba/version"
2
4
  require "aba/validations"
3
5
  require "aba/entry"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding: UTF-8
2
4
 
3
5
  require "spec_helper"
@@ -129,5 +131,31 @@ describe Aba::Batch do
129
131
  expect(batch.errors).to eq(:entries => { 1 => ["amount must be a number"], 2 => ["amount must be a number"] })
130
132
  end
131
133
  end
134
+
135
+ context "with an invalid credit total (exceeding 10 characters)" do
136
+ let(:transactions_attributes) do
137
+ [
138
+ {amount: 9999999999, transaction_code: 50},
139
+ {amount: 9999999999, transaction_code: 50},
140
+ ]
141
+ end
142
+
143
+ it "reports the errors" do
144
+ expect(batch.errors).to include(aba: ["credit_total_amount length must not exceed 10 characters"])
145
+ end
146
+ end
147
+
148
+ context "with an invalid debit total amount (exceeding 10 characters)" do
149
+ let(:transactions_attributes) do
150
+ [
151
+ {amount: 9999999999, transaction_code: 13},
152
+ {amount: 9999999999, transaction_code: 13},
153
+ ]
154
+ end
155
+
156
+ it "reports the errors" do
157
+ expect(batch.errors).to include(aba: ["debit_total_amount length must not exceed 10 characters"])
158
+ end
159
+ end
132
160
  end
133
161
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding: UTF-8
2
4
 
3
5
  require "spec_helper"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding: UTF-8
2
4
 
3
5
  require "spec_helper"
@@ -42,10 +44,31 @@ describe Aba::Transaction do
42
44
  expect(subject.valid?).to eq true
43
45
  end
44
46
 
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"]
47
+ context "without bsb param" do
48
+ before do
49
+ transaction_params.delete(:bsb)
50
+ end
51
+
52
+ it "is invalid" do
53
+ expect(subject.valid?).to eq false
54
+ expect(subject.errors).to eq ["bsb format is incorrect"]
55
+ end
56
+ end
57
+
58
+ describe ":amount" do
59
+ subject(:transaction) { Aba::Transaction.new(transaction_params.merge(amount: amount)) }
60
+
61
+ context "with 10 digits" do
62
+ let(:amount) { "1234567890" }
63
+
64
+ it { is_expected.to be_valid }
65
+ end
66
+
67
+ context "with 11 digits" do
68
+ let(:amount) { "12345678901" }
69
+
70
+ it { is_expected.not_to be_valid }
71
+ end
49
72
  end
50
73
  end
51
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding: UTF-8
2
4
 
3
5
  require "spec_helper"
data/spec/lib/aba_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding: UTF-8
2
4
 
3
5
  require "spec_helper"
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  Bundler.setup
3
5
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Bazhutkin
8
8
  - Trevor Wistaff
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-11 00:00:00.000000000 Z
12
+ date: 2022-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -87,7 +87,7 @@ homepage: https://github.com/andrba/aba
87
87
  licenses:
88
88
  - MIT
89
89
  metadata: {}
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.0.3
106
- signing_key:
105
+ rubygems_version: 3.1.6
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: ABA File Generator
109
109
  test_files: