conectiva-boleto_bancario 0.0.2.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -0
  5. data/Changelog.markdown +10 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +22 -0
  8. data/Planning.markdown +137 -0
  9. data/README.markdown +215 -0
  10. data/Rakefile +9 -0
  11. data/TODO.markdown +11 -0
  12. data/boleto_bancario.gemspec +25 -0
  13. data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
  14. data/lib/boleto_bancario.rb +85 -0
  15. data/lib/boleto_bancario/calculos/digitos.rb +35 -0
  16. data/lib/boleto_bancario/calculos/fator_vencimento.rb +87 -0
  17. data/lib/boleto_bancario/calculos/fatores_de_multiplicacao.rb +67 -0
  18. data/lib/boleto_bancario/calculos/linha_digitavel.rb +158 -0
  19. data/lib/boleto_bancario/calculos/modulo10.rb +83 -0
  20. data/lib/boleto_bancario/calculos/modulo11.rb +54 -0
  21. data/lib/boleto_bancario/calculos/modulo11_fator_de2a7.rb +97 -0
  22. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9.rb +83 -0
  23. data/lib/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
  24. data/lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb +101 -0
  25. data/lib/boleto_bancario/calculos/modulo_numero_de_controle.rb +117 -0
  26. data/lib/boleto_bancario/core/banco_brasil.rb +532 -0
  27. data/lib/boleto_bancario/core/banrisul.rb +182 -0
  28. data/lib/boleto_bancario/core/boleto.rb +559 -0
  29. data/lib/boleto_bancario/core/bradesco.rb +285 -0
  30. data/lib/boleto_bancario/core/itau.rb +455 -0
  31. data/lib/boleto_bancario/core/santander.rb +273 -0
  32. data/lib/boleto_bancario/version.rb +4 -0
  33. data/spec/boleto_bancario/calculos/digitos_spec.rb +19 -0
  34. data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +59 -0
  35. data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +69 -0
  36. data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +57 -0
  37. data/spec/boleto_bancario/calculos/modulo10_spec.rb +53 -0
  38. data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +43 -0
  39. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +39 -0
  40. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +67 -0
  41. data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +37 -0
  42. data/spec/boleto_bancario/calculos/modulo11_spec.rb +19 -0
  43. data/spec/boleto_bancario/calculos/modulo_numero_de_controle_spec.rb +37 -0
  44. data/spec/boleto_bancario/core/banco_brasil_spec.rb +383 -0
  45. data/spec/boleto_bancario/core/banrisul_spec.rb +130 -0
  46. data/spec/boleto_bancario/core/boleto_spec.rb +161 -0
  47. data/spec/boleto_bancario/core/bradesco_spec.rb +170 -0
  48. data/spec/boleto_bancario/core/itau_spec.rb +336 -0
  49. data/spec/boleto_bancario/core/santander_spec.rb +135 -0
  50. data/spec/shared_examples/boleto_bancario_shared_example.rb +157 -0
  51. data/spec/spec_helper.rb +14 -0
  52. metadata +211 -0
