bankserv 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,8 +15,12 @@ module Bankserv
15
15
  after_create :generate_internal_user_ref
16
16
 
17
17
  def generate_internal_user_ref
18
- self.internal_user_ref = "AHV#{id}"
19
- save!
18
+ self.internal_user_ref = Bankserv::AccountHolderVerification.generate_reference_number(self)
19
+ save!
20
+ end
21
+
22
+ def self.generate_reference_number(ahv)
23
+ "AHV#{ahv.id}"
20
24
  end
21
25
 
22
26
  def self.request(options = {})
@@ -89,7 +89,7 @@ module Bankserv
89
89
  def write_file!(document)
90
90
  begin
91
91
  transmission = Absa::H2h::Transmission::Document.build([document.to_hash])
92
- file_name = "INPUT.#{Time.now.strftime('%y%m%d%H%M%S')}.txt"
92
+ file_name = generate_input_file_name
93
93
  File.open("#{Bankserv::Engine.input_directory}/#{file_name}", 'w') { |f|
94
94
  f.puts transmission
95
95
  }
@@ -102,6 +102,10 @@ module Bankserv
102
102
  true
103
103
  end
104
104
 
105
+ def generate_input_file_name
106
+ "INPUT.#{Time.now.strftime('%y%m%d%H%M%S')}.txt"
107
+ end
108
+
105
109
  def archive_file!(file)
106
110
  year, month = Date.today.year, Date.today.month
107
111
 
@@ -4,6 +4,7 @@ module Bankserv
4
4
  self.inheritance_column = :_type_disabled
5
5
 
6
6
  belongs_to :set
7
+ has_many :sets
7
8
  serialize :error
8
9
 
9
10
  def mark_processed!
@@ -2,9 +2,9 @@ module Bankserv
2
2
 
3
3
  class Set < ActiveRecord::Base
4
4
  belongs_to :set
5
+ belongs_to :document
5
6
  has_many :sets
6
7
 
7
- has_one :document
8
8
  has_many :records
9
9
 
10
10
  def build_header(options = {})
@@ -43,7 +43,7 @@ module Bankserv
43
43
  records.each do |record|
44
44
  defaults = klass.record_type(record.record_type).template_options
45
45
  record.data = defaults.merge(record.data)
46
- record.data[:rec_status] = rec_status unless record.data[:rec_status]
46
+ record.data[:rec_status] ||= rec_status
47
47
  end
48
48
 
49
49
  self.records.each{|rec| rec.save!} # TODO: does this cause records to save before set?
@@ -1,3 +1,3 @@
1
1
  module Bankserv
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -104,6 +104,7 @@ class CreateBankservTables < ActiveRecord::Migration
104
104
  end
105
105
 
106
106
  create_table :bankserv_sets do |t|
107
+ t.references :document
107
108
  t.references :set
108
109
  t.string :type
109
110
  t.string :generation_number
@@ -0,0 +1,14 @@
1
+ 000L2012041012345TESTTEST 000000100000
2
+ 030L0000001506
3
+ 031L00000010000000090765462816570367799950JVAJEFFREY VAN ASWEGEN 00000000AHV70
4
+ 031L00000020000000090765462814956965800383JVAJEFFREY VAN ASWEGEN 00000000AHV73
5
+ 039L0000002000000018153092562
6
+ 030L0000002506
7
+ 031L00000010000000045304958348008456465340RC RC TRANSACTIONAL 00000000AHV67 250255000060LD00000000000000000
8
+ 031L00000020000000039243424238008456465340RC RC DEPOSIT 00000000AHV68 250255000060LD00000000000000000
9
+ 031L00000030000000620973636704662871445971DA DOUGLAS ANDERSON 00000000AHV69 250655000060LD00000000000000000
10
+ 031L00000040000000000704402131345940529631PDVPETER DE VILLIERS 00000000AHV71 020009000060LD00000000000000000
11
+ 031L00000050000000620973636704285493033498DA DOUGLAS ANDERSON 00000000AHV72 250655000060LD00000000000000000
12
+ 031L00000060000000000704402131116501771108PDVPETER DE VILLIERS 00000000AHV74 020009000060LD00000000000000000
13
+ 039L0000006000000132790446023
14
+ 999L000000014
@@ -103,6 +103,7 @@ ActiveRecord::Schema.define do
103
103
  end
