boleto_bancario 0.0.2 → 1.0.0

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.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/Changelog.markdown +54 -2
  3. data/README.markdown +660 -189
  4. data/lib/boleto_bancario/calculos/documento.rb +191 -0
  5. data/lib/boleto_bancario/calculos/fator_vencimento.rb +78 -31
  6. data/lib/boleto_bancario/core/boleto.rb +30 -1
  7. data/lib/boleto_bancario/core/c6_bank.rb +155 -0
  8. data/lib/boleto_bancario/core/inter.rb +155 -0
  9. data/lib/boleto_bancario/core/nubank.rb +156 -0
  10. data/lib/boleto_bancario/locales/pt-BR.yml +55 -0
  11. data/lib/boleto_bancario/renderers/base.rb +154 -0
  12. data/lib/boleto_bancario/renderers/html_renderer.rb +92 -0
  13. data/lib/boleto_bancario/renderers/pdf_renderer.rb +130 -0
  14. data/lib/boleto_bancario/renderers/png_renderer.rb +66 -0
  15. data/lib/boleto_bancario/templates/_barcode.html.erb +3 -0
  16. data/lib/boleto_bancario/templates/_cedente.html.erb +14 -0
  17. data/lib/boleto_bancario/templates/_header.html.erb +4 -0
  18. data/lib/boleto_bancario/templates/_instructions.html.erb +10 -0
  19. data/lib/boleto_bancario/templates/_payment.html.erb +36 -0
  20. data/lib/boleto_bancario/templates/_sacado.html.erb +10 -0
  21. data/lib/boleto_bancario/templates/boleto.html.erb +22 -0
  22. data/lib/boleto_bancario/templates/boleto_styles.css +18 -0
  23. data/lib/boleto_bancario/version.rb +3 -1
  24. data/lib/boleto_bancario.rb +23 -6
  25. data/lib/generators/boleto_bancario/views_generator.rb +47 -0
  26. metadata +91 -129
  27. data/.gitignore +0 -19
  28. data/.rspec +0 -1
  29. data/.travis.yml +0 -10
  30. data/Gemfile +0 -3
  31. data/Planning.markdown +0 -63
  32. data/Rakefile +0 -15
  33. data/TODO.markdown +0 -19
  34. data/boleto_bancario.gemspec +0 -29
  35. data/documentacoes_dos_boletos/Bradesco/Manual_BRADESCO.PDF +0 -0
  36. data/lib/boleto_bancario/core/hsbc.rb +0 -170
  37. data/lib/boleto_bancario/core/real.rb +0 -177
  38. data/spec/boleto_bancario/calculos/digitos_spec.rb +0 -19
  39. data/spec/boleto_bancario/calculos/fator_vencimento_spec.rb +0 -59
  40. data/spec/boleto_bancario/calculos/fatores_de_multiplicacao_spec.rb +0 -69
  41. data/spec/boleto_bancario/calculos/linha_digitavel_spec.rb +0 -57
  42. data/spec/boleto_bancario/calculos/modulo10_spec.rb +0 -53
  43. data/spec/boleto_bancario/calculos/modulo11_fator_de2a7_spec.rb +0 -43
  44. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_resto_zero_spec.rb +0 -39
  45. data/spec/boleto_bancario/calculos/modulo11_fator_de2a9_spec.rb +0 -67
  46. data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_resto_x_spec.rb +0 -37
  47. data/spec/boleto_bancario/calculos/modulo11_fator_de9a2_spec.rb +0 -31
  48. data/spec/boleto_bancario/calculos/modulo11_spec.rb +0 -19
  49. data/spec/boleto_bancario/calculos/modulo_numero_de_controle_spec.rb +0 -37
  50. data/spec/boleto_bancario/core/banco_brasil_spec.rb +0 -377
  51. data/spec/boleto_bancario/core/banrisul_spec.rb +0 -129
  52. data/spec/boleto_bancario/core/boleto_spec.rb +0 -218
  53. data/spec/boleto_bancario/core/bradesco_spec.rb +0 -163
  54. data/spec/boleto_bancario/core/caixa_spec.rb +0 -111
  55. data/spec/boleto_bancario/core/hsbc_spec.rb +0 -72
  56. data/spec/boleto_bancario/core/itau_spec.rb +0 -333
  57. data/spec/boleto_bancario/core/real_spec.rb +0 -104
  58. data/spec/boleto_bancario/core/santander_spec.rb +0 -137
  59. data/spec/boleto_bancario/core/sicoob_spec.rb +0 -111
  60. data/spec/boleto_bancario/core/sicredi_spec.rb +0 -149
  61. data/spec/inheritance/banco_brasil_spec.rb +0 -22
  62. data/spec/inheritance/banrisul_spec.rb +0 -22
  63. data/spec/inheritance/boleto_spec.rb +0 -15
  64. data/spec/inheritance/bradesco_spec.rb +0 -22
  65. data/spec/inheritance/caixa_spec.rb +0 -22
  66. data/spec/inheritance/hsbc_spec.rb +0 -22
  67. data/spec/inheritance/itau_spec.rb +0 -22
  68. data/spec/inheritance/real_spec.rb +0 -22
  69. data/spec/inheritance/santander_spec.rb +0 -22
  70. data/spec/inheritance/sicoob_spec.rb +0 -22
  71. data/spec/inheritance/sicredi_spec.rb +0 -22
  72. data/spec/shared_examples/boleto_bancario_shared_example.rb +0 -151
  73. data/spec/spec_helper.rb +0 -14
