boleto_bancario 0.0.1.beta → 0.0.2
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 +7 -0
- data/.gitignore +3 -2
- data/.travis.yml +10 -0
- data/Changelog.markdown +4 -0
- data/Gemfile +1 -1
- data/Planning.markdown +18 -86
- data/README.markdown +107 -55
- data/Rakefile +7 -1
- data/TODO.markdown +15 -1
- data/boleto_bancario.gemspec +7 -3
- data/lib/boleto_bancario.rb +27 -15
- data/lib/boleto_bancario/calculos/modulo11_fator_de9a2.rb +65 -0
- data/lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb +5 -51
- data/lib/boleto_bancario/calculos/modulo_numero_de_controle.rb +117 -0
- data/lib/boleto_bancario/core/banco_brasil.rb +30 -5
- data/lib/boleto_bancario/core/banrisul.rb +182 -0
- data/lib/boleto_bancario/core/boleto.rb +67 -34
- data/lib/boleto_bancario/core/bradesco.rb +28 -16
- data/lib/boleto_bancario/core/caixa.rb +233 -0
- data/lib/boleto_bancario/core/hsbc.rb +170 -0
- data/lib/boleto_bancario/core/itau.rb +20 -10
- data/lib/boleto_bancario/core/real.rb +177 -0
- data/lib/boleto_bancario/core/santander.rb +19 -22
- data/lib/boleto_bancario/core/sicoob.rb +172 -0
- data/lib/boleto_bancario/core/sicredi.rb +290 -0
- data/lib/boleto_bancario/version.rb +1 -2
- data/spec/boleto_bancario/calculos/modulo10_spec.rb +4 -0
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +6 -0
- data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_spec.rb +31 -0
- data/spec/boleto_bancario/calculos/modulo_numero_de_controle_spec.rb +37 -0
- data/spec/boleto_bancario/core/banco_brasil_spec.rb +59 -65
- data/spec/boleto_bancario/core/banrisul_spec.rb +129 -0
- data/spec/boleto_bancario/core/boleto_spec.rb +148 -32
- data/spec/boleto_bancario/core/bradesco_spec.rb +29 -36
- data/spec/boleto_bancario/core/caixa_spec.rb +111 -0
- data/spec/boleto_bancario/core/hsbc_spec.rb +72 -0
- data/spec/boleto_bancario/core/itau_spec.rb +33 -36
- data/spec/boleto_bancario/core/real_spec.rb +104 -0
- data/spec/boleto_bancario/core/santander_spec.rb +26 -24
- data/spec/boleto_bancario/core/sicoob_spec.rb +111 -0
- data/spec/boleto_bancario/core/sicredi_spec.rb +149 -0
- data/spec/inheritance/banco_brasil_spec.rb +22 -0
- data/spec/inheritance/banrisul_spec.rb +22 -0
- data/spec/inheritance/boleto_spec.rb +15 -0
- data/spec/inheritance/bradesco_spec.rb +22 -0
- data/spec/inheritance/caixa_spec.rb +22 -0
- data/spec/inheritance/hsbc_spec.rb +22 -0
- data/spec/inheritance/itau_spec.rb +22 -0
- data/spec/inheritance/real_spec.rb +22 -0
- data/spec/inheritance/santander_spec.rb +22 -0
- data/spec/inheritance/sicoob_spec.rb +22 -0
- data/spec/inheritance/sicredi_spec.rb +22 -0
- data/spec/shared_examples/boleto_bancario_shared_example.rb +21 -34
- data/spec/spec_helper.rb +2 -2
- metadata +119 -47
- data/.rvmrc +0 -1
@@ -16,19 +16,22 @@ module BoletoBancario
|
|
16
16
|
it { should have_valid(:numero_documento).when('1', '12', '123', '123456789112') }
|
17
17
|
it { should_not have_valid(:numero_documento).when('1234567891123', nil, '') }
|
18
18
|
|
19
|
-
it { should have_valid(:carteira).when('
|
20
|
-
it { should_not have_valid(:carteira).when('
|
19
|
+
it { should have_valid(:carteira).when('101', '102', '121', 101, 102, 121) }
|
20
|
+
it { should_not have_valid(:carteira).when(nil, '', '05', '20', '100', '120') }
|
21
|
+
|
22
|
+
it { should have_valid(:valor_documento).when(1, 1.99, 100.99, 99_999_999.99, '100.99') }
|
23
|
+
it { should_not have_valid(:valor_documento).when(nil, '', '100,99', 100_000_000.99) }
|
21
24
|
end
|
22
25
|
|
23
26
|
describe "#agencia" do
|
24
27
|
context "when have a value" do
|
25
28
|
subject { Santander.new(agencia: '2') }
|
26
29
|
|
27
|
-
|
30
|
+
it { expect(subject.agencia).to eq '0002' }
|
28
31
|
end
|
29
32
|
|
30
33
|
context "when is nil" do
|
31
|
-
|
34
|
+
it { expect(subject.agencia).to be nil }
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -36,11 +39,11 @@ module BoletoBancario
|
|
36
39
|
context "when have a value" do
|
37
40
|
subject { Santander.new(codigo_cedente: '1') }
|
38
41
|
|
39
|
-
|
42
|
+
it { expect(subject.codigo_cedente).to eq '0000001' }
|
40
43
|
end
|
41
44
|
|
42
45
|
context "when is nil" do
|
43
|
-
|
46
|
+
it { expect(subject.codigo_cedente).to be nil }
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
@@ -48,23 +51,23 @@ module BoletoBancario
|
|
48
51
|
context "when have a value" do
|
49
52
|
subject { Santander.new(numero_documento: '1') }
|
50
53
|
|
51
|
-
|
54
|
+
it { expect(subject.numero_documento).to eq '000000000001' }
|
52
55
|
end
|
53
56
|
|
54
57
|
context "when is nil" do
|
55
|
-
|
58
|
+
it { expect(subject.numero_documento).to be nil }
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
62
|
describe "#carteira" do
|
60
63
|
context "when have a value" do
|
61
|
-
subject { Santander.new(carteira: '
|
64
|
+
subject { Santander.new(carteira: '101') }
|
62
65
|
|
63
|
-
|
66
|
+
it { expect(subject.carteira).to eq '101' }
|
64
67
|
end
|
65
68
|
|
66
69
|
context "when is nil" do
|
67
|
-
|
70
|
+
it { expect(subject.carteira).to be nil }
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
@@ -72,34 +75,34 @@ module BoletoBancario
|
|
72
75
|
context "when is registered" do
|
73
76
|
subject { Santander.new(:carteira => 101) }
|
74
77
|
|
75
|
-
|
78
|
+
it { expect(subject.carteira_formatada).to eq 'COBRANÇA SIMPLES ECR' }
|
76
79
|
end
|
77
80
|
|
78
81
|
context "when isn't registered" do
|
79
82
|
subject { Santander.new(:carteira => 102) }
|
80
83
|
|
81
|
-
|
84
|
+
it { expect(subject.carteira_formatada).to eq 'COBRANÇA SIMPLES CSR' }
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
85
88
|
describe "#codigo_banco" do
|
86
|
-
|
89
|
+
it { expect(subject.codigo_banco).to eq '033' }
|
87
90
|
end
|
88
91
|
|
89
92
|
describe "#digito_codigo_banco" do
|
90
|
-
|
93
|
+
it { expect(subject.digito_codigo_banco).to eq '7' }
|
91
94
|
end
|
92
95
|
|
93
96
|
describe "#agencia_codigo_cedente" do
|
94
|
-
subject { Santander.new(agencia: '0235',
|
97
|
+
subject { Santander.new(agencia: '0235', codigo_cedente: '1625462') }
|
95
98
|
|
96
|
-
|
99
|
+
it { expect(subject.agencia_codigo_cedente).to eq '0235 / 1625462' }
|
97
100
|
end
|
98
101
|
|
99
102
|
describe "#nosso_numero" do
|
100
103
|
subject { Santander.new(numero_documento: '566612457800') }
|
101
104
|
|
102
|
-
|
105
|
+
it { expect(subject.nosso_numero).to eq '566612457800-2' }
|
103
106
|
end
|
104
107
|
|
105
108
|
describe "#codigo_de_barras" do
|
@@ -110,26 +113,25 @@ module BoletoBancario
|
|
110
113
|
santander.valor_documento = 2952.95
|
111
114
|
santander.carteira = '102'
|
112
115
|
santander.agencia = 1333
|
113
|
-
santander.digito_agencia = 1
|
114
116
|
santander.data_vencimento = Date.parse('2012-12-28')
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
+
it { expect(subject.codigo_de_barras).to eq '03391556100002952959070707700000123456790102' }
|
121
|
+
it { expect(subject.linha_digitavel).to eq '03399.07073 07700.000123 34567.901029 1 55610000295295' }
|
120
122
|
end
|
121
123
|
|
122
124
|
describe "#iof" do
|
123
125
|
context "default iof" do
|
124
|
-
|
126
|
+
it { expect(subject.iof).to eq '0' }
|
125
127
|
end
|
126
128
|
|
127
129
|
context "setting iof" do
|
128
130
|
subject { Santander.new(iof: 7) }
|
129
131
|
|
130
|
-
|
132
|
+
it { expect(subject.iof).to eq '7' }
|
131
133
|
end
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|
135
|
-
end
|
137
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module BoletoBancario
|
5
|
+
module Core
|
6
|
+
describe Sicoob 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', 12345, '1234567') }
|
14
|
+
it { should_not have_valid(:codigo_cedente).when('12345678', 123456789, nil, '') }
|
15
|
+
|
16
|
+
it { should have_valid(:numero_documento).when('1', 12345, '123456') }
|
17
|
+
it { should_not have_valid(:numero_documento).when('1234567', nil, '') }
|
18
|
+
|
19
|
+
it { should have_valid(:carteira).when('1', 1, '9', 9) }
|
20
|
+
it { should_not have_valid(:carteira).when(nil, '', 2, '6') }
|
21
|
+
|
22
|
+
it { should have_valid(:valor_documento).when(1, 1.99, 100.99, 99_999_999.99, '100.99') }
|
23
|
+
it { should_not have_valid(:valor_documento).when(nil, '', '100,99', 100_000_000.99) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#agencia" do
|
27
|
+
context "when have a value" do
|
28
|
+
subject { Sicoob.new(agencia: '215') }
|
29
|
+
|
30
|
+
it { expect(subject.agencia).to eq '0215' }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when is nil" do
|
34
|
+
it { expect(subject.agencia).to be nil }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#conta_corrente" do
|
39
|
+
context "when have a value" do
|
40
|
+
subject { Sicoob.new(codigo_cedente: '9201') }
|
41
|
+
|
42
|
+
it { expect(subject.codigo_cedente).to eq '0009201' }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when is nil" do
|
46
|
+
it { expect(subject.codigo_cedente).to be nil }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#numero_documento" do
|
51
|
+
context "when have a value" do
|
52
|
+
subject { Sicoob.new(numero_documento: '1') }
|
53
|
+
|
54
|
+
it { expect(subject.numero_documento).to eq '000001' }
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when is nil" do
|
58
|
+
it { expect(subject.numero_documento).to be nil }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#carteira" do
|
63
|
+
context "when have a value" do
|
64
|
+
subject { Sicoob.new(carteira: '1') }
|
65
|
+
|
66
|
+
it { expect(subject.carteira).to eq '1' }
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when is nil" do
|
70
|
+
it { expect(subject.carteira).to be nil }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#codigo_banco" do
|
75
|
+
it { expect(subject.codigo_banco).to eq '756' }
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#digito_codigo_banco" do
|
79
|
+
it { expect(subject.digito_codigo_banco).to eq '0' }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#agencia_codigo_beneficiario" do
|
83
|
+
subject { Sicoob.new(agencia: 48, codigo_cedente: '7368') }
|
84
|
+
|
85
|
+
it { expect(subject.agencia_codigo_cedente).to eq '0048 / 0007368' }
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#nosso_numero" do
|
89
|
+
subject { Sicoob.new(numero_documento: '68315') }
|
90
|
+
|
91
|
+
it { expect(subject.nosso_numero).to eq '15068315' }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#codigo_de_barras" do
|
95
|
+
subject do
|
96
|
+
Sicoob.new do |sicoob|
|
97
|
+
sicoob.agencia = 95
|
98
|
+
sicoob.codigo_cedente = 6532
|
99
|
+
sicoob.numero_documento = 1101
|
100
|
+
sicoob.carteira = 1
|
101
|
+
sicoob.valor_documento = 93015.78
|
102
|
+
sicoob.data_vencimento = Date.parse('2019-02-17')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it { expect(subject.codigo_de_barras).to eq '75692780300093015781009501000653215001101001' }
|
107
|
+
it { expect(subject.linha_digitavel).to eq '75691.00956 01000.653210 50011.010019 2 78030009301578' }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module BoletoBancario
|
5
|
+
module Core
|
6
|
+
describe Sicredi 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(:conta_corrente).when('1', '12', '123', '12345') }
|
14
|
+
it { should_not have_valid(:conta_corrente).when('123456', '1234567', nil, '') }
|
15
|
+
|
16
|
+
it { should have_valid(:numero_documento).when('1', '12', '123', '12345') }
|
17
|
+
it { should_not have_valid(:numero_documento).when('123456', nil, '') }
|
18
|
+
|
19
|
+
it { should have_valid(:carteira).when('03', 'C') }
|
20
|
+
it { should_not have_valid(:carteira).when(nil, '', '05', '20', '100', '120') }
|
21
|
+
|
22
|
+
it { should have_valid(:posto).when('1', '56', 34, 99) }
|
23
|
+
it { should_not have_valid(:posto).when(nil, '', '100', 100) }
|
24
|
+
|
25
|
+
it { should have_valid(:byte_id).when('2', 2, 5, '9') }
|
26
|
+
it { should_not have_valid(:byte_id).when(nil, '', '1', 1, 10, '100') }
|
27
|
+
|
28
|
+
it { should have_valid(:valor_documento).when(1, 1.99, 100.99, 99_999_999.99, '100.99') }
|
29
|
+
it { should_not have_valid(:valor_documento).when(nil, '', '100,99', 100_000_000.99) }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#agencia" do
|
33
|
+
context "when have a value" do
|
34
|
+
subject { Sicredi.new(agencia: '530') }
|
35
|
+
|
36
|
+
it { expect(subject.agencia).to eq '0530' }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when is nil" do
|
40
|
+
it { expect(subject.agencia).to be nil }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#conta_corrente" do
|
45
|
+
context "when have a value" do
|
46
|
+
subject { Sicredi.new(conta_corrente: '96') }
|
47
|
+
|
48
|
+
it { expect(subject.conta_corrente).to eq '00096' }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when is nil" do
|
52
|
+
it { expect(subject.conta_corrente).to be nil }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#numero_documento" do
|
57
|
+
context "when have a value" do
|
58
|
+
subject { Sicredi.new(numero_documento: '1') }
|
59
|
+
|
60
|
+
it { expect(subject.numero_documento).to eq '00001' }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when is nil" do
|
64
|
+
it { expect(subject.numero_documento).to be nil }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#carteira" do
|
69
|
+
context "when have a value" do
|
70
|
+
subject { Sicredi.new(carteira: '03') }
|
71
|
+
|
72
|
+
it { expect(subject.carteira).to eq '03' }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when is nil" do
|
76
|
+
it { expect(subject.carteira).to be nil }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#carteira_formatada" do
|
81
|
+
context "when is registered" do
|
82
|
+
subject { Sicredi.new(carteira: '03') }
|
83
|
+
|
84
|
+
it { expect(subject.carteira_formatada).to eq '1' }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when isn't registered" do
|
88
|
+
subject { Sicredi.new(carteira: 'C') }
|
89
|
+
|
90
|
+
it { expect(subject.carteira_formatada).to eq '1' }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#codigo_banco" do
|
95
|
+
it { expect(subject.codigo_banco).to eq '748' }
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#digito_codigo_banco" do
|
99
|
+
it { expect(subject.digito_codigo_banco).to eq 'X' }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#tipo_cobranca" do
|
103
|
+
it { expect(subject.tipo_cobranca).to eq '3' }
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#tipo_carteira" do
|
107
|
+
it { expect(subject.tipo_carteira).to eq '1' }
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#agencia_codigo_beneficiario" do
|
111
|
+
subject { Sicredi.new(agencia: '7190', posto: 2, conta_corrente: '25439') }
|
112
|
+
|
113
|
+
it { expect(subject.agencia_codigo_cedente).to eq '7190.02.25439' }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#nosso_numero" do
|
117
|
+
subject do
|
118
|
+
Sicredi.new do |sicredi|
|
119
|
+
sicredi.agencia = 4927
|
120
|
+
sicredi.posto = '99'
|
121
|
+
sicredi.conta_corrente = 24837
|
122
|
+
sicredi.byte_id = '9'
|
123
|
+
sicredi.numero_documento = '72815'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it { expect(subject.nosso_numero).to eq '15/972815-9' }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#codigo_de_barras" do
|
131
|
+
subject do
|
132
|
+
Sicredi.new do |sicredi|
|
133
|
+
sicredi.agencia = '8136'
|
134
|
+
sicredi.conta_corrente = '62918'
|
135
|
+
sicredi.posto = 34
|
136
|
+
sicredi.byte_id = 3
|
137
|
+
sicredi.carteira = '03'
|
138
|
+
sicredi.numero_documento = 87264
|
139
|
+
sicredi.valor_documento = 8013.65
|
140
|
+
sicredi.data_vencimento = Date.parse('2006-10-29')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it { expect(subject.codigo_de_barras).to eq '74894330900008013653115387264581363462918104' }
|
145
|
+
it { expect(subject.linha_digitavel).to eq '74893.11535 87264.581361 34629.181040 4 33090000801365' }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class BancoBrasil < BoletoBancario::BancoBrasil
|
5
|
+
def self.valor_documento_tamanho_maximo
|
6
|
+
100 # Default 99999999.99
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.carteiras_suportadas
|
10
|
+
%w[12 17] # Default %w[12 16 17 18]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe BancoBrasil do
|
15
|
+
describe "on validations" do
|
16
|
+
it { should have_valid(:valor_documento).when(99, 99.99, 25) }
|
17
|
+
it { should_not have_valid(:valor_documento).when(100.01, 150) }
|
18
|
+
|
19
|
+
it { should have_valid(:carteira).when(12, 17) }
|
20
|
+
it { should_not have_valid(:carteira).when(16, 18, 20) }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class Banrisul < BoletoBancario::Banrisul
|
5
|
+
def self.valor_documento_tamanho_maximo
|
6
|
+
250 # Default 99999999.99
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.carteiras_suportadas
|
10
|
+
%w[00] # Default %w[00 08]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Banrisul do
|
15
|
+
describe "on validations" do
|
16
|
+
it { should have_valid(:valor_documento).when(99, 249, 250) }
|
17
|
+
it { should_not have_valid(:valor_documento).when(250.01, 260) }
|
18
|
+
|
19
|
+
it { should have_valid(:carteira).when('00', 0) }
|
20
|
+
it { should_not have_valid(:carteira).when('08', 8, 10) }
|
21
|
+
end
|
22
|
+
end
|