@@ -0,0 +1,336 @@
1
+ require 'spec_helper'
2
+
3
+ module BoletoBancario
4
+ module Core
5
+ describe Itau do
6
+ it_should_behave_like 'boleto bancario'
7
+
8
+ describe "on validations" do
9
+ describe "#carteira" do
10
+ it { should have_valid(:carteira).when('109', '107', '175', 109, 198) }
11
+ it { should_not have_valid(:carteira).when('10912', '10790', '17523', '1451') }
12
+ end
13
+
14
+ describe "#numero_documento" do
15
+ it { should have_valid(:numero_documento).when('12345', '123456', '12345678') }
16
+ it { should_not have_valid(:numero_documento).when('123456789', nil, '', '12345678910') }
17
+ end
18
+
19
+ describe "#conta_corrente" do
20
+ it { should have_valid(:conta_corrente).when('1', '1234', '12345') }
21
+ it { should_not have_valid(:conta_corrente).when('123456', nil, '1234567', '') }
22
+ end
23
+
24
+ describe "#agencia" do
25
+ it { should have_valid(:agencia).when('1', '1234', '1234') }
26
+ it { should_not have_valid(:agencia).when('12345', nil, '123456', '') }
27
+ end
28
+
29
+ describe "#codigo_cedente" do
30
+ %w(107 122 142 143 196 198).each do |carteira_especial|
31
+ context "when 'carteira' is special: #{carteira_especial}" do
32
+ subject { Itau.new(carteira: carteira_especial) }
33
+
34
+ it { should have_valid(:codigo_cedente).when('1', '1234', '12345') }
35
+ it { should_not have_valid(:codigo_cedente).when('123456', nil, '1234567', '') }
36
+ end
37
+ end
38
+
39
+ %w(109 126 131 146 150 168 174 175).each do |carteira|
40
+ context "when 'carteira' isn't special: #{carteira}" do
41
+ subject { Itau.new(carteira: carteira) }
42
+
43
+ # Código do Cedente não precisa ser validado quando possui essas carteiras.
44
+ #
45
+ it { should have_valid(:codigo_cedente).when('1', '1234', '12345', nil, '') }
46
+ end
47
+ end
48
+
49
+ describe "#seu_numero" do
50
+ %w(107 122 142 143 196 198).each do |carteira_especial|
51
+ context "when 'carteira' is special: #{carteira_especial}" do
52
+ subject { Itau.new(carteira: carteira_especial) }
53
+
54
+ it { should have_valid(:seu_numero).when('1', '1234', '1234567') }
55
+ it { should_not have_valid(:seu_numero).when('12345678', nil, '123456789', '') }
56
+ end
57
+ end
58
+
59
+ %w(109 126 131 146 150 168 174 175).each do |carteira|
60
+ context "when 'carteira' isn't special: #{carteira}" do
61
+ subject { Itau.new(carteira: carteira) }
62
+
63
+ # Seu número não precisa ser validado quando possui essas carteiras.
64
+ #
65
+ it { should have_valid(:seu_numero).when('1', '1234', '12345', nil, '') }
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#digito_conta_corrente" do
72
+ it { should have_valid(:digito_conta_corrente).when('1', '2', '3') }
73
+ it { should_not have_valid(:digito_conta_corrente).when('12', nil, '123', '') }
74
+ end
75
+ end
76
+
77
+ describe "#numero_documento" do
78
+ subject { Itau.new(:numero_documento => '123') }
79
+
80
+ its(:numero_documento) { should eq '00000123' }
81
+ end
82
+
83
+ describe "#seu_numero" do
84
+ context "when have a value" do
85
+ subject { Itau.new(:seu_numero => '11804') }
86
+
87
+ its(:seu_numero) { should eq '0011804' }
88
+ end
89
+
90
+ context "when is nil" do
91
+ subject { Itau.new(:seu_numero => nil) }
92
+
93
+ its(:seu_numero) { should be nil }
94
+ end
95
+ end
96
+
97
+ describe "#agencia" do
98
+ context "when have a value" do
99
+ subject { Itau.new(:agencia => '001') }
100
+
101
+ its(:agencia) { should eq '0001' }
102
+ end
103
+
104
+ context "when is nil" do
105
+ subject { Itau.new(:agencia => nil) }
106
+
107
+ its(:agencia) { should be nil }
108
+ end
109
+ end
110
+
111
+ describe "#conta_corrente" do
112
+ context "when have a value" do
113
+ subject { Itau.new(:conta_corrente => 9013) }
114
+
115
+ its(:conta_corrente) { should eq '09013' }
116
+ end
117
+
118
+ context "when is nil" do
119
+ subject { Itau.new(:conta_corrente => nil) }
120
+
121
+ its(:conta_corrente) { should be nil }
122
+ end
123
+ end
124
+
125
+ describe "#codigo_cedente" do
126
+ context "when have a value" do
127
+ subject { Itau.new(:codigo_cedente => 1987) }
128
+
129
+ its(:codigo_cedente) { should eq '01987' }
130
+ end
131
+
132
+ context "when is nil" do
133
+ subject { Itau.new(:codigo_cedente => nil) }
134
+
135
+ its(:codigo_cedente) { should be nil }
136
+ end
137
+ end
138
+
139
+ describe "#codigo_banco" do
140
+ its(:codigo_banco) { should eq '341' }
141
+ end
142
+
143
+ describe "#digito_codigo_banco" do
144
+ its(:digito_codigo_banco) { should eq '7' }
145
+ end
146
+
147
+ describe "#agencia_codigo_cedente" do
148
+ subject { Itau.new(:agencia => '0057', :conta_corrente => '12345', :digito_conta_corrente => '7') }
149
+
150
+ it "should return the agency and bank account with digit" do
151
+ subject.agencia_codigo_cedente.should eq '0057 / 12345-7'
152
+ end
153
+ end
154
+
155
+ describe "#nosso_numero" do
156
+ context "when 'carteira' is 126" do
157
+ subject { Itau.new(:carteira => '126', :numero_documento => '12345') }
158
+
159
+ it "should calculate the 'nosso numero' with carteira and document number" do
160
+ subject.nosso_numero.should eq '126/00012345-8'
161
+ end
162
+ end
163
+
164
+ context "when 'carteira' is 131" do
165
+ subject { Itau.new(:carteira => '131', :numero_documento => '6789') }
166
+
167
+ it "should calculate the 'nosso numero' with carteira and document number" do
168
+ subject.nosso_numero.should eq '131/00006789-5'
169
+ end
170
+ end
171
+
172
+ context "when 'carteira' is 146" do
173
+ subject { Itau.new(:carteira => '146', :numero_documento => '147890') }
174
+
175
+ it "should calculate the 'nosso numero' with carteira and document number" do
176
+ subject.nosso_numero.should eq '146/00147890-9'
177
+ end
178
+ end
179
+
180
+ context "when 'carteira' is 150" do
181
+ subject { Itau.new(:carteira => '150', :numero_documento => '18765476') }
182
+
183
+ it "should calculate the 'nosso numero' with carteira and document number" do
184
+ subject.nosso_numero.should eq '150/18765476-2'
185
+ end
186
+ end
187
+
188
+ context "when 'carteira' is 168" do
189
+ subject { Itau.new(:carteira => '168', :numero_documento => '12784698') }
190
+
191
+ it "should calculate the 'nosso numero' with carteira and document number" do
192
+ subject.nosso_numero.should eq '168/12784698-3'
193
+ end
194
+ end
195
+
196
+ context "when 'carteira' is 110" do
197
+ subject do
198
+ Itau.new(
199
+ :agencia => '0057',
200
+ :conta_corrente => '12345',
201
+ :carteira => '110',
202
+ :numero_documento => '12345678'
203
+ )
204
+ end
205
+
206
+ it "should format the 'nosso numero' with agencia, conta_corrente, carteira and document number" do
207
+ subject.nosso_numero.should eq '110/12345678-8'
208
+ end
209
+ end
210
+
211
+ context "when 'carteira' is 198" do
212
+ subject do
213
+ Itau.new(
214
+ :agencia => '0057',
215
+ :conta_corrente => '72192',
216
+ :carteira => '198',
217
+ :numero_documento => '98712345'
218
+ )
219
+ end
220
+
221
+ it "should follow the Itau documentation" do
222
+ subject.nosso_numero.should eq '198/98712345-1'
223
+ end
224
+ end
225
+ end
226
+
227
+ describe "#carteira_especial?" do
228
+ %w(107 122 142 143 196 198).each do |carteira_especial|
229
+ context "when 'carteira' is special: #{carteira_especial}" do
230
+ subject { Itau.new(carteira: carteira_especial) }
231
+
232
+ its(:carteira_especial?) { should be true }
233
+ end
234
+
235
+ context "when 'carteira' is special: #{carteira_especial} as numeric" do
236
+ subject { Itau.new(carteira: carteira_especial.to_i) }
237
+
238
+ its(:carteira_especial?) { should be true }
239
+ end
240
+ end
241
+
242
+ %w(109 126 131 146 150 168 174 175).each do |carteira|
243
+ context "when 'carteira' isn't special: #{carteira}" do
244
+ subject { Itau.new(carteira: carteira) }
245
+
246
+ its(:carteira_especial?) { should be false }
247
+ end
248
+ end
249
+ end
250
+
251
+ describe "#codigo_de_barras_do_banco" do
252
+ context "when default carteira" do
253
+ subject do
254
+ Itau.new do |boleto|
255
+ boleto.carteira = '109'
256
+ boleto.numero_documento = '12345678'
257
+ boleto.agencia = '0057'
258
+ boleto.conta_corrente = '12345'
259
+ boleto.digito_conta_corrente = '7'
260
+ end
261
+ end
262
+
263
+ its(:codigo_de_barras_do_banco) { should eq '1091234567800057123457000' }
264
+ end
265
+
266
+ context "when special 'carteira'" do
267
+ subject do
268
+ Itau.new(
269
+ :codigo_cedente => '94786',
270
+ :carteira => carteira,
271
+ :numero_documento => '12345678',
272
+ :seu_numero => '1108954'
273
+ )
274
+ end
275
+
276
+ context "when 'carteira' is 107" do
277
+ let(:carteira) { '107' }
278
+
279
+ its(:codigo_de_barras_do_banco) { should eq '1071234567811089549478620' }
280
+ end
281
+
282
+ context "when 'carteira' is 122" do
283
+ let(:carteira) { '122' }
284
+
285
+ its(:codigo_de_barras_do_banco) { should eq '1221234567811089549478610' }
286
+ end
287
+
288
+ context "when 'carteira' is 142" do
289
+ let(:carteira) { '142' }
290
+
291
+ its(:codigo_de_barras_do_banco) { should eq '1421234567811089549478690' }
292
+ end
293
+
294
+ context "when 'carteira' is 143" do
295
+ let(:carteira) { '143' }
296
+
297
+ its(:codigo_de_barras_do_banco) { should eq '1431234567811089549478670' }
298
+ end
299
+
300
+ context "when 'carteira' is 196" do
301
+ let(:carteira) { '196' }
302
+
303
+ its(:codigo_de_barras_do_banco) { should eq '1961234567811089549478650' }
304
+ end
305
+
306
+ context "when 'carteira' is 198" do
307
+ let(:carteira) { '198' }
308
+
309
+ its(:codigo_de_barras_do_banco) { should eq '1981234567811089549478610' }
310
+ end
311
+ end
312
+ end
313
+
314
+ describe "#linha_digitavel" do
315
+ subject do
316
+ Itau.new do |boleto|
317
+ boleto.carteira = '175'
318
+ boleto.agencia = 1565
319
+ boleto.conta_corrente = 13877
320
+ boleto.digito_conta_corrente = 1
321
+ boleto.numero_documento = 12345678
322
+ boleto.data_vencimento = Date.parse('2012-12-21')
323
+ boleto.valor_documento = 2952.95
324
+ end
325
+ end
326
+
327
+ # Grep this example from boleto php demo page.
328
+ its(:linha_digitavel) { should eq '34191.75124 34567.861561 51387.710000 1 55540000295295' }
329
+ end
330
+
331
+ describe "#to_partial_path" do
332
+ its(:to_partial_path) { should eq 'boleto_bancario/itau' }
333
+ end
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,135 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ module BoletoBancario
5
+ module Core
6
+ describe Santander do
7
+ it_should_behave_like 'boleto bancario'
8
+
9
+ describe "on validations" do
10
+ it { should have_valid(:agencia).when('1', '12', '123', '1234') }
11
+ it { should_not have_valid(:agencia).when('12345', '123456', nil, '') }
12
+
13
+ it { should have_valid(:codigo_cedente).when('1', '12', '123', '1234567') }
14
+ it { should_not have_valid(:codigo_cedente).when('12345678', '123456789', nil, '') }
15
+
16
+ it { should have_valid(:numero_documento).when('1', '12', '123', '123456789112') }
17
+ it { should_not have_valid(:numero_documento).when('1234567891123', nil, '') }
18
+
19
+ it { should have_valid(:carteira).when('1', '12', '123') }
20
+ it { should_not have_valid(:carteira).when('1234', nil, '') }
21
+ end
22
+
23
+ describe "#agencia" do
24
+ context "when have a value" do
25
+ subject { Santander.new(agencia: '2') }
26
+
27
+ its(:agencia) { should eq '0002' }
28
+ end
29
+
30
+ context "when is nil" do
31
+ its(:agencia) { should be nil }
32
+ end
33
+ end
34
+
35
+ describe "#codigo_cedente" do
36
+ context "when have a value" do
37
+ subject { Santander.new(codigo_cedente: '1') }
38
+
39
+ its(:codigo_cedente) { should eq '0000001' }
40
+ end
41
+
42
+ context "when is nil" do
43
+ its(:codigo_cedente) { should be nil }
44
+ end
45
+ end
46
+
47
+ describe "#numero_documento" do
48
+ context "when have a value" do
49
+ subject { Santander.new(numero_documento: '1') }
50
+
51
+ its(:numero_documento) { should eq '000000000001' }
52
+ end
53
+
54
+ context "when is nil" do
55
+ its(:numero_documento) { should be nil }
56
+ end
57
+ end
58
+
59
+ describe "#carteira" do
60
+ context "when have a value" do
61
+ subject { Santander.new(carteira: '1') }
62
+
63
+ its(:carteira) { should eq '001' }
64
+ end
65
+
66
+ context "when is nil" do
67
+ its(:carteira) { should be nil }
68
+ end
69
+ end
70
+
71
+ describe "#carteira_formatada" do
72
+ context "when is registered" do
73
+ subject { Santander.new(:carteira => 101) }
74
+
75
+ its(:carteira_formatada) { should eq 'COBRANÇA SIMPLES ECR' }
76
+ end
77
+
78
+ context "when isn't registered" do
79
+ subject { Santander.new(:carteira => 102) }
80
+
81
+ its(:carteira_formatada) { should eq 'COBRANÇA SIMPLES CSR' }
82
+ end
83
+ end
84
+
85
+ describe "#codigo_banco" do
86
+ its(:codigo_banco) { should eq '033' }
87
+ end
88
+
89
+ describe "#digito_codigo_banco" do
90
+ its(:digito_codigo_banco) { should eq '7' }
91
+ end
92
+
93
+ describe "#agencia_codigo_cedente" do
94
+ subject { Santander.new(agencia: '0235', digito_agencia: '6', codigo_cedente: '1625462') }
95
+
96
+ its(:agencia_codigo_cedente) { should eq '0235-6 / 1625462' }
97
+ end
98
+
99
+ describe "#nosso_numero" do
100
+ subject { Santander.new(numero_documento: '566612457800') }
101
+
102
+ its(:nosso_numero) { should eq '566612457800-2' }
103
+ end
104
+
105
+ describe "#codigo_de_barras" do
106
+ subject do
107
+ Santander.new do |santander|
108
+ santander.codigo_cedente = '0707077'
109
+ santander.numero_documento = '000001234567'
110
+ santander.valor_documento = 2952.95
111
+ santander.carteira = '102'
112
+ santander.agencia = 1333
113
+ santander.digito_agencia = 1
114
+ santander.data_vencimento = Date.parse('2012-12-28')
115
+ end
116
+ end
117
+
118
+ its(:codigo_de_barras) { should eq '03391556100002952959070707700000123456790102' }
119
+ its(:linha_digitavel) { should eq '03399.07073 07700.000123 34567.901029 1 55610000295295' }
120
+ end
121
+
122
+ describe "#iof" do
123
+ context "default iof" do
124
+ its(:iof) { should eq '0' }
125
+ end
126
+
127
+ context "setting iof" do
128
+ subject { Santander.new(iof: 7) }
129
+
130
+ its(:iof) { should eq '7' }
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end