@@ -1,218 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- module BoletoBancario
5
- module Core
6
- describe Boleto do
7
- describe '.model_name' do
8
- it 'returns Boleto' do
9
- expect(Boleto.model_name).to eq 'BoletoBancario::Core::Boleto'
10
- end
11
- end
12
-
13
- describe '.human_attribute_name' do
14
- it 'respond to internationalization attribute' do
15
- expect(Boleto).to respond_to(:human_attribute_name)
16
- end
17
- end
18
-
19
- describe '#to_partial_path' do
20
- subject(:boleto) { Boleto.new }
21
-
22
- it 'returns the path from class name' do
23
- expect(boleto.to_partial_path).to eq 'boleto_bancario/boleto'
24
- end
25
- end
26
-
27
- describe '#to_model' do
28
- subject(:boleto) { Boleto.new }
29
-
30
- it 'returns the same object for comparison purposes' do
31
- expect(boleto.to_model).to eq boleto
32
- end
33
- end
34
-
35
- describe '#initialize' do
36
- context 'when passing a Hash' do
37
- subject do
38
- described_class.new(
39
- :numero_documento => '191075',
40
- :valor_documento => 101.99,
41
- :data_vencimento => Date.new(2012, 10, 10),
42
- :carteira => '175',
43
- :agencia => '0098',
44
- :conta_corrente => '98701',
45
- :cedente => 'Nome da razao social',
46
- :sacado => 'Teste',
47
- :documento_sacado => '725.275.005-10',
48
- :endereco_sacado => 'Rua teste, 23045',
49
- :instrucoes1 => 'Lembrar de algo 1',
50
- :instrucoes2 => 'Lembrar de algo 2',
51
- :instrucoes3 => 'Lembrar de algo 3',
52
- :instrucoes4 => 'Lembrar de algo 4',
53
- :instrucoes5 => 'Lembrar de algo 5',
54
- :instrucoes6 => 'Lembrar de algo 6',
55
- )
56
- end
57
-
58
- it { expect(subject.numero_documento).to eq '191075' }
59
- it { expect(subject.valor_documento).to eq 101.99 }
60
- it { expect(subject.data_vencimento).to eq Date.new(2012, 10, 10) }
61
- it { expect(subject.carteira).to eq '175' }
62
- it { expect(subject.agencia).to eq '0098' }
63
- it { expect(subject.conta_corrente).to eq '98701' }
64
- it { expect(subject.codigo_moeda).to eq '9' }
65
- it { expect(subject.cedente).to eq 'Nome da razao social' }
66
- it { expect(subject.especie).to eq 'R$' }
67
- it { expect(subject.especie_documento).to eq 'DM' }
68
- it { expect(subject.data_documento).to eq Date.today }
69
- it { expect(subject.sacado).to eq 'Teste' }
70
- it { expect(subject.documento_sacado).to eq '725.275.005-10' }
71
- it { expect(subject.endereco_sacado).to eq 'Rua teste, 23045' }
72
- it { expect(subject.local_pagamento).to eq 'PAGÁVEL EM QUALQUER BANCO ATÉ O VENCIMENTO' }
73
- it { expect(subject.instrucoes1).to eq 'Lembrar de algo 1' }
74
- it { expect(subject.instrucoes2).to eq 'Lembrar de algo 2' }
75
- it { expect(subject.instrucoes3).to eq 'Lembrar de algo 3' }
76
- it { expect(subject.instrucoes4).to eq 'Lembrar de algo 4' }
77
- it { expect(subject.instrucoes5).to eq 'Lembrar de algo 5' }
78
- it { expect(subject.instrucoes6).to eq 'Lembrar de algo 6' }
79
- end
80
-
81
- context 'when passing a block' do
82
- subject do
83
- described_class.new do |boleto|
84
- boleto.numero_documento = '187390'
85
- boleto.valor_documento = 1
86
- boleto.data_vencimento = Date.new(2012, 10, 10)
87
- boleto.carteira = '109'
88
- boleto.agencia = '0914'
89
- boleto.conta_corrente = '82369'
90
- boleto.codigo_cedente = '90182'
91
- boleto.endereco_cedente = 'Rua Itapaiuna, 2434'
92
- boleto.cedente = 'Nome da razao social'
93
- boleto.documento_cedente = '62.526.713/0001-40'
94
- boleto.sacado = 'Teste'
95
- boleto.instrucoes1 = 'Lembrar de algo 1'
96
- boleto.instrucoes2 = 'Lembrar de algo 2'
97
- boleto.instrucoes3 = 'Lembrar de algo 3'
98
- boleto.instrucoes4 = 'Lembrar de algo 4'
99
- boleto.instrucoes5 = 'Lembrar de algo 5'
100
- boleto.instrucoes6 = 'Lembrar de algo 6'
101
- end
102
- end
103
-
104
- it { expect(subject.numero_documento).to eq '187390' }
105
- it { expect(subject.valor_documento).to eq 1 }
106
- it { expect(subject.carteira).to eq '109' }
107
- it { expect(subject.agencia).to eq '0914' }
108
- it { expect(subject.conta_corrente).to eq '82369' }
109
- it { expect(subject.codigo_moeda).to eq '9' }
110
- it { expect(subject.codigo_cedente).to eq '90182' }
111
- it { expect(subject.endereco_cedente).to eq 'Rua Itapaiuna, 2434' }
112
- it { expect(subject.cedente).to eq 'Nome da razao social' }
113
- it { expect(subject.documento_cedente).to eq '62.526.713/0001-40' }
114
- it { expect(subject.sacado).to eq 'Teste' }
115
- it { expect(subject.aceite).to be true }
116
- it { expect(subject.instrucoes1).to eq 'Lembrar de algo 1' }
117
- it { expect(subject.instrucoes2).to eq 'Lembrar de algo 2' }
118
- it { expect(subject.instrucoes3).to eq 'Lembrar de algo 3' }
119
- it { expect(subject.instrucoes4).to eq 'Lembrar de algo 4' }
120
- it { expect(subject.instrucoes5).to eq 'Lembrar de algo 5' }
121
- it { expect(subject.instrucoes6).to eq 'Lembrar de algo 6' }
122
- end
123
- end
124
-
125
- describe "#carteira_formatada" do
126
- it "returns 'carteira' as default" do
127
- subject.stub(:carteira).and_return('Foo')
128
-
129
- expect(subject.carteira_formatada).to eq 'Foo'
130
- end
131
- end
132
-
133
- describe "#valor_documento_formatado" do
134
- context "when period" do
135
- before { subject.stub(:valor_documento).and_return(123.45) }
136
-
137
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000012345' }
138
- end
139
-
140
- context "when less than ten" do
141
- before { subject.stub(:valor_documento).and_return(5.0) }
142
-
143
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000000500' }
144
- end
145
-
146
- context "when have many decimal points" do
147
- before { subject.stub(:valor_documento).and_return(10.999999) }
148
-
149
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000001099' }
150
- end
151
-
152
- context "when integer" do
153
- before { subject.stub(:valor_documento).and_return(1_999) }
154
-
155
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000199900' }
156
- end
157
-
158
- context "when period with string" do
159
- before { subject.stub(:valor_documento).and_return('236.91') }
160
-
161
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000023691' }
162
- end
163
-
164
- context "when period with string with many decimals" do
165
- before { subject.stub(:valor_documento).and_return('10.999999') }
166
-
167
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000001099' }
168
- end
169
-
170
- context "when the cents is not broken" do
171
- before { subject.stub(:valor_documento).and_return(229.5) }
172
-
173
- it { expect(subject.valor_formatado_para_codigo_de_barras).to eq '0000022950' }
174
- end
175
- end
176
-
177
- describe "#aceite_formatado" do
178
- context "when is true" do
179
- subject { described_class.new(aceite: true) }
180
-
181
- it { expect(subject.aceite_formatado).to eq 'S' }
182
- end
183
-
184
- context "when is false" do
185
- subject { described_class.new(aceite: false) }
186
-
187
- it { expect(subject.aceite_formatado).to eq 'N' }
188
- end
189
-
190
- context "when is nil" do
191
- subject { described_class.new(aceite: nil) }
192
-
193
- it { expect(subject.aceite_formatado).to eq 'N' }
194
- end
195
- end
196
-
197
- describe "#codigo_banco" do
198
- it { expect { subject.codigo_banco }.to raise_error(NotImplementedError) }
199
- end
200
-
201
- describe "#digito_codigo_banco" do
202
- it { expect { subject.digito_codigo_banco }.to raise_error(NotImplementedError) }
203
- end
204
-
205
- describe "#agencia_codigo_cedente" do
206
- it { expect { subject.agencia_codigo_cedente }.to raise_error(NotImplementedError) }
207
- end
208
-
209
- describe "#nosso_numero" do
210
- it { expect { subject.nosso_numero }.to raise_error(NotImplementedError) }
211
- end
212
-
213
- describe "#codigo_de_barras_do_banco" do
214
- it { expect { subject.codigo_de_barras_do_banco }.to raise_error(NotImplementedError) }
215
- end
216
- end
217
- end
218
- end
@@ -1,163 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- module BoletoBancario
5
- module Core
6
- describe Bradesco do
7
- it_should_behave_like 'boleto bancario'
8
-
9
- describe "on validations" do
10
- it { should have_valid(:agencia).when('1', '123', '1234') }
11
- it { should_not have_valid(:agencia).when('12345', '123456', '1234567', nil, '') }
12
-
13
- it { should have_valid(:conta_corrente).when('1', '123', '1234') }
14
- it { should_not have_valid(:conta_corrente).when('12345678', '123456789', nil, '') }
15
-
16
- it { should have_valid(:numero_documento).when(12345678911, '12345678911', '13') }
17
- it { should_not have_valid(:numero_documento).when('', nil, 123456789112, 1234567891113) }
18
-
19
- it { should have_valid(:carteira).when('03', '06', '09', '19', '21', '22', 3, 9, 19, 21, 22) }
20
- it { should_not have_valid(:carteira).when(nil, '', '05', '20', '100') }
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 { Bradesco.new(:agencia => 2) }
29
-
30
- it { expect(subject.agencia).to eq '0002' }
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 { Bradesco.new(:conta_corrente => 1) }
41
-
42
- it { expect(subject.conta_corrente).to eq '0000001' }
43
- end
44
-
45
- context "when is nil" do
46
- it { expect(subject.conta_corrente).to be nil }
47
- end
48
- end
49
-
50
- describe "#numero_documento" do
51
- context "when have a value" do
52
- subject { Bradesco.new(:numero_documento => 1234) }
53
-
54
- it { expect(subject.numero_documento).to eq '00000001234' }
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 { Bradesco.new(:carteira => 3) }
65
-
66
- it { expect(subject.carteira).to eq '03' }
67
- end
68
-
69
- context "when is nil" do
70
- it { expect(subject.carteira).to be nil }
71
- end
72
- end
73
-
74
- describe "#carteira_formatada" do
75
- context "when carteira is '21'" do
76
- subject { Bradesco.new(:carteira => 21) }
77
-
78
- it { expect(subject.carteira_formatada).to eq '21 – Cobrança Interna Com Registro' }
79
- end
80
-
81
- context "when carteira is '22'" do
82
- subject { Bradesco.new(:carteira => 22) }
83
-
84
- it { expect(subject.carteira_formatada).to eq '22 – Cobrança Interna sem registro' }
85
- end
86
-
87
- context "when carteira is '03'" do
88
- subject { Bradesco.new(:carteira => 3) }
89
-
90
- it { expect(subject.carteira_formatada).to eq '03' }
91
- end
92
- end
93
-
94
- describe "#codigo_banco" do
95
- it { expect(subject.codigo_banco).to eq '237' }
96
- end
97
-
98
- describe "#digito_codigo_banco" do
99
- it { expect(subject.digito_codigo_banco).to eq '2' }
100
- end
101
-
102
- describe "#agencia_codigo_cedente" do
103
- subject { Bradesco.new(agencia: '1172', conta_corrente: '0403005') }
104
-
105
- it { expect(subject.agencia_codigo_cedente).to eq '1172-10 / 0403005-2' }
106
- end
107
-
108
- describe "#nosso_numero" do
109
- context "documentation example" do
110
- subject { Bradesco.new(:carteira => '19', :numero_documento => '00000000002') }
111
-
112
- it { expect(subject.nosso_numero).to eq '19/00000000002-8' }
113
- end
114
-
115
- context "more examples from documentation" do
116
- subject { Bradesco.new(:carteira => '19', :numero_documento => '00000000001') }
117
-
118
- it { expect(subject.nosso_numero).to eq '19/00000000001-P' }
119
- end
120
-
121
- context "more examples" do
122
- subject { Bradesco.new(:carteira => '06', :numero_documento => '00075896452') }
123
-
124
- it { expect(subject.nosso_numero).to eq '06/00075896452-5' }
125
- end
126
- end
127
-
128
- describe "#codigo_de_barras" do
129
- context "more examples" do
130
- subject do
131
- Bradesco.new do |boleto|
132
- boleto.carteira = 6
133
- boleto.numero_documento = 75896452
134
- boleto.valor_documento = 2952.95
135
- boleto.data_vencimento = Date.parse('2012-12-28')
136
- boleto.agencia = 1172
137
- boleto.conta_corrente = 403005
138
- end
139
- end
140
-
141
- it { expect(subject.codigo_de_barras).to eq '23796556100002952951172060007589645204030050' }
142
- it { expect(subject.linha_digitavel).to eq '23791.17209 60007.589645 52040.300502 6 55610000295295' }
143
- end
144
-
145
- context "when carteira '09'" do
146
- subject do
147
- Bradesco.new do |boleto|
148
- boleto.carteira = 9
149
- boleto.numero_documento = 175896451
150
- boleto.valor_documento = 2959.78
151
- boleto.data_vencimento = Date.parse('2012-12-28')
152
- boleto.agencia = 1172
153
- boleto.conta_corrente = 403005
154
- end
155
- end
156
-
157
- it { expect(subject.codigo_de_barras).to eq '23791556100002959781172090017589645104030050' }
158
- it { expect(subject.linha_digitavel).to eq '23791.17209 90017.589640 51040.300504 1 55610000295978' }
159
- end
160
- end
161
- end
162
- end
163
- end
@@ -1,111 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- module BoletoBancario
5
- module Core
6
- describe Caixa do
7
- it_should_behave_like 'boleto bancario'
8
-
9
- describe "on validations" do
10
- it { should have_valid(:agencia).when(1, 1234, '1', '1234') }
11
- it { should_not have_valid(:agencia).when(12345, '12345', nil, '') }
12
-
13
- it { should have_valid(:codigo_cedente).when(1, 123456, '1', '123456') }
14
- it { should_not have_valid(:codigo_cedente).when(1234567, '1234567', nil, '') }
15
-
16
- it { should have_valid(:carteira).when(14, 24, '14', '24') }
17
- it { should_not have_valid(:carteira).when(nil, '', 5, 20, '20', '100') }
18
-
19
- it { should have_valid(:numero_documento).when(1, 123456789112345, '1', '123456789112345') }
20
- it { should_not have_valid(:numero_documento).when(nil, '', 1234567891123456, '1234567891123456') }
21
-
22
- it { should have_valid(:valor_documento).when(1, 1.99, 100.99, 9_999_999.99, '100.99') }
23
- it { should_not have_valid(:valor_documento).when(nil, '', '100,99', 10_000_000.00) }
24
- end
25
-
26
- describe "#agencia" do
27
- context "when have a value" do
28
- subject { Caixa.new(agencia: 2) }
29
-
30
- it { expect(subject.agencia).to eq '0002' }
31
- end
32
-
33
- context "when is nil" do
34
- it { expect(subject.agencia).to be nil }
35
- end
36
- end
37
-
38
- describe "#codigo_cedente" do
39
- context "when have a value" do
40
- subject { Caixa.new(codigo_cedente: '1') }
41
-
42
- it { expect(subject.codigo_cedente).to eq '000001' }
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 { Caixa.new(numero_documento: 1234) }
53
-
54
- it { expect(subject.numero_documento).to eq '000000000001234' }
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 { Caixa.new(carteira: '24') }
65
-
66
- it { expect(subject.carteira).to eq '24' }
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 '104' }
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_cedente" do
83
- subject { Caixa.new(agencia: '0235', codigo_cedente: '162546') }
84
-
85
- it { expect(subject.agencia_codigo_cedente).to eq '0235 / 162546-2' }
86
- end
87
-
88
- describe "#nosso_numero" do
89
- subject { Caixa.new(carteira: '24', numero_documento: '863245679215648') }
90
-
91
- it { expect(subject.nosso_numero).to eq '24863245679215648-2' }
92
- end
93
-
94
- describe "#codigo_de_barras" do
95
- subject do
96
- Caixa.new do |caixa|
97
- caixa.agencia = 1333
98
- caixa.codigo_cedente = '792157'
99
- caixa.carteira = '14'
100
- caixa.numero_documento = '946375189643625'
101
- caixa.valor_documento = 2952.95
102
- caixa.data_vencimento = Date.parse('2015-03-16')
103
- end
104
- end
105
-
106
- it { expect(subject.codigo_de_barras).to eq '10492636900002952957921578946137541896436250' }
107
- it { expect(subject.linha_digitavel).to eq '10497.92151 78946.137540 18964.362505 2 63690000295295' }
108
- end
109
- end
110
- end
111
- end
@@ -1,72 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- module BoletoBancario
5
- module Core
6
- describe Hsbc do
7
- it_should_behave_like 'boleto bancario'
8
-
9
- describe "on validations" do
10
- it { should have_valid(:codigo_cedente).when(1, 1234567, '1', '1234567') }
11
- it { should_not have_valid(:codigo_cedente).when(12345678, '12345678', nil, '') }
12
-
13
- it { should have_valid(:numero_documento).when(1, 1234567891123, '1', '1234567891123') }
14
- it { should_not have_valid(:numero_documento).when(nil, '', 12345678911234, '12345678911234') }
15
-
16
- it { should have_valid(:valor_documento).when(1, 1.99, 100.99, 99_999_999.99, '100.99') }
17
- it { should_not have_valid(:valor_documento).when(nil, '', '100,99', 100_000_000.00) }
18
-
19
- it { should have_valid(:carteira).when('CNR') }
20
- it { should_not have_valid(:carteira).when(nil, '', '5', 'CSB') }
21
- end
22
-
23
- describe "#codigo_cedente" do
24
- context "when have a value" do
25
- subject { Hsbc.new(codigo_cedente: '1') }
26
-
27
- it { expect(subject.codigo_cedente).to eq '0000001' }
28
- end
29
-
30
- context "when is nil" do
31
- it { expect(subject.codigo_cedente).to be nil }
32
- end
33
- end
34
-
35
- describe "#numero_documento" do
36
- context "when have a value" do
37
- subject { Hsbc.new(numero_documento: 1234) }
38
-
39
- it { expect(subject.numero_documento).to eq '0000000001234' }
40
- end
41
-
42
- context "when is nil" do
43
- it { expect(subject.numero_documento).to be nil }
44
- end
45
- end
46
-
47
- it { expect(subject.codigo_banco).to eq '399' }
48
-
49
- it { expect(subject.digito_codigo_banco).to eq '9' }
50
-
51
- describe "#nosso_numero" do
52
- subject { Hsbc.new(codigo_cedente: '7984135', numero_documento: '4716881775613', data_vencimento: Date.parse('2009-05-22')) }
53
-
54
- it { expect(subject.nosso_numero).to eq '4716881775613440' }
55
- end
56
-
57
- describe "#codigo_de_barras" do
58
- subject do
59
- Hsbc.new do |hsbc|
60
- hsbc.codigo_cedente = 3485910
61
- hsbc.numero_documento = '43862'
62
- hsbc.valor_documento = 3740.58
63
- hsbc.data_vencimento = Date.parse('2024-02-18')
64
- end
65
- end
66
-
67
- it { expect(subject.codigo_de_barras).to eq '39991963000003740583485910000000004386204942' }
68
- it { expect(subject.linha_digitavel).to eq '39993.48596 10000.000009 43862.049426 1 96300000374058' }
69
- end
70
- end
71
- end
72
- end