br_boleto 0.1.0 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile.lock +3 -3
- data/README.markdown +196 -11
- data/Rakefile +5 -0
- data/br_boleto.gemspec +1 -1
- data/lib/br_boleto.rb +30 -12
- data/lib/br_boleto/{core/boleto.rb → boleto/base.rb} +83 -5
- data/lib/br_boleto/boleto/sicoob.rb +211 -0
- data/lib/br_boleto/calculos/modulo11_fator3197.rb +5 -5
- data/lib/br_boleto/helper/cpf_cnpj.rb +60 -0
- data/lib/br_boleto/helper/number.rb +15 -0
- data/lib/br_boleto/remessa/base.rb +89 -0
- data/lib/br_boleto/remessa/cnab240/base.rb +328 -0
- data/lib/br_boleto/remessa/cnab240/helper/header_arquivo.rb +186 -0
- data/lib/br_boleto/remessa/cnab240/helper/header_lote.rb +180 -0
- data/lib/br_boleto/remessa/cnab240/helper/segmento_p.rb +349 -0
- data/lib/br_boleto/remessa/cnab240/helper/segmento_q.rb +206 -0
- data/lib/br_boleto/remessa/cnab240/helper/segmento_r.rb +261 -0
- data/lib/br_boleto/remessa/cnab240/helper/segmento_s.rb +193 -0
- data/lib/br_boleto/remessa/cnab240/helper/trailer_arquivo.rb +88 -0
- data/lib/br_boleto/remessa/cnab240/helper/trailer_lote.rb +75 -0
- data/lib/br_boleto/remessa/cnab240/sicoob.rb +246 -0
- data/lib/br_boleto/remessa/lote.rb +52 -0
- data/lib/br_boleto/remessa/pagamento.rb +238 -0
- data/lib/br_boleto/string_methods.rb +21 -0
- data/lib/br_boleto/version.rb +2 -2
- data/test/br_boleto/{core/boleto_test.rb → boleto/base_test.rb} +107 -11
- data/test/br_boleto/{core → boleto}/sicoob_test.rb +60 -2
- data/test/br_boleto/remessa/base_test.rb +80 -0
- data/test/br_boleto/remessa/cnab240/base_test.rb +405 -0
- data/test/br_boleto/remessa/cnab240/helper/header_arquivo_test.rb +208 -0
- data/test/br_boleto/remessa/cnab240/helper/header_lote_test.rb +200 -0
- data/test/br_boleto/remessa/cnab240/helper/segmento_p_test.rb +390 -0
- data/test/br_boleto/remessa/cnab240/helper/segmento_q_test.rb +223 -0
- data/test/br_boleto/remessa/cnab240/helper/segmento_r_test.rb +260 -0
- data/test/br_boleto/remessa/cnab240/helper/segmento_s_test.rb +217 -0
- data/test/br_boleto/remessa/cnab240/helper/trailer_arquivo_test.rb +82 -0
- data/test/br_boleto/remessa/cnab240/helper/trailer_lote_test.rb +67 -0
- data/test/br_boleto/remessa/cnab240/sicoob_test.rb +347 -0
- data/test/br_boleto/remessa/lote_test.rb +49 -0
- data/test/br_boleto/remessa/pagamento_test.rb +339 -0
- data/test/factories/{boleto.rb → boleto/base.rb} +1 -1
- data/test/factories/{boleto_sicoob.rb → boleto/boleto_sicoob.rb} +1 -1
- data/test/factories/remessa/base.rb +13 -0
- data/test/factories/remessa/cnab240/base.rb +18 -0
- data/test/factories/remessa/cnab240/sicoob.rb +18 -0
- data/test/factories/remessa/lote.rb +7 -0
- data/test/factories/remessa/pagamento.rb +16 -0
- data/test/inheritance/boleto_test.rb +1 -1
- data/test/inheritance/sicoob_test.rb +1 -1
- metadata +65 -13
- data/lib/br_boleto/core/sicoob.rb +0 -169
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
|
-
describe BrBoleto::
|
5
|
-
subject {
|
4
|
+
describe BrBoleto::Boleto::Sicoob do
|
5
|
+
subject { FactoryGirl.build(:boleto_sicoob) }
|
6
6
|
context "on validations" do
|
7
7
|
it { must validate_length_of(:agencia).is_at_most(4) }
|
8
8
|
|
@@ -13,6 +13,10 @@ describe BrBoleto::Core::Sicoob do
|
|
13
13
|
it { must validate_inclusion_of(:carteira).in_array(%w(1 3)) }
|
14
14
|
it { wont allow_value(9).for(:carteira) }
|
15
15
|
it { wont allow_value(6).for(:carteira) }
|
16
|
+
|
17
|
+
it { must validate_inclusion_of(:modalidade_cobranca).in_array(%w(1 2 3)) }
|
18
|
+
it { wont allow_value(4).for(:modalidade_cobranca) }
|
19
|
+
it { wont allow_value(5).for(:modalidade_cobranca) }
|
16
20
|
|
17
21
|
it { must validate_numericality_of(:valor_documento).is_less_than_or_equal_to(99999999.99) }
|
18
22
|
|
@@ -113,7 +117,26 @@ describe BrBoleto::Core::Sicoob do
|
|
113
117
|
subject.stubs(:nosso_numero).returns('1234567-8')
|
114
118
|
subject.codigo_de_barras_do_banco.must_equal "1007801000006612345678001"
|
115
119
|
end
|
120
|
+
end
|
116
121
|
|
122
|
+
describe "#modalidade_cobranca" do
|
123
|
+
it "tem um valor padrão que é 01" do
|
124
|
+
subject.class.new().modalidade_cobranca.must_equal "01"
|
125
|
+
end
|
126
|
+
it "posso modificar a modalidade de cobranca" do
|
127
|
+
subject.modalidade_cobranca = 2
|
128
|
+
subject.modalidade_cobranca.must_equal "02"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#parcelas" do
|
133
|
+
it "tem um valor padrão que é 001" do
|
134
|
+
subject.class.new().parcelas.must_equal "001"
|
135
|
+
end
|
136
|
+
it "deve permitir a modificação do número de parcelas" do
|
137
|
+
subject.parcelas = 2
|
138
|
+
subject.parcelas.must_equal "002"
|
139
|
+
end
|
117
140
|
end
|
118
141
|
|
119
142
|
describe "#codigo_de_barras" do
|
@@ -135,4 +158,39 @@ describe BrBoleto::Core::Sicoob do
|
|
135
158
|
describe "#carteiras_suportadas" do
|
136
159
|
it { subject.class.carteiras_suportadas.must_equal ["1","3"] }
|
137
160
|
end
|
161
|
+
|
162
|
+
describe "#tipo_cobranca" do
|
163
|
+
it "deve ser :com_registro se modalidade_cobranca for 01" do
|
164
|
+
subject.modalidade_cobranca = '01'
|
165
|
+
subject.tipo_cobranca.must_equal :com_registro
|
166
|
+
end
|
167
|
+
it "deve ser :com_registro se modalidade_cobranca for 1" do
|
168
|
+
subject.modalidade_cobranca = 1
|
169
|
+
subject.tipo_cobranca.must_equal :com_registro
|
170
|
+
end
|
171
|
+
it "deve ser :sem_registro se modalidade_cobranca for 02" do
|
172
|
+
subject.modalidade_cobranca = '02'
|
173
|
+
subject.tipo_cobranca.must_equal :sem_registro
|
174
|
+
end
|
175
|
+
it "deve ser :sem_registro se modalidade_cobranca for 2" do
|
176
|
+
subject.modalidade_cobranca = 2
|
177
|
+
subject.tipo_cobranca.must_equal :sem_registro
|
178
|
+
end
|
179
|
+
it "deve ser :garantia_caucionada se modalidade_cobranca for 03" do
|
180
|
+
subject.modalidade_cobranca = '03'
|
181
|
+
subject.tipo_cobranca.must_equal :garantia_caucionada
|
182
|
+
end
|
183
|
+
it "deve ser :garantia_caucionada se modalidade_cobranca for 3" do
|
184
|
+
subject.modalidade_cobranca = 3
|
185
|
+
subject.tipo_cobranca.must_equal :garantia_caucionada
|
186
|
+
end
|
187
|
+
it "deve ser nil se modalidade_cobranca for outro numero" do
|
188
|
+
subject.modalidade_cobranca = 4
|
189
|
+
subject.tipo_cobranca.must_be_nil
|
190
|
+
end
|
191
|
+
it "deve ser com_registro se modalidade_cobranca for nil, pois o defaul de modalidade_cobranca é 01" do
|
192
|
+
subject.modalidade_cobranca = nil
|
193
|
+
subject.tipo_cobranca.must_equal :com_registro
|
194
|
+
end
|
195
|
+
end
|
138
196
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BrBoleto::Remessa::Base do
|
4
|
+
subject { FactoryGirl.build(:remessa_base) }
|
5
|
+
let(:lote) { FactoryGirl.build(:remessa_lote) }
|
6
|
+
describe "validations" do
|
7
|
+
it { must validate_presence_of(:nome_empresa) }
|
8
|
+
|
9
|
+
it { must validate_inclusion_of(:aceite).in_array(%w(a A n N)).with_message("valor deve ser A(aceito) ou N(não ceito)") }
|
10
|
+
it { wont allow_value('x').for(:aceite) }
|
11
|
+
it { wont allow_value('q').for(:aceite) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#lotes" do
|
15
|
+
it "deve haver ao menos 1 lote" do
|
16
|
+
wont allow_value([]).for(:lotes).with_message("não pode estar vazio.")
|
17
|
+
end
|
18
|
+
it "deve ser um objeto lote" do
|
19
|
+
wont allow_value(FactoryGirl.build(:boleto_sicoob)).for(:lotes).with_message("cada item deve ser um objeto Lote.")
|
20
|
+
end
|
21
|
+
it "deve ser válido com um lote válido" do
|
22
|
+
must allow_value([lote]).for(:lotes)
|
23
|
+
end
|
24
|
+
it "não deve ser válido se houver algum lote inválido" do
|
25
|
+
wont allow_value([FactoryGirl.build(:remessa_lote, pagamentos: [])]).for(:lotes)
|
26
|
+
end
|
27
|
+
it "deve ser válido se passar apenas um lote sem Array" do
|
28
|
+
must allow_value(lote).for(:lotes)
|
29
|
+
end
|
30
|
+
it "se setar apenas 1 lote sem array deve retornar um array de 1 posicao" do
|
31
|
+
subject.lotes = lote
|
32
|
+
subject.lotes.size.must_equal 1
|
33
|
+
subject.lotes.is_a?(Array).must_equal true
|
34
|
+
subject.lotes[0].must_equal lote
|
35
|
+
end
|
36
|
+
it "posso setar mais que 1 lote" do
|
37
|
+
lote2 = FactoryGirl.build(:remessa_lote)
|
38
|
+
subject.lotes = [lote, lote2]
|
39
|
+
subject.lotes.size.must_equal 2
|
40
|
+
subject.lotes.is_a?(Array).must_equal true
|
41
|
+
subject.lotes[0].must_equal lote
|
42
|
+
subject.lotes[1].must_equal lote2
|
43
|
+
end
|
44
|
+
|
45
|
+
it "posso incrementar os lotes com <<" do
|
46
|
+
lote2 = FactoryGirl.build(:remessa_lote)
|
47
|
+
subject.lotes = lote
|
48
|
+
subject.lotes.size.must_equal 1
|
49
|
+
subject.lotes << lote2
|
50
|
+
subject.lotes.size.must_equal 2
|
51
|
+
subject.lotes.is_a?(Array).must_equal true
|
52
|
+
subject.lotes[0].must_equal lote
|
53
|
+
subject.lotes[1].must_equal lote2
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#default_values" do
|
58
|
+
it "for aceite" do
|
59
|
+
object = subject.class.new()
|
60
|
+
object.aceite.must_equal 'N'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "wont be persisted?" do
|
65
|
+
subject.persisted?.must_equal false
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#nome_empresa_formatada" do
|
69
|
+
it "deve adicionar valor em branco no final se for menor que 30 caracteres" do
|
70
|
+
subject.nome_empresa = '1234567890'
|
71
|
+
subject.nome_empresa_formatada.size.must_equal 30
|
72
|
+
subject.nome_empresa_formatada.must_equal('1234567890'.ljust(30, ' '))
|
73
|
+
end
|
74
|
+
it "deve retornar no maximo 30 caracteres se for maior que 30" do
|
75
|
+
subject.nome_empresa = '0123456'.ljust(35, 'A')
|
76
|
+
subject.nome_empresa_formatada.size.must_equal 30
|
77
|
+
subject.nome_empresa_formatada.must_equal('0123456'.ljust(30, 'A'))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,405 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'br_boleto/remessa/cnab240/helper/header_arquivo_test'
|
3
|
+
require 'br_boleto/remessa/cnab240/helper/header_lote_test'
|
4
|
+
require 'br_boleto/remessa/cnab240/helper/segmento_p_test'
|
5
|
+
require 'br_boleto/remessa/cnab240/helper/segmento_q_test'
|
6
|
+
require 'br_boleto/remessa/cnab240/helper/segmento_r_test'
|
7
|
+
require 'br_boleto/remessa/cnab240/helper/segmento_s_test'
|
8
|
+
require 'br_boleto/remessa/cnab240/helper/trailer_arquivo_test'
|
9
|
+
require 'br_boleto/remessa/cnab240/helper/trailer_lote_test'
|
10
|
+
|
11
|
+
describe BrBoleto::Remessa::Cnab240::Base do
|
12
|
+
subject { FactoryGirl.build(:remessa_cnab240_base, lotes: lote) }
|
13
|
+
let(:pagamento) { FactoryGirl.build(:remessa_pagamento) }
|
14
|
+
let(:lote) { FactoryGirl.build(:remessa_lote, pagamentos: pagamento) }
|
15
|
+
|
16
|
+
context "validations" do
|
17
|
+
it { must validate_presence_of(:documento_cedente) }
|
18
|
+
it { must validate_presence_of(:convenio) }
|
19
|
+
|
20
|
+
it { must validate_length_of(:codigo_carteira ).is_equal_to(1).with_message("deve ter 1 dígito.") }
|
21
|
+
it { must validate_length_of(:forma_cadastramento).is_equal_to(1).with_message("deve ter 1 dígito.") }
|
22
|
+
it { must validate_length_of(:emissao_boleto ).is_equal_to(1).with_message("deve ter 1 dígito.") }
|
23
|
+
it { must validate_length_of(:distribuicao_boleto).is_equal_to(1).with_message("deve ter 1 dígito.") }
|
24
|
+
it { must validate_length_of(:especie_titulo ).is_equal_to(2).with_message("deve ter 2 dígitos.") }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#default_values" do
|
28
|
+
it "for codigo_carteira" do
|
29
|
+
object = subject.class.new()
|
30
|
+
object.codigo_carteira.must_equal '1'
|
31
|
+
end
|
32
|
+
it "for forma_cadastramento" do
|
33
|
+
object = subject.class.new()
|
34
|
+
object.forma_cadastramento.must_equal '1'
|
35
|
+
end
|
36
|
+
it "deve continuar com o default da superclass" do
|
37
|
+
object = subject.class.new()
|
38
|
+
object.aceite.must_equal 'N'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#tipo_inscricao" do
|
43
|
+
it "se for cpf deve retornar 1" do
|
44
|
+
subject.documento_cedente = '12345678901'
|
45
|
+
subject.tipo_inscricao.must_equal '1'
|
46
|
+
end
|
47
|
+
it "se for cnpj deve retornar 2" do
|
48
|
+
subject.documento_cedente = '12345678901234'
|
49
|
+
subject.tipo_inscricao.must_equal '2'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#data_hora_arquivo" do
|
54
|
+
it "se for nil deve pegar o time now" do
|
55
|
+
subject.data_hora_arquivo = nil
|
56
|
+
now = Time.now
|
57
|
+
Time.stubs(:now).returns(now)
|
58
|
+
subject.data_hora_arquivo.must_equal now
|
59
|
+
end
|
60
|
+
it "se passar um date_time deve converter para time" do
|
61
|
+
now = DateTime.now
|
62
|
+
subject.data_hora_arquivo = now
|
63
|
+
subject.data_hora_arquivo.must_equal now.to_time
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#data_geracao" do
|
68
|
+
it "deve pegar a data com 8 posições do atributo data_hora_arquivo" do
|
69
|
+
subject.data_hora_arquivo = Time.parse("30/12/2015 01:02:03")
|
70
|
+
subject.data_geracao.must_equal "30122015"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#hora_geracao" do
|
75
|
+
it "deve pegar a hora minuto e segundo da data_hora_arquivo" do
|
76
|
+
subject.data_hora_arquivo = Time.parse("30/12/2015 01:02:03")
|
77
|
+
subject.hora_geracao.must_equal "010203"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#segmento_p_numero_do_documento" do
|
82
|
+
it "deve pegar o nosso_numero do pagamento do parametro e ajustar para 15 caracateres" do
|
83
|
+
pagamento.nosso_numero = '123456'
|
84
|
+
subject.segmento_p_numero_do_documento(pagamento).must_equal '123456'.rjust(15, '0')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "metodos que devem ser sobrescritos para cada banco" do
|
89
|
+
it "#complemento_header" do
|
90
|
+
assert_raises NotImplementedError do
|
91
|
+
subject.complemento_header
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "#versao_layout_arquivo" do
|
96
|
+
assert_raises NotImplementedError do
|
97
|
+
subject.versao_layout_arquivo
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "#versao_layout_lote" do
|
102
|
+
assert_raises NotImplementedError do
|
103
|
+
subject.versao_layout_lote
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "#convenio_lote" do
|
108
|
+
assert_raises NotImplementedError do
|
109
|
+
subject.convenio_lote(lote)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "#nome_banco" do
|
114
|
+
assert_raises NotImplementedError do
|
115
|
+
subject.nome_banco
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "#codigo_banco" do
|
120
|
+
assert_raises NotImplementedError do
|
121
|
+
subject.codigo_banco
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "#informacoes_da_conta" do
|
126
|
+
assert_raises NotImplementedError do
|
127
|
+
subject.informacoes_da_conta
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it "#codigo_convenio" do
|
132
|
+
assert_raises NotImplementedError do
|
133
|
+
subject.codigo_convenio
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it "#digito_agencia" do
|
138
|
+
assert_raises NotImplementedError do
|
139
|
+
subject.digito_agencia
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "#complemento_trailer_lote" do
|
145
|
+
it "deve ter 217 caracteres em branco por padrão" do
|
146
|
+
subject.complemento_trailer_lote(nil, nil).must_equal ''.rjust(217, ' ')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
context "TESTE DAS PARTES DO ARQUIVO" do
|
150
|
+
# Em cada banco pode incluir esses modules para testar sobrescrevendo os testes específicos
|
151
|
+
|
152
|
+
include Helper::HeaderArquivoTest
|
153
|
+
include Helper::HeaderLoteTest
|
154
|
+
include Helper::SegmentoPTest
|
155
|
+
include Helper::SegmentoQTest
|
156
|
+
include Helper::SegmentoRTest
|
157
|
+
include Helper::SegmentoSTest
|
158
|
+
include Helper::TrailerArquivoTest
|
159
|
+
include Helper::TrailerLoteTest
|
160
|
+
end
|
161
|
+
context "MONTAGEM DO ARQUIVO " do
|
162
|
+
|
163
|
+
|
164
|
+
before do
|
165
|
+
# Stub nos metodos que devem ser sobrescritos nos bancos
|
166
|
+
subject.stubs(:complemento_header).returns( ''.rjust(29, ' '))
|
167
|
+
subject.stubs(:versao_layout_arquivo).returns( '081')
|
168
|
+
subject.stubs(:versao_layout_lote).returns( '040')
|
169
|
+
subject.stubs(:convenio_lote).returns( ''.rjust(20, ' '))
|
170
|
+
subject.stubs(:nome_banco).returns( 'NOMEBANCO'.ljust(30, ' '))
|
171
|
+
subject.stubs(:codigo_banco).returns( '123')
|
172
|
+
subject.stubs(:informacoes_da_conta).returns( ''.rjust(20, ' '))
|
173
|
+
subject.stubs(:codigo_convenio).returns( ''.rjust(20, ' '))
|
174
|
+
subject.stubs(:digito_agencia).returns( '1')
|
175
|
+
subject.stubs(:complemento_p).returns( ''.rjust(34, ' '))
|
176
|
+
end
|
177
|
+
describe "#dados_do_arquivo#" do
|
178
|
+
let(:lote_2) { FactoryGirl.build(:remessa_lote) }
|
179
|
+
before do
|
180
|
+
subject.lotes = [lote, lote_2]
|
181
|
+
end
|
182
|
+
it "se não for valido deve retornar nil" do
|
183
|
+
subject.stubs(:valid?).returns(false)
|
184
|
+
subject.dados_do_arquivo.must_be_nil
|
185
|
+
end
|
186
|
+
it "o valor do metodo monta_header_arquivo deve estar nas primeiras posições" do
|
187
|
+
subject.expects(:monta_header_arquivo).returns("TESTE_HEADER_ARQUIVO")
|
188
|
+
subject.dados_do_arquivo[0..19].must_equal "TESTE_HEADER_ARQUIVO"
|
189
|
+
end
|
190
|
+
context "deve montar o lote para cada um dos lotes e devem vir depois da montagem do header_arquivo" do
|
191
|
+
it "com 2 lotes" do
|
192
|
+
subject.stubs(:monta_header_arquivo).returns("1234567890")
|
193
|
+
subject.expects(:monta_lote).with(lote, 1).returns(["LOTE_lote_1"])
|
194
|
+
subject.expects(:monta_lote).with(lote_2, 2).returns(["LOTE_lote_2"])
|
195
|
+
resultado = subject.dados_do_arquivo
|
196
|
+
resultado[10..21].must_equal "\nLOTE_LOTE_1"
|
197
|
+
resultado[22..33].must_equal "\nLOTE_LOTE_2"
|
198
|
+
end
|
199
|
+
|
200
|
+
it "com 1 lote" do
|
201
|
+
subject.lotes = lote
|
202
|
+
subject.stubs(:monta_header_arquivo).returns("1234567890")
|
203
|
+
subject.expects(:monta_lote).with(lote, 1).returns(["LOTE_lote_1"])
|
204
|
+
resultado = subject.dados_do_arquivo
|
205
|
+
resultado[10..21].must_equal "\nLOTE_LOTE_1"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
it "deve chamar o metodo monta_trailer_arquivo passando o total de lotes e o contador de registros do lote" do
|
210
|
+
subject.stubs(:monta_header_arquivo).returns("1234567890")
|
211
|
+
subject.stubs(:monta_lote).with(lote, 1).returns(["LOTE_LOTE01234_1", "PARTE 2"])
|
212
|
+
subject.stubs(:monta_lote).with(lote_2, 2).returns(["LOTE_LOTE01234_2", "PARTE 2"])
|
213
|
+
subject.expects(:monta_trailer_arquivo).with(2, 6).returns("TRAILER_DO_LOTE")
|
214
|
+
resultado = subject.dados_do_arquivo
|
215
|
+
resultado[10..26].must_equal "\nLOTE_LOTE01234_1"
|
216
|
+
resultado[27..34].must_equal "\nPARTE 2"
|
217
|
+
resultado[35..51].must_equal "\nLOTE_LOTE01234_2"
|
218
|
+
resultado[52..59].must_equal "\nPARTE 2"
|
219
|
+
resultado[60..75].must_equal "\nTRAILER_DO_LOTE"
|
220
|
+
resultado.size.must_equal 76
|
221
|
+
end
|
222
|
+
end
|
223
|
+
describe "#monta_lote" do
|
224
|
+
it "se o lote for inválido deve retornar nil" do
|
225
|
+
lote.stubs(:valid?).returns(false)
|
226
|
+
subject.monta_lote(lote, 1).must_be_nil
|
227
|
+
end
|
228
|
+
it "deve retornar um vetor com 6 posições" do
|
229
|
+
resultado = subject.monta_lote(lote, 123)
|
230
|
+
resultado.is_a?(Array).must_equal true
|
231
|
+
resultado.size.must_equal 6
|
232
|
+
end
|
233
|
+
context "1 - Primeira posição do vetor" do
|
234
|
+
it "deve ter o conteudo do metodo monta_header_lote" do
|
235
|
+
subject.expects(:monta_header_lote).with(lote, 123).returns("RESULTADO_HEADER_LOTE")
|
236
|
+
resultado = subject.monta_lote(lote, 123)
|
237
|
+
resultado[0].must_equal "RESULTADO_HEADER_LOTE"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
context "2 - Segunda posição do vetor" do
|
241
|
+
it "deve ter o conteudo do metodo monta_segmento_p passando o pagamento, nro_lote e o contador" do
|
242
|
+
lote.pagamentos = pagamento
|
243
|
+
subject.stubs(:monta_header_lote).with(lote, 123).returns("RESULTADO_HEADER_LOTE")
|
244
|
+
subject.expects(:monta_segmento_p).with(pagamento, 123, 1).returns("RESULTADO_SEGMENTO_P")
|
245
|
+
resultado = subject.monta_lote(lote, 123)
|
246
|
+
resultado[1].must_equal "RESULTADO_SEGMENTO_P"
|
247
|
+
end
|
248
|
+
it "Se o lote tiver 2 pagamentos deve setar o segmento_p na posição 1 e 5" do
|
249
|
+
pagamento_2 = FactoryGirl.build(:remessa_pagamento)
|
250
|
+
lote.pagamentos = [pagamento, pagamento_2]
|
251
|
+
subject.stubs(:monta_header_lote).with(lote, 123).returns("RESULTADO_HEADER_LOTE")
|
252
|
+
subject.expects(:monta_segmento_p).with(pagamento, 123, 1).returns("RESULTADO_SEGMENTO_P_2")
|
253
|
+
subject.expects(:monta_segmento_p).with(pagamento_2, 123, 5).returns("RESULTADO_SEGMENTO_P_6")
|
254
|
+
resultado = subject.monta_lote(lote, 123)
|
255
|
+
resultado[1].must_equal "RESULTADO_SEGMENTO_P_2"
|
256
|
+
resultado[5].must_equal "RESULTADO_SEGMENTO_P_6"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
context "3 - Terceira posição do vetor" do
|
260
|
+
it "deve ter o conteudo do metodo monta_segmento_q passando o pagamento, nro_lote e o contador" do
|
261
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
262
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
263
|
+
subject.expects(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
264
|
+
resultado = subject.monta_lote(lote, 55)
|
265
|
+
resultado[2].must_equal "RESULTADO_SEGMENTO_Q"
|
266
|
+
end
|
267
|
+
it "Se o lote tiver 2 pagamentos deve setar o segmento_q na posição 3 e 7" do
|
268
|
+
pagamento_2 = FactoryGirl.build(:remessa_pagamento)
|
269
|
+
lote.pagamentos = [pagamento, pagamento_2]
|
270
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
271
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
272
|
+
subject.stubs(:monta_segmento_p).with(pagamento_2, 55, 5).returns("RESULTADO_SEGMENTO_P")
|
273
|
+
subject.expects(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q_3")
|
274
|
+
subject.expects(:monta_segmento_q).with(pagamento_2, 55, 6).returns("RESULTADO_SEGMENTO_Q_7")
|
275
|
+
resultado = subject.monta_lote(lote, 55)
|
276
|
+
resultado[2].must_equal "RESULTADO_SEGMENTO_Q_3"
|
277
|
+
resultado[6].must_equal "RESULTADO_SEGMENTO_Q_7"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "4 - Quarta posição do vetor" do
|
282
|
+
it "deve ter o conteudo do metodo monta_segmento_r passando o pagamento, nro_lote e o contador" do
|
283
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
284
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
285
|
+
subject.stubs(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
286
|
+
subject.expects(:monta_segmento_r).with(pagamento, 55, 3).returns("RESULTADO_SEGMENTO_R")
|
287
|
+
resultado = subject.monta_lote(lote, 55)
|
288
|
+
resultado[3].must_equal "RESULTADO_SEGMENTO_R"
|
289
|
+
end
|
290
|
+
it "Se o lote tiver 2 pagamentos deve setar o segmento_r na posição 4 e 8" do
|
291
|
+
pagamento_2 = FactoryGirl.build(:remessa_pagamento)
|
292
|
+
lote.pagamentos = [pagamento, pagamento_2]
|
293
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
294
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
295
|
+
subject.stubs(:monta_segmento_p).with(pagamento_2, 55, 5).returns("RESULTADO_SEGMENTO_P")
|
296
|
+
subject.stubs(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
297
|
+
subject.stubs(:monta_segmento_q).with(pagamento_2, 55, 6).returns("RESULTADO_SEGMENTO_Q")
|
298
|
+
subject.expects(:monta_segmento_r).with(pagamento, 55, 3).returns("RESULTADO_SEGMENTO_R_4")
|
299
|
+
subject.expects(:monta_segmento_r).with(pagamento_2, 55, 7).returns("RESULTADO_SEGMENTO_R_8")
|
300
|
+
resultado = subject.monta_lote(lote, 55)
|
301
|
+
resultado[3].must_equal "RESULTADO_SEGMENTO_R_4"
|
302
|
+
resultado[7].must_equal "RESULTADO_SEGMENTO_R_8"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "5 - Quinta posição do vetor" do
|
307
|
+
it "deve ter o conteudo do metodo monta_segmento_s passando o pagamento, nro_lote e o contador" do
|
308
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
309
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
310
|
+
subject.stubs(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
311
|
+
subject.stubs(:monta_segmento_r).with(pagamento, 55, 3).returns("RESULTADO_SEGMENTO_R")
|
312
|
+
subject.expects(:monta_segmento_s).with(pagamento, 55, 4).returns("RESULTADO_SEGMENTO_S")
|
313
|
+
resultado = subject.monta_lote(lote, 55)
|
314
|
+
resultado[4].must_equal "RESULTADO_SEGMENTO_S"
|
315
|
+
end
|
316
|
+
it "Se o lote tiver 2 pagamentos deve setar o monta_segmento_s na posição 5 e 9" do
|
317
|
+
pagamento_2 = FactoryGirl.build(:remessa_pagamento)
|
318
|
+
lote.pagamentos = [pagamento, pagamento_2]
|
319
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
320
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
321
|
+
subject.stubs(:monta_segmento_p).with(pagamento_2, 55, 5).returns("RESULTADO_SEGMENTO_P")
|
322
|
+
subject.stubs(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
323
|
+
subject.stubs(:monta_segmento_q).with(pagamento_2, 55, 6).returns("RESULTADO_SEGMENTO_Q")
|
324
|
+
subject.stubs(:monta_segmento_r).with(pagamento, 55, 3).returns("RESULTADO_SEGMENTO_R")
|
325
|
+
subject.stubs(:monta_segmento_r).with(pagamento_2, 55, 7).returns("RESULTADO_SEGMENTO_R")
|
326
|
+
subject.expects(:monta_segmento_s).with(pagamento, 55, 4).returns("RESULTADO_SEGMENTO_S_5")
|
327
|
+
subject.expects(:monta_segmento_s).with(pagamento_2, 55, 8).returns("RESULTADO_SEGMENTO_S_9")
|
328
|
+
resultado = subject.monta_lote(lote, 55)
|
329
|
+
resultado[4].must_equal "RESULTADO_SEGMENTO_S_5"
|
330
|
+
resultado[8].must_equal "RESULTADO_SEGMENTO_S_9"
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context "6 - Sexta posição do vetor" do
|
335
|
+
it "deve ter o conteudo do metodo monta_trailer_lote passando o nro_lote e o contador" do
|
336
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
337
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
338
|
+
subject.stubs(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
339
|
+
subject.stubs(:monta_segmento_r).with(pagamento, 55, 3).returns("RESULTADO_SEGMENTO_R")
|
340
|
+
subject.stubs(:monta_segmento_s).with(pagamento, 55, 4).returns("RESULTADO_SEGMENTO_S")
|
341
|
+
subject.expects(:monta_trailer_lote).with(lote, 55, 6).returns("RESULTADO_TRAILER_LOTE")
|
342
|
+
resultado = subject.monta_lote(lote, 55)
|
343
|
+
resultado[5].must_equal "RESULTADO_TRAILER_LOTE"
|
344
|
+
end
|
345
|
+
it "Se o lote tiver 2 pagamentos deve setar o monta_trailer_lote 10" do
|
346
|
+
pagamento_2 = FactoryGirl.build(:remessa_pagamento)
|
347
|
+
lote.pagamentos = [pagamento, pagamento_2]
|
348
|
+
subject.stubs(:monta_header_lote).with(lote, 55).returns("RESULTADO_HEADER_LOTE")
|
349
|
+
subject.stubs(:monta_segmento_p).with(pagamento, 55, 1).returns("RESULTADO_SEGMENTO_P")
|
350
|
+
subject.stubs(:monta_segmento_p).with(pagamento_2, 55, 5).returns("RESULTADO_SEGMENTO_P")
|
351
|
+
subject.stubs(:monta_segmento_q).with(pagamento, 55, 2).returns("RESULTADO_SEGMENTO_Q")
|
352
|
+
subject.stubs(:monta_segmento_q).with(pagamento_2, 55, 6).returns("RESULTADO_SEGMENTO_Q")
|
353
|
+
subject.stubs(:monta_segmento_r).with(pagamento, 55, 3).returns("RESULTADO_SEGMENTO_R")
|
354
|
+
subject.stubs(:monta_segmento_r).with(pagamento_2, 55, 7).returns("RESULTADO_SEGMENTO_R")
|
355
|
+
subject.stubs(:monta_segmento_s).with(pagamento, 55, 4).returns("RESULTADO_SEGMENTO_S_5")
|
356
|
+
subject.stubs(:monta_segmento_s).with(pagamento_2, 55, 8).returns("RESULTADO_SEGMENTO_S_9")
|
357
|
+
subject.expects(:monta_trailer_lote).with(lote, 55, 10).returns("RESULTADO_TRAILER_LOTE")
|
358
|
+
resultado = subject.monta_lote(lote, 55)
|
359
|
+
resultado[9].must_equal "RESULTADO_TRAILER_LOTE"
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
context "remoção de caracteres especiais" do
|
364
|
+
it "deve remover" do
|
365
|
+
subject.stubs(:monta_header_arquivo).returns("AÇÃOíóú")
|
366
|
+
subject.dados_do_arquivo[0..6].must_equal "ACAOIOU"
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
context "Tamanho de caracteres" do
|
371
|
+
it "para monta_header_arquivo deve ter 240 caracteres" do
|
372
|
+
subject.monta_header_arquivo.size.must_equal 240
|
373
|
+
end
|
374
|
+
it "para monta_lote deve ter 1440 caracteres" do
|
375
|
+
subject.monta_lote(lote,1).join("").size.must_equal 1440
|
376
|
+
end
|
377
|
+
|
378
|
+
it "para monta_header_lote deve ter 240 caracteres" do
|
379
|
+
subject.monta_header_lote(lote, 1).size.must_equal 240
|
380
|
+
end
|
381
|
+
|
382
|
+
it "para monta_segmento_p deve ter 240 caracteres" do
|
383
|
+
subject.monta_segmento_p(pagamento, 1, 2).size.must_equal 240
|
384
|
+
end
|
385
|
+
|
386
|
+
it "para monta_segmento_q deve ter 240 caracteres" do
|
387
|
+
subject.monta_segmento_q(pagamento, 1, 2).size.must_equal 240
|
388
|
+
end
|
389
|
+
|
390
|
+
# Para o segmento R e S esse teste é feito dentro dos modules
|
391
|
+
|
392
|
+
it "para monta_trailer_lote deve ter 240 caracteres" do
|
393
|
+
subject.monta_trailer_lote(lote, 1, 2).size.must_equal 240
|
394
|
+
end
|
395
|
+
it "para monta_trailer_arquivo deve ter 240 caracteres" do
|
396
|
+
subject.monta_trailer_arquivo(1, 2).size.must_equal 240
|
397
|
+
end
|
398
|
+
it "o total de caracteres do arquivo para 1 pagamento deve ser de 1445 caracteres" do
|
399
|
+
# 1440 são das montagens e 5 caracteres são das quebras de linha (\n)
|
400
|
+
subject.dados_do_arquivo.size.must_equal 1927
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|