forked from kivanio/brcobranca
/
banco_banespa_spec.rb
260 lines (224 loc) · 10.3 KB
/
banco_banespa_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# -*- encoding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Brcobranca::Boleto::Banespa do
before(:each) do
@valid_attributes = {
:cedente => "Kivanio Barbosa",
:documento_cedente => "12345678912",
:sacado => "Claudio Pozzebom",
:sacado_documento => "12345678900",
:agencia => "400",
:conta_corrente => "61900",
:convenio => 12387989,
:numero_documento => "777700168"
}
end
it "Criar nova instancia com atributos padrões" do
boleto_novo = Brcobranca::Boleto::Banespa.new
boleto_novo.banco.should eql("033")
boleto_novo.especie_documento.should eql("DM")
boleto_novo.especie.should eql("R$")
boleto_novo.moeda.should eql("9")
boleto_novo.data_documento.should eql(Date.today)
boleto_novo.dias_vencimento.should eql(1)
boleto_novo.data_vencimento.should eql(Date.today + 1)
boleto_novo.aceite.should eql("S")
boleto_novo.quantidade.should eql(1)
boleto_novo.valor.should eql(0.0)
boleto_novo.valor_documento.should eql(0.0)
boleto_novo.local_pagamento.should eql("QUALQUER BANCO ATÉ O VENCIMENTO")
boleto_novo.carteira.should eql("COB")
end
it "Criar nova instancia com atributos válidos" do
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.banco.should eql("033")
boleto_novo.especie_documento.should eql("DM")
boleto_novo.especie.should eql("R$")
boleto_novo.moeda.should eql("9")
boleto_novo.data_documento.should eql(Date.today)
boleto_novo.dias_vencimento.should eql(1)
boleto_novo.data_vencimento.should eql(Date.today + 1)
boleto_novo.aceite.should eql("S")
boleto_novo.quantidade.should eql(1)
boleto_novo.valor.should eql(0.0)
boleto_novo.valor_documento.should eql(0.0)
boleto_novo.local_pagamento.should eql("QUALQUER BANCO ATÉ O VENCIMENTO")
boleto_novo.cedente.should eql("Kivanio Barbosa")
boleto_novo.documento_cedente.should eql("12345678912")
boleto_novo.sacado.should eql("Claudio Pozzebom")
boleto_novo.sacado_documento.should eql("12345678900")
boleto_novo.conta_corrente.should eql("0061900")
boleto_novo.agencia.should eql("400")
boleto_novo.convenio.should eql("00012387989")
boleto_novo.numero_documento.should eql("777700168")
boleto_novo.carteira.should eql("COB")
end
it "Não permitir gerar boleto com atributos inválido" do
boleto_novo = Brcobranca::Boleto::Banespa.new
lambda { boleto_novo.codigo_barras }.should raise_error(Brcobranca::BoletoInvalido)
boleto_novo.errors.count.should eql(3)
end
it "Gerar boleto" do
@valid_attributes[:valor] = 103.58
@valid_attributes[:data_documento] = Date.parse("2001-08-01")
@valid_attributes[:dias_vencimento] = 0
@valid_attributes[:convenio] = 14813026478
@valid_attributes[:numero_documento] = "0004952"
@valid_attributes[:conta_corrente] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.conta_corrente_dv.should eql(2)
boleto_novo.codigo_barras_segunda_parte.should eql("1481302647800049520003306")
boleto_novo.codigo_barras.should eql("03398139400000103581481302647800049520003306")
boleto_novo.codigo_barras.linha_digitavel.should eql("03391.48132 02647.800040 95200.033066 8 13940000010358")
@valid_attributes[:valor] = 2952.95
@valid_attributes[:data_documento] = Date.parse("2009-08-14")
@valid_attributes[:dias_vencimento] = 5
@valid_attributes[:convenio] = 40013012168
@valid_attributes[:numero_documento] = "1234567"
@valid_attributes[:conta_corrente] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.conta_corrente_dv.should eql(2)
boleto_novo.codigo_barras_segunda_parte.should eql("4001301216812345670003361")
boleto_novo.codigo_barras.should eql("03398433400002952954001301216812345670003361")
boleto_novo.codigo_barras.linha_digitavel.should eql("03394.00137 01216.812345 56700.033618 8 43340000295295")
end
it "Montar nosso_numero e nosso_numero_dv" do
@valid_attributes[:numero_documento] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.nosso_numero.should eql("4000403005")
boleto_novo.nosso_numero_dv.should eql(6)
boleto_novo.nosso_numero_boleto.should eql("400 0403005 6")
@valid_attributes[:numero_documento] = "403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.nosso_numero.should eql("4000403005")
boleto_novo.nosso_numero_dv.should eql(6)
boleto_novo.nosso_numero_boleto.should eql("400 0403005 6")
@valid_attributes[:numero_documento] = "1234567"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.nosso_numero.should eql("4001234567")
boleto_novo.nosso_numero_dv.should eql(8)
boleto_novo.nosso_numero_boleto.should eql("400 1234567 8")
@valid_attributes[:agencia] = "123"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.nosso_numero.should eql("1231234567")
boleto_novo.nosso_numero_dv.should eql(0)
boleto_novo.nosso_numero_boleto.should eql("123 1234567 0")
@valid_attributes[:agencia] = "123"
@valid_attributes[:numero_documento] = "7469108"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.nosso_numero.should eql("1237469108")
boleto_novo.nosso_numero_dv.should eql(3)
boleto_novo.nosso_numero_boleto.should eql("123 7469108 3")
end
it "Montar agencia_conta_dv" do
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo.agencia_conta_boleto.should eql("000 12 38798 9")
end
it "Busca logotipo do banco" do
boleto_novo = Brcobranca::Boleto::Banespa.new
File.exist?(boleto_novo.logotipo).should be_true
File.stat(boleto_novo.logotipo).zero?.should be_false
end
it "Gerar boleto nos formatos válidos com método to_" do
@valid_attributes[:valor] = 2952.95
@valid_attributes[:data_documento] = Date.parse("2009-08-14")
@valid_attributes[:dias_vencimento] = 5
@valid_attributes[:convenio] = 40013012168
@valid_attributes[:numero_documento] = "1234567"
@valid_attributes[:conta_corrente] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
%w| pdf jpg tif png ps |.each do |format|
file_body=boleto_novo.send("to_#{format}".to_sym)
tmp_file=Tempfile.new("foobar." << format)
tmp_file.puts file_body
tmp_file.close
File.exist?(tmp_file.path).should be_true
File.stat(tmp_file.path).zero?.should be_false
File.delete(tmp_file.path).should eql(1)
File.exist?(tmp_file.path).should be_false
end
end
it "Gerar boleto usando bloco nos formatos válidos com método to_" do
boleto_novo = Brcobranca::Boleto::Banespa.new do |boleto|
boleto.cedente = "Kivanio Barbosa"
boleto.documento_cedente = "12345678912"
boleto.sacado = "Claudio Pozzebom"
boleto.sacado_documento = "12345678900"
boleto.agencia = "400"
boleto.valor = 2952.95
boleto.data_documento = Date.parse("2009-08-14")
boleto.dias_vencimento = 5
boleto.convenio = 40013012168
boleto.numero_documento = "1234567"
boleto.conta_corrente = "0403005"
end
%w| pdf jpg tif png ps |.each do |format|
file_body=boleto_novo.send("to_#{format}".to_sym)
tmp_file=Tempfile.new("foobar." << format)
tmp_file.puts file_body
tmp_file.close
File.exist?(tmp_file.path).should be_true
File.stat(tmp_file.path).zero?.should be_false
File.delete(tmp_file.path).should eql(1)
File.exist?(tmp_file.path).should be_false
end
end
it "Gerar boleto nos formatos válidos com método to_ e com opcoes" do
@valid_attributes[:valor] = 2952.95
@valid_attributes[:data_documento] = Date.parse("2009-08-14")
@valid_attributes[:dias_vencimento] = 5
@valid_attributes[:convenio] = 40013012168
@valid_attributes[:numero_documento] = "1234567"
@valid_attributes[:conta_corrente] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
%w| pdf jpg tif png ps |.each do |format|
file_body=boleto_novo.send("to_#{format}".to_sym, :resolucao => 200)
tmp_file=Tempfile.new("foobar." << format)
tmp_file.puts file_body
tmp_file.close
File.exist?(tmp_file.path).should be_true
File.stat(tmp_file.path).zero?.should be_false
File.delete(tmp_file.path).should eql(1)
File.exist?(tmp_file.path).should be_false
end
end
it "Gerar boleto nos formatos válidos" do
@valid_attributes[:valor] = 2952.95
@valid_attributes[:data_documento] = Date.parse("2009-08-14")
@valid_attributes[:dias_vencimento] = 5
@valid_attributes[:convenio] = 40013012168
@valid_attributes[:numero_documento] = "1234567"
@valid_attributes[:conta_corrente] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
%w| pdf jpg tif png ps |.each do |format|
file_body=boleto_novo.to(format)
tmp_file=Tempfile.new("foobar." << format)
tmp_file.puts file_body
tmp_file.close
File.exist?(tmp_file.path).should be_true
File.stat(tmp_file.path).zero?.should be_false
File.delete(tmp_file.path).should eql(1)
File.exist?(tmp_file.path).should be_false
end
end
it "Gerar multiplos boletos nos formatos válidos" do
@valid_attributes[:valor] = 2952.95
@valid_attributes[:data_documento] = Date.parse("2009-08-14")
@valid_attributes[:dias_vencimento] = 5
@valid_attributes[:convenio] = 40013012168
@valid_attributes[:numero_documento] = "1234567"
@valid_attributes[:conta_corrente] = "0403005"
boleto_novo = Brcobranca::Boleto::Banespa.new(@valid_attributes)
boleto_novo_2 = Brcobranca::Boleto::Banespa.new(@valid_attributes)
%w| pdf jpg tif png ps |.each do |format|
file_body=Brcobranca::Boleto::Banespa.imprimir_lista([boleto_novo, boleto_novo_2], {:formato => format, :multipage => true})
tmp_file=Tempfile.new("foobar." << format)
tmp_file.puts file_body
tmp_file.close
File.exist?(tmp_file.path).should be_true
File.stat(tmp_file.path).zero?.should be_false
File.delete(tmp_file.path).should eql(1)
File.exist?(tmp_file.path).should be_false
end
end
end