conectiva-boleto_bancario 0.0.2.beta
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 +18 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Changelog.markdown +10 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/Planning.markdown +137 -0
- data/README.markdown +215 -0
- data/Rakefile +9 -0
- data/TODO.markdown +11 -0
- data/boleto_bancario.gemspec +25 -0
- data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
- data/lib/boleto_bancario.rb +85 -0
- data/lib/boleto_bancario/calculos/digitos.rb +35 -0
- data/lib/boleto_bancario/calculos/fator_vencimento.rb +87 -0
- data/lib/boleto_bancario/calculos/fatores_de_multiplicacao.rb +67 -0
- data/lib/boleto_bancario/calculos/linha_digitavel.rb +158 -0
- data/lib/boleto_bancario/calculos/modulo10.rb +83 -0
- data/lib/boleto_bancario/calculos/modulo11.rb +54 -0
- data/lib/boleto_bancario/calculos/modulo11_fator_de2a7.rb +97 -0
- data/lib/boleto_bancario/calculos/modulo11_fator_de2a9.rb +83 -0
- data/lib/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
- data/lib/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x.rb +101 -0
- data/lib/boleto_bancario/calculos/modulo_numero_de_controle.rb +117 -0
- data/lib/boleto_bancario/core/banco_brasil.rb +532 -0
- data/lib/boleto_bancario/core/banrisul.rb +182 -0
- data/lib/boleto_bancario/core/boleto.rb +559 -0
- data/lib/boleto_bancario/core/bradesco.rb +285 -0
- data/lib/boleto_bancario/core/itau.rb +455 -0
- data/lib/boleto_bancario/core/santander.rb +273 -0
- data/lib/boleto_bancario/version.rb +4 -0
- data/spec/boleto_bancario/calculos/digitos_spec.rb +19 -0
- data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +59 -0
- data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +69 -0
- data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +57 -0
- data/spec/boleto_bancario/calculos/modulo10_spec.rb +53 -0
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +43 -0
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +39 -0
- data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +67 -0
- data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +37 -0
- data/spec/boleto_bancario/calculos/modulo11_spec.rb +19 -0
- data/spec/boleto_bancario/calculos/modulo_numero_de_controle_spec.rb +37 -0
- data/spec/boleto_bancario/core/banco_brasil_spec.rb +383 -0
- data/spec/boleto_bancario/core/banrisul_spec.rb +130 -0
- data/spec/boleto_bancario/core/boleto_spec.rb +161 -0
- data/spec/boleto_bancario/core/bradesco_spec.rb +170 -0
- data/spec/boleto_bancario/core/itau_spec.rb +336 -0
- data/spec/boleto_bancario/core/santander_spec.rb +135 -0
- data/spec/shared_examples/boleto_bancario_shared_example.rb +157 -0
- data/spec/spec_helper.rb +14 -0
- metadata +211 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe Modulo10 do
|
6
|
+
it "should accept the examples by the 'Itau documentation'" do
|
7
|
+
Modulo10.new('341911012').should eq '1'
|
8
|
+
Modulo10.new('3456788005').should eq '8'
|
9
|
+
Modulo10.new('7123457000').should eq '1'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should accept the example from Banrisul" do
|
13
|
+
Modulo10.new('00009274').should eq '2'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns zero when number is 0" do
|
17
|
+
Modulo10.new('0').should eq '0'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns zero when mod 10 is zero" do
|
21
|
+
Modulo10.new('99906').should eq '0'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "calculate when number had 1 digit" do
|
25
|
+
Modulo10.new('1').should eq '8'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "calculate when number had 2 digits" do
|
29
|
+
Modulo10.new('10').should eq '9'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "calculate when number had 3 digits" do
|
33
|
+
Modulo10.new('994').should eq '4'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "calculate when number had 5 digits" do
|
37
|
+
Modulo10.new('97831').should eq '2'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "calculate when number had 6 digits" do
|
41
|
+
Modulo10.new('147966').should eq '6'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "calculate when number had 10 digits" do
|
45
|
+
Modulo10.new('3456788005').should eq '8'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should accept numbers too" do
|
49
|
+
Modulo10.new(12345).should eq '5'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe Modulo11FatorDe2a7 do
|
6
|
+
context 'with Bradesco documentation example' do
|
7
|
+
subject { Modulo11FatorDe2a7.new('1900000000002') }
|
8
|
+
|
9
|
+
it { should eq '8' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with Bradesco example that returns P' do
|
13
|
+
subject { Modulo11FatorDe2a7.new('1900000000001') }
|
14
|
+
|
15
|
+
it { should eq 'P' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with Bradesco example that returns zero' do
|
19
|
+
subject { Modulo11FatorDe2a7.new('1900000000006') }
|
20
|
+
|
21
|
+
it { should eq '0' }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when have two digits" do
|
25
|
+
subject { Modulo11FatorDe2a7.new('20') }
|
26
|
+
|
27
|
+
it { should eq '5' }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when have two digits (more examples)" do
|
31
|
+
subject { Modulo11FatorDe2a7.new('26') }
|
32
|
+
|
33
|
+
it { should eq '4' }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "more examples" do
|
37
|
+
subject { Modulo11FatorDe2a7.new('64') }
|
38
|
+
|
39
|
+
it { should eq '7' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe Modulo11FatorDe2a9RestoZero do
|
6
|
+
describe "#calculate" do
|
7
|
+
context "with a one number digit" do
|
8
|
+
subject { Modulo11FatorDe2a9RestoZero.new(6) }
|
9
|
+
|
10
|
+
it { should eq '0' }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with a two number digit" do
|
14
|
+
subject { Modulo11FatorDe2a9RestoZero.new(100) }
|
15
|
+
|
16
|
+
it { should eq '7' }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with a three number digit" do
|
20
|
+
subject { Modulo11FatorDe2a9RestoZero.new(1004) }
|
21
|
+
|
22
|
+
it { should eq '9' }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with a three number digit that returns zero" do
|
26
|
+
subject { Modulo11FatorDe2a9RestoZero.new(1088) }
|
27
|
+
|
28
|
+
it { should eq '0' }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when mod division return '10'" do
|
32
|
+
subject { Modulo11FatorDe2a9RestoZero.new(1073) }
|
33
|
+
|
34
|
+
it { should eq '1' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe Modulo11FatorDe2a9 do
|
6
|
+
context 'with Itau example' do
|
7
|
+
subject { Modulo11FatorDe2a9.new('3419166700000123451101234567880057123457000') }
|
8
|
+
|
9
|
+
it { should eq '6' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with Bradesco example' do
|
13
|
+
subject { Modulo11FatorDe2a9.new('9999101200000350007772130530150081897500000') }
|
14
|
+
|
15
|
+
it { should eq '1' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with Banco Brasil example' do
|
19
|
+
subject { Modulo11FatorDe2a9.new('0019373700000001000500940144816060680935031') }
|
20
|
+
|
21
|
+
it { should eq '3' }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with Caixa example' do
|
25
|
+
subject { Modulo11FatorDe2a9.new('1049107400000160000001100128701000901200200') }
|
26
|
+
|
27
|
+
it { should eq '1' }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with Banrisul example' do
|
31
|
+
subject { Modulo11FatorDe2a9.new('0419100100000550002110000000012283256304168') }
|
32
|
+
|
33
|
+
it { should eq '1' }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when calculations returns 11' do
|
37
|
+
subject { Modulo11FatorDe2a9.new('1049107400000160000001100128701000901200298') }
|
38
|
+
|
39
|
+
it { should eq '1' }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when calculations returns 1' do
|
43
|
+
subject { Modulo11FatorDe2a9.new('1049107400000160000001100128701000901244437') }
|
44
|
+
|
45
|
+
it { should eq '1' }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with one digit' do
|
49
|
+
subject { Modulo11FatorDe2a9.new('1') }
|
50
|
+
|
51
|
+
it { should eq '9' }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with two digits' do
|
55
|
+
subject { Modulo11FatorDe2a9.new('91') }
|
56
|
+
|
57
|
+
it { should eq '4' }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with three digits' do
|
61
|
+
subject { Modulo11FatorDe2a9.new('189') }
|
62
|
+
|
63
|
+
it { should eq '9' }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe Modulo11FatorDe9a2RestoX do
|
6
|
+
context "when the mod result is 10 (ten)" do
|
7
|
+
subject { Modulo11FatorDe9a2RestoX.new('3973') }
|
8
|
+
|
9
|
+
it { should eq 'X' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when the mod result is zero" do
|
13
|
+
subject { Modulo11FatorDe9a2RestoX.new('3995') }
|
14
|
+
|
15
|
+
it { should eq '0' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "using the 'Banco Brasil' documentation example" do
|
19
|
+
subject { Modulo11FatorDe9a2RestoX.new('01129004590') }
|
20
|
+
|
21
|
+
it { should eq '3' }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the result is one" do
|
25
|
+
subject { Modulo11FatorDe9a2RestoX.new('5964') }
|
26
|
+
|
27
|
+
it { should eq '1' }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with a five digit number" do
|
31
|
+
subject { Modulo11FatorDe9a2RestoX.new('10949') }
|
32
|
+
|
33
|
+
it { should eq '5' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe Modulo11 do
|
6
|
+
subject { Modulo11.new(1) }
|
7
|
+
|
8
|
+
describe "#fatores" do
|
9
|
+
before { Modulo11.any_instance.stub(:calculate).and_return(1) }
|
10
|
+
|
11
|
+
it { expect { subject.fatores }.to raise_error(NotImplementedError, "Not implemented #fatores in subclass.") }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#calculate" do
|
15
|
+
it { expect { Modulo11.new(1) }.to raise_error(NotImplementedError, "Not implemented #calculate in subclass.") }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BoletoBancario
|
4
|
+
module Calculos
|
5
|
+
describe ModuloNumeroDeControle do
|
6
|
+
context "when is simple calculation" do
|
7
|
+
subject { ModuloNumeroDeControle.new('00009274') }
|
8
|
+
|
9
|
+
it { should eq '22' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "another example" do
|
13
|
+
subject { ModuloNumeroDeControle.new('0000001') }
|
14
|
+
|
15
|
+
it { should eq '83' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "example with second digit invalid" do
|
19
|
+
subject { ModuloNumeroDeControle.new('00009194') }
|
20
|
+
|
21
|
+
it { should eq '38' }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "example with second digit invalid and first digit with '9'" do
|
25
|
+
subject { ModuloNumeroDeControle.new('411') }
|
26
|
+
|
27
|
+
it { should eq '06' }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'should calculate when the first digit is not 10 (ten)' do
|
31
|
+
subject { ModuloNumeroDeControle.new('5') }
|
32
|
+
|
33
|
+
it { should eq '90' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,383 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module BoletoBancario
|
5
|
+
module Core
|
6
|
+
describe BancoBrasil do
|
7
|
+
it_should_behave_like 'boleto bancario'
|
8
|
+
|
9
|
+
describe "on validations" do
|
10
|
+
context "#agencia" do
|
11
|
+
it { should have_valid(:agencia).when('123', '1234') }
|
12
|
+
it { should_not have_valid(:agencia).when('12345', '123456', nil, '') }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#digito_agencia" do
|
16
|
+
it { should have_valid(:digito_agencia).when('1', '3', 'X') }
|
17
|
+
it { should_not have_valid(:digito_agencia).when('12', nil, '') }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#conta_corrente" do
|
21
|
+
it { should have_valid(:conta_corrente).when('12345678', '12345', '1234') }
|
22
|
+
it { should_not have_valid(:conta_corrente).when('123456789', nil, '') }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#digito_conta_corrente" do
|
26
|
+
it { should have_valid(:digito_conta_corrente).when('1') }
|
27
|
+
it { should_not have_valid(:digito_conta_corrente).when('12', nil, '') }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#codigo_cedente" do
|
31
|
+
it { should have_valid(:codigo_cedente).when('1234', '123456', '1234567', '12345678') }
|
32
|
+
it { should_not have_valid(:codigo_cedente).when('123', '1', '12', nil, '') }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when 'carteira' is 16 and 'codigo_cedente' 6 digits" do
|
36
|
+
subject { BancoBrasil.new(carteira: 16, codigo_cedente: 123456) }
|
37
|
+
|
38
|
+
it { should have_valid(:numero_documento).when('1234', '12345', '12345', '12345678911234567') }
|
39
|
+
it { should_not have_valid(:numero_documento).when(nil, '', '123456', '123456789112345678') }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when 'carteira' is 18 and 'codigo_cedente' 6 digits" do
|
43
|
+
subject { BancoBrasil.new(carteira: 18, codigo_cedente: 123456) }
|
44
|
+
|
45
|
+
it { should have_valid(:numero_documento).when('1234', '12345', '12345678911234567') }
|
46
|
+
it { should_not have_valid(:numero_documento).when(nil, '', '123456', '1234567', '123456789112345678') }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when 'carteira' is 12 and 'codigo_cedente' 6 digits" do
|
50
|
+
subject { BancoBrasil.new(carteira: 12, codigo_cedente: 123456) }
|
51
|
+
|
52
|
+
it { should have_valid(:numero_documento).when('12345', '1234') }
|
53
|
+
it { should_not have_valid(:numero_documento).when(nil, '', '123456', '12345678911234567') }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when 'codigo_cedente' 4 digits" do
|
57
|
+
subject { BancoBrasil.new(codigo_cedente: 1234) }
|
58
|
+
|
59
|
+
it { should have_valid(:numero_documento).when('123', '1235', '1234567') }
|
60
|
+
it { should_not have_valid(:numero_documento).when(nil, '', '12345678', '12345678911234567') }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when 'codigo_cedente' 7 digits" do
|
64
|
+
subject { BancoBrasil.new(codigo_cedente: 1234567) }
|
65
|
+
|
66
|
+
it { should have_valid(:numero_documento).when('1234567890', '1235', '1234567') }
|
67
|
+
it { should_not have_valid(:numero_documento).when(nil, '', '12345678901', '12345678911234567') }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when 'codigo_cedente' 8 digits" do
|
71
|
+
subject { BancoBrasil.new(codigo_cedente: 12345678) }
|
72
|
+
|
73
|
+
it { should have_valid(:numero_documento).when('123456789', '1235', '1234567') }
|
74
|
+
it { should_not have_valid(:numero_documento).when(nil, '', '1234567890', '12345678911234567') }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#agencia" do
|
79
|
+
context "when have a value" do
|
80
|
+
subject { BancoBrasil.new(:agencia => '001') }
|
81
|
+
|
82
|
+
its(:agencia) { should eq '0001' }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when is nil" do
|
86
|
+
subject { BancoBrasil.new(:agencia => nil) }
|
87
|
+
|
88
|
+
its(:agencia) { should be nil }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#conta_corrente" do
|
93
|
+
context "when have a value" do
|
94
|
+
subject { BancoBrasil.new(:conta_corrente => 913) }
|
95
|
+
|
96
|
+
its(:conta_corrente) { should eq '00000913' }
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when is nil" do
|
100
|
+
subject { BancoBrasil.new(:conta_corrente => nil) }
|
101
|
+
|
102
|
+
its(:conta_corrente) { should be nil }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#numero_documento" do
|
107
|
+
context "when have 'codigo_cedente' 4 digits" do
|
108
|
+
subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 1234) }
|
109
|
+
|
110
|
+
its(:numero_documento) { should eq '0000913' }
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when have 'codigo_cedente' 6 digits" do
|
114
|
+
subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 123456) }
|
115
|
+
|
116
|
+
its(:numero_documento) { should eq '00913' }
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when have 'codigo_cedente' 7 digits" do
|
120
|
+
subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 1234567) }
|
121
|
+
|
122
|
+
its(:numero_documento) { should eq '0000000913' }
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when have 'codigo_cedente' 8 digits" do
|
126
|
+
subject { BancoBrasil.new(:numero_documento => 913, :codigo_cedente => 12345678) }
|
127
|
+
|
128
|
+
its(:numero_documento) { should eq '000000913' }
|
129
|
+
end
|
130
|
+
|
131
|
+
context "when is nil" do
|
132
|
+
subject { BancoBrasil.new(:numero_documento => nil) }
|
133
|
+
|
134
|
+
its(:numero_documento) { should be nil }
|
135
|
+
end
|
136
|
+
|
137
|
+
context "when 'codigo_cedente' is nil" do
|
138
|
+
subject { BancoBrasil.new(:numero_documento => '12') }
|
139
|
+
|
140
|
+
its(:numero_documento) { should eq '12' }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#codigo_banco" do
|
145
|
+
its(:codigo_banco) { should eq '001' }
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "#digito_codigo_banco" do
|
149
|
+
its(:digito_codigo_banco) { should eq '9' }
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#agencia_codigo_cedente" do
|
153
|
+
subject { BancoBrasil.new(agencia: 9999, digito_agencia: 6, conta_corrente: 99999, digito_conta_corrente: 7) }
|
154
|
+
|
155
|
+
its(:agencia_codigo_cedente) { should eq '9999-6 / 00099999-7' }
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#nosso_numero" do
|
159
|
+
context "when 'codigo_cedente 4 digits" do
|
160
|
+
subject { BancoBrasil.new(codigo_cedente: 1234, numero_documento: 1984) }
|
161
|
+
|
162
|
+
its(:nosso_numero) { should eq '12340001984-7' }
|
163
|
+
end
|
164
|
+
|
165
|
+
context "when 'codigo_cedente 6 digits" do
|
166
|
+
subject { BancoBrasil.new(codigo_cedente: 123456, numero_documento: 1984) }
|
167
|
+
|
168
|
+
its(:nosso_numero) { should eq '12345601984-2' }
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when 'codigo_cedente 7 digits" do
|
172
|
+
subject { BancoBrasil.new(codigo_cedente: 1234567, numero_documento: 1984) }
|
173
|
+
|
174
|
+
its(:nosso_numero) { should eq '12345670000001984' }
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when 'codigo_cedente 8 digits" do
|
178
|
+
subject { BancoBrasil.new(codigo_cedente: 12345678, numero_documento: 1984) }
|
179
|
+
|
180
|
+
its(:nosso_numero) { should eq '12345678000001984' }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#codigo_cedente_quatro_digitos?" do
|
185
|
+
context "when is true" do
|
186
|
+
subject { BancoBrasil.new(codigo_cedente: 1234) }
|
187
|
+
|
188
|
+
its(:codigo_cedente_quatro_digitos?) { should be true }
|
189
|
+
end
|
190
|
+
|
191
|
+
context "when is false" do
|
192
|
+
subject { BancoBrasil.new(codigo_cedente: 12345) }
|
193
|
+
|
194
|
+
its(:codigo_cedente_quatro_digitos?) { should be false }
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "#codigo_cedente_seis_digitos?" do
|
199
|
+
context "when is true" do
|
200
|
+
subject { BancoBrasil.new(codigo_cedente: 123456) }
|
201
|
+
|
202
|
+
its(:codigo_cedente_seis_digitos?) { should be true }
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when is false" do
|
206
|
+
subject { BancoBrasil.new(codigo_cedente: 1234567) }
|
207
|
+
|
208
|
+
its(:codigo_cedente_seis_digitos?) { should be false }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#codigo_cedente_sete_digitos?" do
|
213
|
+
context "when is true" do
|
214
|
+
subject { BancoBrasil.new(codigo_cedente: 1234567) }
|
215
|
+
|
216
|
+
its(:codigo_cedente_sete_digitos?) { should be true }
|
217
|
+
end
|
218
|
+
|
219
|
+
context "when is false" do
|
220
|
+
subject { BancoBrasil.new(codigo_cedente: 12345678) }
|
221
|
+
|
222
|
+
its(:codigo_cedente_sete_digitos?) { should be false }
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "#codigo_cedente_oito_digitos?" do
|
227
|
+
context "when is true" do
|
228
|
+
subject { BancoBrasil.new(codigo_cedente: 12345678) }
|
229
|
+
|
230
|
+
its(:codigo_cedente_oito_digitos?) { should be true }
|
231
|
+
end
|
232
|
+
|
233
|
+
context "when is false" do
|
234
|
+
subject { BancoBrasil.new(codigo_cedente: 123456789) }
|
235
|
+
|
236
|
+
its(:codigo_cedente_oito_digitos?) { should be false }
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "#nosso_numero_dezessete_posicoes?" do
|
241
|
+
context "when 'carteira' 18, 'numero_documento' 17 digits and 'codigo_cedente' 6 digits" do
|
242
|
+
subject { BancoBrasil.new(numero_documento: 12345678911234567, carteira: 18, codigo_cedente: 123456) }
|
243
|
+
|
244
|
+
its(:nosso_numero_dezessete_posicoes?) { should be true }
|
245
|
+
end
|
246
|
+
|
247
|
+
context "when 'carteira' 16, 'numero_documento' 17 digits and 'codigo_cedente' 6 digits" do
|
248
|
+
subject { BancoBrasil.new(numero_documento: 12345678911234567, carteira: 16, codigo_cedente: 123456) }
|
249
|
+
|
250
|
+
its(:nosso_numero_dezessete_posicoes?) { should be true }
|
251
|
+
end
|
252
|
+
|
253
|
+
context "when is 'carteira' is not supported" do
|
254
|
+
subject { BancoBrasil.new(numero_documento: 123456789, carteira: 12, codigo_cedente: 123456) }
|
255
|
+
|
256
|
+
its(:nosso_numero_dezessete_posicoes?) { should be false }
|
257
|
+
end
|
258
|
+
|
259
|
+
context "when is 'codigo_cedente' is not supported" do
|
260
|
+
subject { BancoBrasil.new(numero_documento: 123456789, carteira: 16, codigo_cedente: 1234567) }
|
261
|
+
|
262
|
+
its(:nosso_numero_dezessete_posicoes?) { should be false }
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "#codigo_de_barras" do
|
267
|
+
context "'codigo_cedente' with 4 digits" do
|
268
|
+
subject do
|
269
|
+
BancoBrasil.new do |banco_brasil|
|
270
|
+
banco_brasil.carteira = 18
|
271
|
+
banco_brasil.valor_documento = 2952.95
|
272
|
+
banco_brasil.numero_documento = 90801
|
273
|
+
banco_brasil.agencia = 7123
|
274
|
+
banco_brasil.digito_agencia = 6
|
275
|
+
banco_brasil.conta_corrente = 19345
|
276
|
+
banco_brasil.digito_conta_corrente = 7
|
277
|
+
banco_brasil.data_vencimento = Date.parse('2012-12-28')
|
278
|
+
banco_brasil.codigo_cedente = 4321
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
its(:codigo_de_barras) { should eq '00193556100002952954321009080171230001934518' }
|
283
|
+
its(:linha_digitavel) { should eq '00194.32103 09080.171235 00019.345180 3 55610000295295' }
|
284
|
+
end
|
285
|
+
|
286
|
+
context "'codigo_cedente' with 6 digits" do
|
287
|
+
subject do
|
288
|
+
BancoBrasil.new do |banco_brasil|
|
289
|
+
banco_brasil.carteira = 18
|
290
|
+
banco_brasil.valor_documento = 14001.99
|
291
|
+
banco_brasil.numero_documento = 12901
|
292
|
+
banco_brasil.agencia = 5030
|
293
|
+
banco_brasil.digito_agencia = 6
|
294
|
+
banco_brasil.conta_corrente = 14204195
|
295
|
+
banco_brasil.digito_conta_corrente = 7
|
296
|
+
banco_brasil.data_vencimento = Date.parse('2012-12-28')
|
297
|
+
banco_brasil.codigo_cedente = 555444
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
its(:codigo_de_barras) { should eq '00197556100014001995554441290150301420419518' }
|
302
|
+
its(:linha_digitavel) { should eq '00195.55440 41290.150303 14204.195185 7 55610001400199' }
|
303
|
+
end
|
304
|
+
|
305
|
+
context "'codigo_cedente' with 6 digits and 'nosso numero' with 17 digits" do
|
306
|
+
subject do
|
307
|
+
BancoBrasil.new do |banco_brasil|
|
308
|
+
banco_brasil.carteira = 12
|
309
|
+
banco_brasil.valor_documento = 14001.99
|
310
|
+
banco_brasil.numero_documento = 12345678911234567
|
311
|
+
banco_brasil.agencia = 5030
|
312
|
+
banco_brasil.digito_agencia = 6
|
313
|
+
banco_brasil.conta_corrente = 14204195
|
314
|
+
banco_brasil.digito_conta_corrente = 7
|
315
|
+
banco_brasil.data_vencimento = Date.parse('2012-12-28')
|
316
|
+
banco_brasil.codigo_cedente = 555444
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
its(:linha_digitavel) { should eq "" }
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
context "'codigo_cedente' with 6 digits and 'nosso numero' with 17 digits" do
|
325
|
+
subject do
|
326
|
+
BancoBrasil.new do |banco_brasil|
|
327
|
+
banco_brasil.carteira = 18
|
328
|
+
banco_brasil.valor_documento = 14001.99
|
329
|
+
banco_brasil.numero_documento = 12345678911234567
|
330
|
+
banco_brasil.agencia = 5030
|
331
|
+
banco_brasil.digito_agencia = 6
|
332
|
+
banco_brasil.conta_corrente = 14204195
|
333
|
+
banco_brasil.digito_conta_corrente = 7
|
334
|
+
banco_brasil.data_vencimento = Date.parse('2012-12-28')
|
335
|
+
banco_brasil.codigo_cedente = 555444
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
its(:codigo_de_barras) { should eq '00194556100014001995554441234567891123456721' }
|
340
|
+
its(:linha_digitavel) { should eq "00195.55440 41234.567893 11234.567219 4 55610001400199" }
|
341
|
+
end
|
342
|
+
|
343
|
+
context "'codigo_cedente' with 7 digits" do
|
344
|
+
subject do
|
345
|
+
BancoBrasil.new do |banco_brasil|
|
346
|
+
banco_brasil.carteira = 18
|
347
|
+
banco_brasil.valor_documento = 2952.95
|
348
|
+
banco_brasil.numero_documento = 87654
|
349
|
+
banco_brasil.agencia = 9999
|
350
|
+
banco_brasil.digito_agencia = 6
|
351
|
+
banco_brasil.conta_corrente = 99999
|
352
|
+
banco_brasil.digito_conta_corrente = 7
|
353
|
+
banco_brasil.data_vencimento = Date.parse('2012-12-28')
|
354
|
+
banco_brasil.codigo_cedente = 7777777
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
its(:codigo_de_barras) { should eq '00197556100002952950000007777777000008765418' }
|
359
|
+
its(:linha_digitavel) { should eq '00190.00009 07777.777009 00087.654182 7 55610000295295' }
|
360
|
+
end
|
361
|
+
|
362
|
+
context "'codigo_cedente' with 8 digits" do
|
363
|
+
subject do
|
364
|
+
BancoBrasil.new do |banco_brasil|
|
365
|
+
banco_brasil.carteira = 18
|
366
|
+
banco_brasil.valor_documento = 2952.95
|
367
|
+
banco_brasil.numero_documento = 87654
|
368
|
+
banco_brasil.agencia = 9999
|
369
|
+
banco_brasil.digito_agencia = 6
|
370
|
+
banco_brasil.conta_corrente = 99999
|
371
|
+
banco_brasil.digito_conta_corrente = 7
|
372
|
+
banco_brasil.data_vencimento = Date.parse('2012-12-28')
|
373
|
+
banco_brasil.codigo_cedente = 77777778
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
its(:codigo_de_barras) { should eq '00191556100002952950000007777777800008765418' }
|
378
|
+
its(:linha_digitavel) { should eq '00190.00009 07777.777801 00087.654182 1 55610000295295' }
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|