104
104
 
105
105
  create_table :bankserv_sets, :force => true do |t|
106
+ t.references :document
106
107
  t.references :set
107
108
  t.string :type
108
109
  t.string :generation_number
@@ -16,7 +16,7 @@ describe Bankserv::Engine do
16
16
  end
17
17
 
18
18
  FileUtils.rm_rf(Dir.pwd + "/spec/examples/host2host/archives", secure: true)
19
-
19
+ File.delete(Dir.pwd + "/spec/tmp/harry.txt")
20
20
  end
21
21
 
22
22
  context "Prepare engine" do
@@ -134,4 +134,29 @@ describe Bankserv::Engine do
134
134
 
135
135
  end
136
136
 
137
+ context "processing ahv requests" do
138
+
139
+ before(:each) do
140
+ Timecop.travel(Time.local(2012, 4, 10, 10, 5, 0))
141
+ @tmpdir = Dir.pwd + "/spec/tmp"
142
+ tear_it_down
143
+ create(:configuration, client_code: "12345", client_name: "TESTTEST", user_code: "9999", user_generation_number: 1, client_abbreviated_name: "TESTTEST", department_code: "506")
144
+ Bankserv::EngineConfiguration.create!(interval_in_minutes: 15, input_directory: @tmpdir, output_directory: @tmpdir, archive_directory: @tmpdir)
145
+ end
146
+
147
+ it "should create a valid input document" do
148
+ Bankserv::AccountHolderVerification.should_receive(:generate_reference_number).exactly(8).times.and_return("AHV67","AHV68","AHV69","AHV70","AHV71","AHV72","AHV73","AHV74")
149
+ create_ahv_requests_scenario
150
+ e = Bankserv::Engine.new
151
+ e.should_receive(:generate_input_file_name).and_return("harry.txt")
152
+ e.process!
153
+
154
+ expected_string = File.open("./spec/examples/INPUT.120410144410.txt", "rb").read
155
+ got_string = File.open(@tmpdir + '/harry.txt', "rb").read
156
+
157
+ got_string.should == expected_string
158
+ end
159
+
160
+ end
161
+
137
162
  end
@@ -182,6 +182,25 @@ module Helpers
182
182
  }]
183
183
  }
184
184
  })
185
- end
185
+ end
186
+
187
+ def create_ahv_requests_scenario
188
+ info = {:data=>{:user_ref=>618, :bank_account=>{:account_number=>"4530495834", :id_number=>"8008456465340", :initials=>"RC", :account_name=>"RC Transactional", :branch_code=>"250255", :account_type=>"savings"}}}
189
+ Bankserv::AccountHolderVerification.request(info)
190
+ info = {:data=>{:user_ref=>619, :bank_account=>{:account_number=>"3924342423", :id_number=>"8008456465340", :initials=>"RC", :account_name=>"RC Deposit", :branch_code=>"250255", :account_type=>"savings"}}}
191
+ Bankserv::AccountHolderVerification.request(info)
192
+ info = {:data=>{:user_ref=>620, :bank_account=>{:account_number=>"62097363670", :id_number=>"4662871445971", :initials=>"DA", :account_name=>"Douglas Anderson", :branch_code=>"250655", :account_type=>"current"}}}
193
+ Bankserv::AccountHolderVerification.request(info)
194
+ info = {:data=>{:user_ref=>621, :bank_account=>{:account_number=>"9076546281", :id_number=>"6570367799950", :initials=>"JvA", :account_name=>"Jeffrey van Aswegen", :branch_code=>"632005", :account_type=>"savings"}}}
195
+ Bankserv::AccountHolderVerification.request(info)
196
+ info = {:data=>{:user_ref=>622, :bank_account=>{:account_number=>"070440213", :id_number=>"1345940529631", :initials=>"PDV", :account_name=>"Peter De Villiers", :branch_code=>"20009", :account_type=>"current"}}}
197
+ Bankserv::AccountHolderVerification.request(info)
198
+ info = {:data=>{:user_ref=>623, :bank_account=>{:account_number=>"62097363670", :id_number=>"4285493033498", :initials=>"DA", :account_name=>"Douglas Anderson", :branch_code=>"250655", :account_type=>"current"}}}
199
+ Bankserv::AccountHolderVerification.request(info)
200
+ info = {:data=>{:user_ref=>624, :bank_account=>{:account_number=>"9076546281", :id_number=>"4956965800383", :initials=>"JvA", :account_name=>"Jeffrey van Aswegen", :branch_code=>"632005", :account_type=>"savings"}}}
201
+ Bankserv::AccountHolderVerification.request(info)
202
+ info = {:data=>{:user_ref=>625, :bank_account=>{:account_number=>"070440213", :id_number=>"1116501771108", :initials=>"PDV", :account_name=>"Peter De Villiers", :branch_code=>"20009", :account_type=>"current"}}}
203
+ Bankserv::AccountHolderVerification.request(info)
204
+ end
186
205
  end
