ofx_br 0.3.3 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/lib/{ofx_br → ofx}/parser/ofx102.rb +13 -8
- data/lib/{ofx_br → ofx}/parser.rb +1 -3
- data/lib/ofx/statement.rb +11 -0
- data/lib/{ofx_br → ofx}/version.rb +1 -1
- data/lib/ofx.rb +34 -0
- data/spec/{ofx_br → ofx}/ofx102_spec.rb +1 -1
- data/spec/{ofx_br → ofx}/ofx_parser_spec.rb +53 -18
- data/spec/{ofx_br → ofx}/transaction_spec.rb +53 -34
- data/spec/spec_helper.rb +8 -3
- metadata +82 -87
- data/.github/dependabot.yml +0 -13
- data/.gitignore +0 -4
- data/.rspec +0 -1
- data/.travis.yml +0 -9
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -50
- data/lib/ofx_br/parser/ofx103.rb +0 -7
- data/lib/ofx_br/statement.rb +0 -5
- data/lib/ofx_br.rb +0 -33
- data/ofx_br.gemspec +0 -32
- data/spec/fixtures/avatar.gif +0 -0
- data/spec/fixtures/bb.ofx +0 -700
- data/spec/fixtures/bradesco.ofx +0 -96
- data/spec/fixtures/creditcard.ofx +0 -79
- data/spec/fixtures/dtsof_balance_issue.ofx +0 -54
- data/spec/fixtures/error.ofx +0 -24
- data/spec/fixtures/invalid_version.ofx +0 -308
- data/spec/fixtures/nd-amex-sample.ofx +0 -12
- data/spec/fixtures/sample.ofx +0 -315
- data/spec/fixtures/santander.ofx +0 -91
- data/spec/fixtures/utf8.ofx +0 -308
- data/spec/fixtures/v103.ofx +0 -80
- data/spec/fixtures/v211.ofx +0 -85
- data/spec/ofx_br/ofx103_spec.rb +0 -50
- /data/lib/{ofx_br → ofx}/account.rb +0 -0
- /data/lib/{ofx_br → ofx}/balance.rb +0 -0
- /data/lib/{ofx_br → ofx}/errors.rb +0 -0
- /data/lib/{ofx_br → ofx}/foundation.rb +0 -0
- /data/lib/{ofx_br → ofx}/parser/ofx211.rb +0 -0
- /data/lib/{ofx_br → ofx}/sign_on.rb +0 -0
- /data/lib/{ofx_br → ofx}/status.rb +0 -0
- /data/lib/{ofx_br → ofx}/transaction.rb +0 -0
- /data/spec/{ofx_br → ofx}/account_spec.rb +0 -0
- /data/spec/{ofx_br → ofx}/ofx211_spec.rb +0 -0
- /data/spec/{ofx_br → ofx}/ofx_spec.rb +0 -0
- /data/spec/{ofx_br → ofx}/sign_on_spec.rb +0 -0
- /data/spec/{ofx_br → ofx}/statement_spec.rb +0 -0
- /data/spec/{ofx_br → ofx}/status_spec.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cdedb8184f7321dcbae5c63eb80b1eabadf9c2543d383dfa89ffdd0a46c512fb
|
|
4
|
+
data.tar.gz: 27e6a3b16b2a703a260dde990c8afc1549d5d16389d52fa1da88a3255b150b5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d312c4e19283da6d4bab75b0a1989a9e579a94e83ecfbbca8c672a267e3636769586709cbf681174aaded45b5f7fdc6d372390ae30f7577d8381d9f488d73cbb
|
|
7
|
+
data.tar.gz: 01b7e02a8b575cbe51bb3b2da3c06277defc1d114cd5a5ced0ad64f8b1f426fde9235679f111421bd368ee4f90a9433c8da91e59248c512fdd1364b12239e5d2
|
data/README.rdoc
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
= OFX
|
|
2
2
|
|
|
3
|
-
{<img src="https://badge.fury.io/rb/ofx.
|
|
4
|
-
{<img src="https://
|
|
3
|
+
{<img src="https://badge.fury.io/rb/ofx.svg" alt="Gem Version" />}[https://badge.fury.io/rb/ofx]
|
|
4
|
+
{<img src="https://github.com/annacruz/ofx/actions/workflows/config.yml/badge.svg" alt="Build Status" />}[https://github.com/annacruz/ofx/actions]
|
|
5
5
|
|
|
6
6
|
A simple OFX (Open Financial Exchange) parser built on top of Nokogiri. Currently supports both OFX 1.0.2 and 2.1.1.
|
|
7
7
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module OFX
|
|
2
4
|
module Parser
|
|
3
5
|
class OFX102
|
|
@@ -8,28 +10,27 @@ module OFX
|
|
|
8
10
|
'SAVINGS' => :savings,
|
|
9
11
|
'CREDITLINE' => :creditline,
|
|
10
12
|
'MONEYMRKT' => :moneymrkt
|
|
11
|
-
}
|
|
13
|
+
}.freeze
|
|
12
14
|
|
|
13
15
|
TRANSACTION_TYPES = %w[
|
|
14
16
|
ATM CASH CHECK CREDIT DEBIT DEP DIRECTDEBIT DIRECTDEP DIV
|
|
15
|
-
FEE INT OTHER PAYMENT POS REPEATPMT SRVCHG XFER
|
|
16
|
-
].each_with_object({})
|
|
17
|
+
FEE INT OTHER PAYMENT POS REPEATPMT SRVCHG XFER IN OUT
|
|
18
|
+
].each_with_object({}) do |tran_type, hash|
|
|
19
|
+
hash[tran_type] = tran_type.downcase.to_sym
|
|
20
|
+
end
|
|
17
21
|
|
|
18
22
|
SEVERITY = {
|
|
19
23
|
'INFO' => :info,
|
|
20
24
|
'WARN' => :warn,
|
|
21
25
|
'ERROR' => :error
|
|
22
|
-
}
|
|
26
|
+
}.freeze
|
|
23
27
|
|
|
24
|
-
attr_reader :headers, :body, :html
|
|
28
|
+
attr_reader :headers, :body, :html
|
|
25
29
|
|
|
26
30
|
def initialize(options = {})
|
|
27
31
|
@headers = options[:headers]
|
|
28
32
|
@body = options[:body]
|
|
29
33
|
@html = Nokogiri::HTML.parse(body)
|
|
30
|
-
|
|
31
|
-
@date_start ||= build_date(@html.search('banktranlist > dtstart').inner_text)
|
|
32
|
-
@date_end ||= build_date(@html.search('banktranlist > dtend').inner_text)
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
def statements
|
|
@@ -72,6 +73,8 @@ module OFX
|
|
|
72
73
|
account = build_account(node)
|
|
73
74
|
OFX::Statement.new(
|
|
74
75
|
currency: stmrs_node.search('curdef').inner_text,
|
|
76
|
+
start_date: build_date(stmrs_node.search('banktranlist > dtstart').inner_text),
|
|
77
|
+
end_date: build_date(stmrs_node.search('banktranlist > dtend').inner_text),
|
|
75
78
|
account: account,
|
|
76
79
|
transactions: account.transactions,
|
|
77
80
|
balance: account.balance,
|
|
@@ -195,6 +198,8 @@ module OFX
|
|
|
195
198
|
|
|
196
199
|
def to_decimal(amount)
|
|
197
200
|
BigDecimal(amount.to_s.gsub(',', '.'))
|
|
201
|
+
rescue ArgumentError
|
|
202
|
+
BigDecimal('0.0')
|
|
198
203
|
end
|
|
199
204
|
end
|
|
200
205
|
end
|
|
@@ -17,10 +17,8 @@ module OFX
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
case headers["VERSION"]
|
|
20
|
-
when /102/ then
|
|
20
|
+
when /100|102|103/ then
|
|
21
21
|
@parser = OFX102.new(:headers => headers, :body => body)
|
|
22
|
-
when /103/ then
|
|
23
|
-
@parser = OFX103.new(:headers => headers, :body => body)
|
|
24
22
|
when /200|202|211|220/ then
|
|
25
23
|
@parser = OFX211.new(:headers => headers, :body => body)
|
|
26
24
|
else
|
data/lib/ofx.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
require 'nokogiri'
|
|
5
|
+
require 'bigdecimal'
|
|
6
|
+
|
|
7
|
+
require 'kconv'
|
|
8
|
+
|
|
9
|
+
require 'ofx/errors'
|
|
10
|
+
require 'ofx/parser'
|
|
11
|
+
require 'ofx/parser/ofx102'
|
|
12
|
+
require 'ofx/parser/ofx211'
|
|
13
|
+
require 'ofx/foundation'
|
|
14
|
+
require 'ofx/balance'
|
|
15
|
+
require 'ofx/account'
|
|
16
|
+
require 'ofx/sign_on'
|
|
17
|
+
require 'ofx/status'
|
|
18
|
+
require 'ofx/statement'
|
|
19
|
+
require 'ofx/transaction'
|
|
20
|
+
require 'ofx/version'
|
|
21
|
+
|
|
22
|
+
def OFX(resource, &block)
|
|
23
|
+
parser = OFX::Parser::Base.new(resource).parser
|
|
24
|
+
|
|
25
|
+
if block_given?
|
|
26
|
+
if block.arity == 1
|
|
27
|
+
yield parser
|
|
28
|
+
else
|
|
29
|
+
parser.instance_eval(&block)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
parser
|
|
34
|
+
end
|
|
@@ -39,7 +39,7 @@ describe OFX::Parser::OFX102 do
|
|
|
39
39
|
it "should know about all transaction types" do
|
|
40
40
|
valid_types = [
|
|
41
41
|
'CREDIT', 'DEBIT', 'INT', 'DIV', 'FEE', 'SRVCHG', 'DEP', 'ATM', 'POS', 'XFER',
|
|
42
|
-
'CHECK', 'PAYMENT', 'CASH', 'DIRECTDEP', 'DIRECTDEBIT', 'REPEATPMT', 'OTHER'
|
|
42
|
+
'CHECK', 'PAYMENT', 'CASH', 'DIRECTDEP', 'DIRECTDEBIT', 'REPEATPMT', 'OTHER', 'IN', 'OUT'
|
|
43
43
|
]
|
|
44
44
|
valid_types.sort.should == OFX::Parser::OFX102::TRANSACTION_TYPES.keys.sort
|
|
45
45
|
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe OFX::Parser do
|
|
4
|
+
def ofx_example_to(version)
|
|
5
|
+
<<~OFX_CONTENT
|
|
6
|
+
<?xml version="1.0" encoding="US-ASCII"?>
|
|
7
|
+
|
|
8
|
+
<?OFX OFXHEADER="200" VERSION="#{version}" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>"
|
|
9
|
+
|
|
10
|
+
<OFX>
|
|
11
|
+
</OFX>
|
|
12
|
+
OFX_CONTENT
|
|
13
|
+
end
|
|
14
|
+
|
|
4
15
|
before do
|
|
5
16
|
@ofx = OFX::Parser::Base.new("spec/fixtures/sample.ofx")
|
|
6
17
|
end
|
|
@@ -47,18 +58,53 @@ describe OFX::Parser do
|
|
|
47
58
|
}.should raise_error(OFX::UnsupportedFileError)
|
|
48
59
|
end
|
|
49
60
|
|
|
61
|
+
it "should use 102 parser to parse version 100 ofx files" do
|
|
62
|
+
expect(OFX::Parser::OFX102).to receive(:new).and_return('ofx-102-parser')
|
|
63
|
+
|
|
64
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('100'))
|
|
65
|
+
expect(ofx.parser).to eql 'ofx-102-parser'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should use 102 parser to parse version 102 ofx files" do
|
|
69
|
+
expect(OFX::Parser::OFX102).to receive(:new).and_return('ofx-102-parser')
|
|
70
|
+
|
|
71
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('102'))
|
|
72
|
+
expect(ofx.parser).to eql 'ofx-102-parser'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should use 102 parser to parse version 103 ofx files" do
|
|
76
|
+
expect(OFX::Parser::OFX102).to receive(:new).and_return('ofx-102-parser')
|
|
77
|
+
|
|
78
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('103'))
|
|
79
|
+
expect(ofx.parser).to eql 'ofx-102-parser'
|
|
80
|
+
end
|
|
81
|
+
|
|
50
82
|
it "should use 211 parser to parse version 200 ofx files" do
|
|
51
|
-
OFX::Parser::OFX211.
|
|
52
|
-
|
|
83
|
+
expect(OFX::Parser::OFX211).to receive(:new).and_return('ofx-211-parser')
|
|
84
|
+
|
|
85
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('200'))
|
|
53
86
|
ofx.parser.should == 'ofx-211-parser'
|
|
54
87
|
end
|
|
55
88
|
|
|
56
89
|
it "should use 211 parser to parse version 202 ofx files" do
|
|
57
90
|
OFX::Parser::OFX211.stub(:new).and_return('ofx-211-parser')
|
|
58
|
-
ofx = OFX::Parser::Base.new(
|
|
91
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('202'))
|
|
59
92
|
ofx.parser.should == 'ofx-211-parser'
|
|
60
93
|
end
|
|
61
94
|
|
|
95
|
+
it "should use 211 parser to parse version 211 ofx files" do
|
|
96
|
+
OFX::Parser::OFX211.stub(:new).and_return('ofx-211-parser')
|
|
97
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('211'))
|
|
98
|
+
ofx.parser.should == 'ofx-211-parser'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should use 211 parser to parse version 220 ofx files" do
|
|
102
|
+
expect(OFX::Parser::OFX211).to receive(:new).and_return('ofx-211-parser')
|
|
103
|
+
|
|
104
|
+
ofx = OFX::Parser::Base.new(ofx_example_to('220'))
|
|
105
|
+
expect(ofx.parser).to eql 'ofx-211-parser'
|
|
106
|
+
end
|
|
107
|
+
|
|
62
108
|
describe "headers" do
|
|
63
109
|
it "should have OFXHEADER" do
|
|
64
110
|
@ofx.headers["OFXHEADER"].should == "100"
|
|
@@ -101,23 +147,12 @@ describe OFX::Parser do
|
|
|
101
147
|
end
|
|
102
148
|
|
|
103
149
|
it "should parse headers with CR and without LF" do
|
|
150
|
+
header = %{OFXHEADER:100\rDATA:OFXSGML\rVERSION:102\rSECURITY:NONE\rENCODING:USASCII\rCHARSET:1252\rCOMPRESSION:NONE\rOLDFILEUID:NONE\rNEWFILEUID:NONE\r}
|
|
151
|
+
body = open("spec/fixtures/sample.ofx").read.split(/<OFX>/, 2)[1]
|
|
152
|
+
ofx_with_carriage_return = header + "<OFX>" + body
|
|
153
|
+
|
|
104
154
|
@ofx = OFX::Parser::Base.new(ofx_with_carriage_return)
|
|
105
155
|
@ofx.headers.size.should be(9)
|
|
106
156
|
end
|
|
107
157
|
end
|
|
108
|
-
|
|
109
|
-
def ofx_with_carriage_return
|
|
110
|
-
header = %{OFXHEADER:100\rDATA:OFXSGML\rVERSION:102\rSECURITY:NONE\rENCODING:USASCII\rCHARSET:1252\rCOMPRESSION:NONE\rOLDFILEUID:NONE\rNEWFILEUID:NONE\r}
|
|
111
|
-
body = open("spec/fixtures/sample.ofx").read.split(/<OFX>/, 2)[1]
|
|
112
|
-
header + "<OFX>" + body
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def ofx_2_example(version)
|
|
116
|
-
<<-EndOfx
|
|
117
|
-
<?xml version="1.0" encoding="US-ASCII"?>
|
|
118
|
-
<?OFX OFXHEADER="200" VERSION="#{version}" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>"
|
|
119
|
-
<OFX>
|
|
120
|
-
</OFX>
|
|
121
|
-
EndOfx
|
|
122
|
-
end
|
|
123
158
|
end
|
|
@@ -13,43 +13,43 @@ describe OFX::Transaction do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "should set amount" do
|
|
16
|
-
@transaction.amount.
|
|
16
|
+
expect(@transaction.amount).to eql BigDecimal('-35.34')
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "should cast amount to BigDecimal" do
|
|
20
|
-
@transaction.amount.class.
|
|
20
|
+
expect(@transaction.amount.class).to be BigDecimal
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "should set amount in pennies" do
|
|
24
|
-
@transaction.amount_in_pennies.
|
|
24
|
+
expect(@transaction.amount_in_pennies).to eql -3534
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "should set fit id" do
|
|
28
|
-
@transaction.fit_id.
|
|
28
|
+
expect(@transaction.fit_id).to eql "200910091"
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "should set memo" do
|
|
32
|
-
@transaction.memo.
|
|
32
|
+
expect(@transaction.memo).to eql "COMPRA VISA ELECTRON"
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "should set check number" do
|
|
36
|
-
@transaction.check_number.
|
|
36
|
+
expect(@transaction.check_number).to eql "0001223"
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "should have date" do
|
|
40
|
-
@transaction.posted_at.
|
|
40
|
+
expect(@transaction.posted_at).to eql Time.parse("2009-10-09 08:00:00 +0000")
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it 'should have user date' do
|
|
44
|
-
@transaction.occurred_at.
|
|
44
|
+
expect(@transaction.occurred_at).to eql Time.parse("2009-09-09 08:00:00 +0000")
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "should have type" do
|
|
48
|
-
@transaction.type.
|
|
48
|
+
expect(@transaction.type).to eql :debit
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
it "should have sic" do
|
|
52
|
-
@transaction.sic.
|
|
52
|
+
expect(@transaction.sic).to eql '5072'
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
@@ -59,39 +59,39 @@ describe OFX::Transaction do
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it "should set amount" do
|
|
62
|
-
@transaction.amount.
|
|
62
|
+
expect(@transaction.amount).to eql BigDecimal('60.39')
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "should set amount in pennies" do
|
|
66
|
-
@transaction.amount_in_pennies.
|
|
66
|
+
expect(@transaction.amount_in_pennies).to eql 6039
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "should set fit id" do
|
|
70
|
-
@transaction.fit_id.
|
|
70
|
+
expect(@transaction.fit_id).to eql "200910162"
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
it "should set memo" do
|
|
74
|
-
@transaction.memo.
|
|
74
|
+
expect(@transaction.memo).to eql "DEPOSITO POUP.CORRENTE"
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
it "should set check number" do
|
|
78
|
-
@transaction.check_number.
|
|
78
|
+
expect(@transaction.check_number).to eql "0880136"
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "should have date" do
|
|
82
|
-
@transaction.posted_at.
|
|
82
|
+
expect(@transaction.posted_at).to eql Time.parse("2009-10-16 08:00:00 +0000")
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it "should have user date" do
|
|
86
|
-
@transaction.occurred_at.
|
|
86
|
+
expect(@transaction.occurred_at).to eql Time.parse("2009-09-16 08:00:00 +0000")
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "should have type" do
|
|
90
|
-
@transaction.type.
|
|
90
|
+
expect(@transaction.type).to eql :credit
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
it "should have empty sic" do
|
|
94
|
-
@transaction.sic.
|
|
94
|
+
expect(@transaction.sic).to eql ''
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -101,27 +101,27 @@ describe OFX::Transaction do
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
it "should set payee" do
|
|
104
|
-
@transaction.payee.
|
|
104
|
+
expect(@transaction.payee).to eql "Pagto conta telefone"
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
it "should set check number" do
|
|
108
|
-
@transaction.check_number.
|
|
108
|
+
expect(@transaction.check_number).to eql "000000101901"
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it "should have date" do
|
|
112
|
-
@transaction.posted_at.
|
|
112
|
+
expect(@transaction.posted_at).to eql Time.parse("2009-10-19 12:00:00 -0300")
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "should have user date" do
|
|
116
|
-
@transaction.occurred_at.
|
|
116
|
+
expect(@transaction.occurred_at).to eql Time.parse("2009-10-17 12:00:00 -0300")
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
it "should have type" do
|
|
120
|
-
@transaction.type.
|
|
120
|
+
expect(@transaction.type).to eql :other
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
it "should have reference number" do
|
|
124
|
-
@transaction.ref_number.
|
|
124
|
+
expect(@transaction.ref_number).to eql "101.901"
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -131,7 +131,7 @@ describe OFX::Transaction do
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
it "should set name" do
|
|
134
|
-
@transaction.name.
|
|
134
|
+
expect(@transaction.name).to eql "Pagto conta telefone"
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
|
|
@@ -144,22 +144,22 @@ describe OFX::Transaction do
|
|
|
144
144
|
|
|
145
145
|
it "should return dep" do
|
|
146
146
|
@transaction = @account.transactions[9]
|
|
147
|
-
@transaction.type.
|
|
147
|
+
expect(@transaction.type).to eql :dep
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
it "should return xfer" do
|
|
151
151
|
@transaction = @account.transactions[18]
|
|
152
|
-
@transaction.type.
|
|
152
|
+
expect(@transaction.type).to eql :xfer
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
it "should return cash" do
|
|
156
156
|
@transaction = @account.transactions[45]
|
|
157
|
-
@transaction.type.
|
|
157
|
+
expect(@transaction.type).to eql :cash
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
it "should return check" do
|
|
161
161
|
@transaction = @account.transactions[0]
|
|
162
|
-
@transaction.type.
|
|
162
|
+
expect(@transaction.type).to eql :check
|
|
163
163
|
end
|
|
164
164
|
end
|
|
165
165
|
|
|
@@ -176,11 +176,11 @@ describe OFX::Transaction do
|
|
|
176
176
|
end
|
|
177
177
|
|
|
178
178
|
it "should set amount" do
|
|
179
|
-
@transaction.amount.
|
|
179
|
+
expect(@transaction.amount).to eql BigDecimal('-11.76')
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
it "should set amount in pennies" do
|
|
183
|
-
@transaction.amount_in_pennies.
|
|
183
|
+
expect(@transaction.amount_in_pennies).to eql -1176
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
186
|
|
|
@@ -190,12 +190,31 @@ describe OFX::Transaction do
|
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
it "should set amount" do
|
|
193
|
-
@transaction.amount.
|
|
193
|
+
expect(@transaction.amount).to eql BigDecimal('47.01')
|
|
194
194
|
end
|
|
195
195
|
|
|
196
196
|
it "should set amount in pennies" do
|
|
197
|
-
@transaction.amount_in_pennies.
|
|
197
|
+
expect(@transaction.amount_in_pennies).to eql 4701
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
end
|
|
201
|
+
|
|
202
|
+
context "invalid decimal values" do
|
|
203
|
+
before do
|
|
204
|
+
@ofx = OFX::Parser::Base.new("spec/fixtures/cef_malformed_decimal.ofx")
|
|
205
|
+
@parser = @ofx.parser
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it "should not raise error" do
|
|
209
|
+
expect { @parser.account.transactions }.to_not raise_error
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "should return zero in amount" do
|
|
213
|
+
expect(@parser.account.transactions[0].amount).to eql BigDecimal('0.0')
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "should return zero in amount_in_pennies" do
|
|
217
|
+
expect(@parser.account.transactions[0].amount_in_pennies).to eql 0
|
|
218
|
+
end
|
|
219
|
+
end
|
|
201
220
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "ofx"
|
|
2
|
+
require "byebug"
|
|
2
3
|
|
|
3
4
|
RSpec::Matchers.define :have_key do |key|
|
|
4
5
|
match do |hash|
|
|
5
6
|
hash.respond_to?(:keys) &&
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
hash.keys.kind_of?(Array) &&
|
|
8
|
+
hash.keys.include?(key)
|
|
8
9
|
end
|
|
9
10
|
end
|
|
11
|
+
|
|
12
|
+
RSpec.configure do |c|
|
|
13
|
+
c.filter_run_when_matching :focus
|
|
14
|
+
end
|