187
206
 
data/spec/tmp/readme ADDED
@@ -0,0 +1 @@
1
+ For git.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankserv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-04-10 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70246841198760 !ruby/object:Gem::Requirement
17
+ requirement: &70116524139980 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70246841198760
25
+ version_requirements: *70116524139980
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activerecord
28
- requirement: &70246841198220 !ruby/object:Gem::Requirement
28
+ requirement: &70116524139400 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70246841198220
36
+ version_requirements: *70116524139400
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &70246841197600 !ruby/object:Gem::Requirement
39
+ requirement: &70116524138840 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70246841197600
47
+ version_requirements: *70116524138840
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: absa-h2h
50
- requirement: &70246841197020 !ruby/object:Gem::Requirement
50
+ requirement: &70116524138220 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 0.1.1
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70246841197020
58
+ version_requirements: *70116524138220
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: absa-esd
61
- requirement: &70246841196320 !ruby/object:Gem::Requirement
61
+ requirement: &70116524137520 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.0.2
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70246841196320
69
+ version_requirements: *70116524137520
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: combustion
72
- requirement: &70246841195780 !ruby/object:Gem::Requirement
72
+ requirement: &70116524136940 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: 0.3.1
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70246841195780
80
+ version_requirements: *70116524136940
81
81
  description: ! "This engine allows users to inject requests into a queue to be processed.
82
82
  \n \n The queue handles bank account validations, credit payments,
83
83
  debit orders\n and collecting bank statements. "
@@ -128,6 +128,7 @@ files:
128
128
  - lib/core_extensions.rb
129
129
  - lib/generators/active_record/bankserv_generator.rb
130
130
  - lib/generators/active_record/templates/migration.rb
131
+ - spec/examples/INPUT.120410144410.txt
131
132
  - spec/examples/ahv_input_file.txt
132
133
  - spec/examples/ahv_output_file.txt
133
134
  - spec/examples/credit_eft_input.txt
@@ -162,6 +163,7 @@ files:
162
163
  - spec/lib/bankserv/transmission/statement_spec.rb
163
164
  - spec/spec_helper.rb
164
165
  - spec/support/helpers.rb
166
+ - spec/tmp/readme
165
167
  homepage: ''
166
168
  licenses: []
167
169
  post_install_message:
@@ -187,6 +189,7 @@ signing_key:
187
189
  specification_version: 3
188
190
  summary: A rails 3 engine wrapped around the Absa Host 2 Host gem.
189
191
  test_files:
192
+ - spec/examples/INPUT.120410144410.txt
190
193
  - spec/examples/ahv_input_file.txt
191
194
  - spec/examples/ahv_output_file.txt
192
195
  - spec/examples/credit_eft_input.txt
@@ -221,3 +224,4 @@ test_files:
221
224
  - spec/lib/bankserv/transmission/statement_spec.rb
222
225
  - spec/spec_helper.rb
223
226
  - spec/support/helpers.rb
227
+ - spec/tmp/readme