brcobranca 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -1
- data/.travis.yml +7 -1
- data/Gemfile +13 -2
- data/Rakefile +2 -2
- data/brcobranca.gemspec +10 -17
- data/lib/brcobranca.rb +2 -5
- data/lib/brcobranca/arquivos/logos/bancobrasil.eps +0 -0
- data/lib/brcobranca/arquivos/logos/bradesco.eps +0 -0
- data/lib/brcobranca/arquivos/logos/caixa.eps +0 -0
- data/lib/brcobranca/arquivos/logos/hsbc.eps +0 -0
- data/lib/brcobranca/arquivos/logos/itau.eps +0 -0
- data/lib/brcobranca/arquivos/logos/santander.eps +0 -0
- data/lib/brcobranca/arquivos/logos/sicredi.eps +0 -0
- data/lib/brcobranca/arquivos/templates/modelo_generico.eps +0 -0
- data/lib/brcobranca/boleto/banco_brasil.rb +27 -29
- data/lib/brcobranca/boleto/base.rb +29 -30
- data/lib/brcobranca/boleto/bradesco.rb +14 -15
- data/lib/brcobranca/boleto/caixa.rb +25 -23
- data/lib/brcobranca/boleto/hsbc.rb +30 -34
- data/lib/brcobranca/boleto/itau.rb +23 -25
- data/lib/brcobranca/boleto/santander.rb +17 -19
- data/lib/brcobranca/boleto/sicredi.rb +19 -19
- data/lib/brcobranca/boleto/template/base.rb +0 -2
- data/lib/brcobranca/boleto/template/rghost.rb +72 -74
- data/lib/brcobranca/boleto/template/rghost_carne.rb +105 -118
- data/lib/brcobranca/calculo.rb +22 -22
- data/lib/brcobranca/calculo_data.rb +8 -8
- data/lib/brcobranca/currency.rb +11 -11
- data/lib/brcobranca/formatacao.rb +16 -16
- data/lib/brcobranca/limpeza.rb +4 -4
- data/lib/brcobranca/retorno/base.rb +0 -1
- data/lib/brcobranca/retorno/retorno_cbr643.rb +35 -35
- data/lib/brcobranca/retorno/retorno_cnab240.rb +39 -40
- data/lib/brcobranca/retorno/retorno_cnab400.rb +21 -26
- data/lib/brcobranca/version.rb +2 -2
- data/spec/brcobranca/banco_bradesco_spec.rb +113 -113
- data/spec/brcobranca/banco_brasil_spec.rb +167 -167
- data/spec/brcobranca/banco_caixa_spec.rb +58 -58
- data/spec/brcobranca/banco_hsbc_spec.rb +117 -118
- data/spec/brcobranca/banco_sicredi_spec.rb +92 -93
- data/spec/brcobranca/base_spec.rb +78 -78
- data/spec/brcobranca/boletos_em_lote_spec.rb +22 -22
- data/spec/brcobranca/core_ext_spec.rb +134 -135
- data/spec/brcobranca/currency_spec.rb +59 -59
- data/spec/brcobranca/itau_spec.rb +137 -137
- data/spec/brcobranca/retorno_cbr643_spec.rb +32 -32
- data/spec/brcobranca/retorno_cnab400_spec.rb +40 -42
- data/spec/brcobranca/retorno_cnab_240_spec.rb +17 -19
- data/spec/brcobranca/rghost_spec.rb +21 -21
- data/spec/brcobranca/santander_spec.rb +80 -80
- data/spec/brcobranca_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -1
- metadata +12 -54
- data/VERSION +0 -1
- data/lib/brcobranca/arquivos/logos/bancobrasil.jpg +0 -0
- data/lib/brcobranca/arquivos/logos/bradesco.jpg +0 -0
- data/lib/brcobranca/arquivos/logos/caixa.jpg +0 -0
- data/lib/brcobranca/arquivos/logos/hsbc.jpg +0 -0
- data/lib/brcobranca/arquivos/logos/itau.jpg +0 -0
- data/lib/brcobranca/arquivos/logos/santander.jpg +0 -0
- data/lib/brcobranca/arquivos/logos/sicredi.jpg +0 -0
@@ -1,39 +1,39 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe 'Muúltiplos boletos' do #:nodoc:[all]
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
@valid_attributes = {
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
8
|
+
especie_documento: 'DM',
|
9
|
+
moeda: '9',
|
10
|
+
data_documento: Date.today,
|
11
|
+
dias_vencimento: 1,
|
12
|
+
aceite: 'S',
|
13
|
+
quantidade: 1,
|
14
|
+
valor: 0.0,
|
15
|
+
local_pagamento: 'QUALQUER BANCO ATÉ O VENCIMENTO',
|
16
|
+
cedente: 'Kivanio Barbosa',
|
17
|
+
documento_cedente: '12345678912',
|
18
|
+
sacado: 'Claudio Pozzebom',
|
19
|
+
sacado_documento: '12345678900',
|
20
|
+
agencia: '4042',
|
21
|
+
conta_corrente: '61900',
|
22
|
+
convenio: 12_387_989,
|
23
|
+
numero_documento: '777700168'
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'imprimir múltiplos boleto em lote' do
|
28
28
|
boleto_1 = Brcobranca::Boleto::BancoBrasil.new(@valid_attributes)
|
29
29
|
boleto_2 = Brcobranca::Boleto::Bradesco.new(@valid_attributes)
|
30
30
|
boleto_3 = Brcobranca::Boleto::BancoBrasil.new(@valid_attributes)
|
31
31
|
|
32
32
|
boletos = [boleto_1, boleto_2, boleto_3]
|
33
33
|
|
34
|
-
%w
|
35
|
-
file_body=Brcobranca::Boleto::Base.lote(boletos,
|
36
|
-
tmp_file=Tempfile.new(
|
34
|
+
%w(pdf jpg tif png).each do |format|
|
35
|
+
file_body = Brcobranca::Boleto::Base.lote(boletos, formato: "#{format}".to_sym)
|
36
|
+
tmp_file = Tempfile.new('foobar.' << format)
|
37
37
|
tmp_file.puts file_body
|
38
38
|
tmp_file.close
|
39
39
|
expect(File.exist?(tmp_file.path)).to be_truthy
|
@@ -43,4 +43,4 @@ describe "Muúltiplos boletos" do #:nodoc:[all]
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
end
|
46
|
+
end
|
@@ -3,184 +3,183 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
module Brcobranca
|
5
5
|
describe Formatacao do
|
6
|
-
it
|
7
|
-
expect(
|
8
|
-
expect(
|
9
|
-
expect(
|
6
|
+
it 'Formata o CPF' do
|
7
|
+
expect(98_789_298_790.to_br_cpf).to eql('987.892.987-90')
|
8
|
+
expect('98789298790'.to_br_cpf).to eql('987.892.987-90')
|
9
|
+
expect('987.892.987-90'.to_br_cpf).to eql('987.892.987-90')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(
|
14
|
-
expect(
|
15
|
-
expect(
|
12
|
+
it 'Formata o CEP' do
|
13
|
+
expect(85_253_100.to_br_cep).to eql('85253-100')
|
14
|
+
expect('85253100'.to_br_cep).to eql('85253-100')
|
15
|
+
expect('85253-100'.to_br_cep).to eql('85253-100')
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
expect(
|
20
|
-
expect(
|
21
|
-
expect(
|
18
|
+
it 'Formata o CNPJ' do
|
19
|
+
expect(88_394_510_000_103.to_br_cnpj).to eql('88.394.510/0001-03')
|
20
|
+
expect('88394510000103'.to_br_cnpj).to eql('88.394.510/0001-03')
|
21
|
+
expect('88.394.510/0001-03'.to_br_cnpj).to eql('88.394.510/0001-03')
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
expect(
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
expect(
|
35
|
-
expect(
|
24
|
+
it 'Formata números automáticamente de acordo com o número de caracteres' do
|
25
|
+
expect(98_789_298_790.formata_documento).to eql('987.892.987-90')
|
26
|
+
expect('98789298790'.formata_documento).to eql('987.892.987-90')
|
27
|
+
expect('987.892.987-90'.formata_documento).to eql('987.892.987-90')
|
28
|
+
expect(85_253_100.formata_documento).to eql('85253-100')
|
29
|
+
expect('85253100'.formata_documento).to eql('85253-100')
|
30
|
+
expect('85253-100'.formata_documento).to eql('85253-100')
|
31
|
+
expect(88_394_510_000_103.formata_documento).to eql('88.394.510/0001-03')
|
32
|
+
expect('88394510000103'.formata_documento).to eql('88.394.510/0001-03')
|
33
|
+
expect('88.394.510/0001-03'.formata_documento).to eql('88.394.510/0001-03')
|
34
|
+
expect('8839'.formata_documento).to eql('8839')
|
35
|
+
expect('8839451000010388394510000103'.formata_documento).to eql('8839451000010388394510000103')
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect {
|
42
|
-
expect {
|
43
|
-
expect {
|
44
|
-
expect {
|
38
|
+
it 'Monta linha digitável' do
|
39
|
+
expect('00192376900000135000000001238798777770016818'.linha_digitavel).to eql('00190.00009 01238.798779 77700.168188 2 37690000013500')
|
40
|
+
expect('00192376900000135000000001238798777770016818'.linha_digitavel).to be_a_kind_of(String)
|
41
|
+
expect { ''.linha_digitavel }.to raise_error(ArgumentError)
|
42
|
+
expect { '00193373700'.linha_digitavel }.to raise_error(ArgumentError)
|
43
|
+
expect { '0019337370000193373700'.linha_digitavel }.to raise_error(ArgumentError)
|
44
|
+
expect { '00b193373700bb00193373700'.linha_digitavel }.to raise_error(ArgumentError)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe Calculo do
|
49
|
-
it
|
50
|
-
expect {
|
51
|
-
expect {
|
49
|
+
it 'Calcula módulo 10' do
|
50
|
+
expect { ''.modulo10 }.to raise_error(ArgumentError)
|
51
|
+
expect { ' '.modulo10 }.to raise_error(ArgumentError)
|
52
52
|
expect(0.modulo10).to eql(0)
|
53
|
-
expect(
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
-
expect(
|
57
|
-
expect(
|
58
|
-
expect(
|
59
|
-
expect(
|
60
|
-
expect(
|
61
|
-
expect(
|
62
|
-
expect(
|
63
|
-
expect(
|
64
|
-
expect(
|
65
|
-
expect(
|
66
|
-
expect(
|
67
|
-
expect(
|
53
|
+
expect('0'.modulo10).to eql(0)
|
54
|
+
expect('001905009'.modulo10).to eql(5)
|
55
|
+
expect('4014481606'.modulo10).to eql(9)
|
56
|
+
expect('0680935031'.modulo10).to eql(4)
|
57
|
+
expect('29004590'.modulo10).to eql(5)
|
58
|
+
expect('341911012'.modulo10).to eql(1)
|
59
|
+
expect('3456788005'.modulo10).to eql(8)
|
60
|
+
expect('7123457000'.modulo10).to eql(1)
|
61
|
+
expect('00571234511012345678'.modulo10).to eql(8)
|
62
|
+
expect('001905009'.modulo10).to be_a_kind_of(Fixnum)
|
63
|
+
expect(1_905_009.modulo10).to eql(5)
|
64
|
+
expect(4_014_481_606.modulo10).to eql(9)
|
65
|
+
expect(680_935_031.modulo10).to eql(4)
|
66
|
+
expect(29_004_590.modulo10).to eql(5)
|
67
|
+
expect(1_905_009.modulo10).to be_a_kind_of(Fixnum)
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
71
|
-
expect(
|
72
|
-
expect(
|
73
|
-
expect(
|
74
|
-
expect(
|
75
|
-
expect(
|
76
|
-
expect(
|
77
|
-
expect(
|
78
|
-
expect(
|
79
|
-
expect(
|
80
|
-
expect(5444.multiplicador([2,3,4,5,6,7,8,9])).to eql(61)
|
81
|
-
expect(
|
82
|
-
expect(5444.multiplicador([2,3,4,5,6,7,8,9])).to be_a_kind_of(Fixnum)
|
83
|
-
expect {
|
70
|
+
it 'Multiplicador' do
|
71
|
+
expect('85068014982'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(255)
|
72
|
+
expect('05009401448'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(164)
|
73
|
+
expect('12387987777700168'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(460)
|
74
|
+
expect('34230'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(55)
|
75
|
+
expect('258281'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(118)
|
76
|
+
expect('5444'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to be_a_kind_of(Fixnum)
|
77
|
+
expect('000000005444'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to be_a_kind_of(Fixnum)
|
78
|
+
expect(85_068_014_982.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(255)
|
79
|
+
expect(5_009_401_448.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(164)
|
80
|
+
expect(5444.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(61)
|
81
|
+
expect(1_129_004_590.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to eql(162)
|
82
|
+
expect(5444.multiplicador([2, 3, 4, 5, 6, 7, 8, 9])).to be_a_kind_of(Fixnum)
|
83
|
+
expect { '2582fd81'.multiplicador([2, 3, 4, 5, 6, 7, 8, 9]) }.to raise_error(ArgumentError)
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
87
|
-
expect(
|
88
|
-
expect(
|
89
|
-
expect(
|
90
|
-
expect(
|
91
|
-
expect(
|
92
|
-
expect(
|
93
|
-
expect(
|
94
|
-
expect(
|
95
|
-
expect(
|
96
|
-
expect(
|
97
|
-
expect(
|
98
|
-
expect(
|
99
|
-
expect(
|
100
|
-
expect(
|
101
|
-
expect(
|
102
|
-
expect(
|
103
|
-
expect(
|
104
|
-
expect(
|
105
|
-
expect(
|
106
|
-
expect(
|
107
|
-
expect(
|
108
|
-
expect(
|
86
|
+
it 'Calcula módulo 11 de 9 para 2' do
|
87
|
+
expect('85068014982'.modulo11_9to2).to eql(9)
|
88
|
+
expect('05009401448'.modulo11_9to2).to eql(1)
|
89
|
+
expect('12387987777700168'.modulo11_9to2).to eql(2)
|
90
|
+
expect('4042'.modulo11_9to2).to eql(8)
|
91
|
+
expect('61900'.modulo11_9to2).to eql(0)
|
92
|
+
expect('0719'.modulo11_9to2).to eql(6)
|
93
|
+
expect('000000005444'.modulo11_9to2).to eql(5)
|
94
|
+
expect('5444'.modulo11_9to2).to eql(5)
|
95
|
+
expect('01129004590'.modulo11_9to2).to eql(3)
|
96
|
+
expect('15735'.modulo11_9to2).to eql(10)
|
97
|
+
expect('777700168'.modulo11_9to2).to eql(0)
|
98
|
+
expect('77700168'.modulo11_9to2).to eql(3)
|
99
|
+
expect('00015448'.modulo11_9to2).to eql(2)
|
100
|
+
expect('15448'.modulo11_9to2).to eql(2)
|
101
|
+
expect('12345678'.modulo11_9to2).to eql(9)
|
102
|
+
expect('34230'.modulo11_9to2).to eql(0)
|
103
|
+
expect('258281'.modulo11_9to2).to eql(3)
|
104
|
+
expect('5444'.modulo11_9to2).to be_a_kind_of(Fixnum)
|
105
|
+
expect('000000005444'.modulo11_9to2).to be_a_kind_of(Fixnum)
|
106
|
+
expect(85_068_014_982.modulo11_9to2).to eql(9)
|
107
|
+
expect(5_009_401_448.modulo11_9to2).to eql(1)
|
108
|
+
expect(12_387_987_777_700_168.modulo11_9to2).to eql(2)
|
109
109
|
expect(4042.modulo11_9to2).to eql(8)
|
110
|
-
expect(
|
110
|
+
expect(61_900.modulo11_9to2).to eql(0)
|
111
111
|
expect(719.modulo11_9to2).to eql(6)
|
112
112
|
expect(5444.modulo11_9to2).to eql(5)
|
113
|
-
expect(
|
113
|
+
expect(1_129_004_590.modulo11_9to2).to eql(3)
|
114
114
|
expect(5444.modulo11_9to2).to be_a_kind_of(Fixnum)
|
115
|
-
expect {
|
115
|
+
expect { '2582fd81'.modulo11_9to2 }.to raise_error(ArgumentError)
|
116
116
|
end
|
117
117
|
|
118
|
-
it
|
119
|
-
expect(
|
120
|
-
expect(
|
121
|
-
expect(
|
122
|
-
expect(
|
123
|
-
expect(
|
124
|
-
expect(
|
125
|
-
expect(
|
126
|
-
expect(
|
127
|
-
expect(
|
128
|
-
expect(
|
129
|
-
expect(
|
130
|
-
expect(
|
131
|
-
expect(
|
132
|
-
expect {
|
118
|
+
it 'Calcula módulo 11 de 9 para 2, trocando resto 10 por X' do
|
119
|
+
expect('85068014982'.modulo11_9to2_10_como_x).to eql(9)
|
120
|
+
expect('05009401448'.modulo11_9to2_10_como_x).to eql(1)
|
121
|
+
expect('12387987777700168'.modulo11_9to2_10_como_x).to eql(2)
|
122
|
+
expect('4042'.modulo11_9to2_10_como_x).to eql(8)
|
123
|
+
expect('61900'.modulo11_9to2_10_como_x).to eql(0)
|
124
|
+
expect('0719'.modulo11_9to2_10_como_x).to eql(6)
|
125
|
+
expect('000000005444'.modulo11_9to2_10_como_x).to eql(5)
|
126
|
+
expect('5444'.modulo11_9to2_10_como_x).to eql(5)
|
127
|
+
expect('01129004590'.modulo11_9to2_10_como_x).to eql(3)
|
128
|
+
expect('15735'.modulo11_9to2_10_como_x).to eql('X')
|
129
|
+
expect('15735'.modulo11_9to2_10_como_x).to be_a_kind_of(String)
|
130
|
+
expect('5444'.modulo11_9to2_10_como_x).to be_a_kind_of(Fixnum)
|
131
|
+
expect('000000005444'.modulo11_9to2_10_como_x).to be_a_kind_of(Fixnum)
|
132
|
+
expect { '2582fd81'.modulo11_9to2_10_como_x }.to raise_error(ArgumentError)
|
133
133
|
end
|
134
134
|
|
135
|
-
it
|
136
|
-
expect(
|
137
|
-
expect(
|
138
|
-
expect(
|
139
|
-
expect(
|
140
|
-
expect(
|
141
|
-
expect(
|
142
|
-
expect(
|
143
|
-
expect {
|
135
|
+
it 'Calcula módulo 11 de 2 para 9' do
|
136
|
+
expect('0019373700000001000500940144816060680935031'.modulo11_2to9).to eql(3)
|
137
|
+
expect('0019373700000001000500940144816060680935031'.modulo11_2to9).to be_a_kind_of(Fixnum)
|
138
|
+
expect('3419166700000123451101234567880057123457000'.modulo11_2to9).to eql(6)
|
139
|
+
expect('7459588800000774303611264424020000000002674'.modulo11_2to9).to eql(4)
|
140
|
+
expect('7459588800000580253611264424020000000003131'.modulo11_2to9).to eql(1)
|
141
|
+
expect(19_373_700_000_001_000_500_940_144_816_060_680_935_031.modulo11_2to9).to eql(3)
|
142
|
+
expect(19_373_700_000_001_000_500_940_144_816_060_680_935_031.modulo11_2to9).to be_a_kind_of(Fixnum)
|
143
|
+
expect { '2582fd81'.modulo11_2to9 }.to raise_error(ArgumentError)
|
144
144
|
end
|
145
145
|
|
146
|
-
it
|
146
|
+
it 'Calcula a soma dos digitos de um número com mais de 1 algarismo' do
|
147
147
|
expect(111.soma_digitos).to eql(3)
|
148
148
|
expect(8.soma_digitos).to eql(8)
|
149
|
-
expect(
|
150
|
-
expect(
|
149
|
+
expect('111'.soma_digitos).to eql(3)
|
150
|
+
expect('8'.soma_digitos).to eql(8)
|
151
151
|
expect(0.soma_digitos).to eql(0)
|
152
152
|
expect(111.soma_digitos).to be_a_kind_of(Fixnum)
|
153
|
-
expect(
|
153
|
+
expect('111'.soma_digitos).to be_a_kind_of(Fixnum)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
describe Limpeza do
|
158
|
-
it
|
159
|
-
expect(1234.03.limpa_valor_moeda).to eq(
|
160
|
-
expect(1234.3.limpa_valor_moeda).to eq(
|
158
|
+
it 'Formata Float em String' do
|
159
|
+
expect(1234.03.limpa_valor_moeda).to eq('123403')
|
160
|
+
expect(1234.3.limpa_valor_moeda).to eq('123430')
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
describe CalculoData do
|
165
|
-
it
|
166
|
-
expect((Date.parse
|
167
|
-
expect((Date.parse
|
168
|
-
expect((Date.parse
|
165
|
+
it 'Calcula o fator de vencimento' do
|
166
|
+
expect((Date.parse '2008-02-01').fator_vencimento).to eq('3769')
|
167
|
+
expect((Date.parse '2008-02-02').fator_vencimento).to eq('3770')
|
168
|
+
expect((Date.parse '2008-02-06').fator_vencimento).to eq('3774')
|
169
169
|
end
|
170
170
|
|
171
|
-
it
|
172
|
-
expect((Date.parse
|
173
|
-
expect((Date.parse
|
174
|
-
expect((Date.parse
|
171
|
+
it 'Formata a data no padrão visual brasileiro' do
|
172
|
+
expect((Date.parse '2008-02-01').to_s_br).to eq('01/02/2008')
|
173
|
+
expect((Date.parse '2008-02-02').to_s_br).to eq('02/02/2008')
|
174
|
+
expect((Date.parse '2008-02-06').to_s_br).to eq('06/02/2008')
|
175
175
|
end
|
176
176
|
|
177
|
-
it
|
178
|
-
expect((Date.parse
|
179
|
-
expect((Date.parse
|
180
|
-
expect((Date.parse
|
177
|
+
it 'Calcula data juliana' do
|
178
|
+
expect((Date.parse '2009-02-11').to_juliano).to eql('0429')
|
179
|
+
expect((Date.parse '2008-02-11').to_juliano).to eql('0428')
|
180
|
+
expect((Date.parse '2009-04-08').to_juliano).to eql('0989')
|
181
181
|
# Ano 2008 eh bisexto
|
182
|
-
expect((Date.parse
|
182
|
+
expect((Date.parse '2008-04-08').to_juliano).to eql('0998')
|
183
183
|
end
|
184
184
|
end
|
185
|
-
|
186
|
-
end
|
185
|
+
end
|
@@ -4,79 +4,79 @@ require 'spec_helper'
|
|
4
4
|
module Brcobranca #:nodoc:[all]
|
5
5
|
module Currency #:nodoc:[all]
|
6
6
|
describe String do
|
7
|
-
it
|
8
|
-
expect(
|
9
|
-
expect(
|
10
|
-
expect(
|
11
|
-
expect(
|
12
|
-
expect(
|
13
|
-
expect(
|
14
|
-
expect(
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
21
|
-
expect(
|
22
|
-
expect(
|
7
|
+
it 'returns true if value seted is a valid ruby number' do
|
8
|
+
expect('1234'.numeric?).to be_truthy
|
9
|
+
expect('123.4'.numeric?).to be_truthy
|
10
|
+
expect('123,4'.numeric?).to be_truthy
|
11
|
+
expect('1234.03'.numeric?).to be_truthy
|
12
|
+
expect('1234,03'.numeric?).to be_truthy
|
13
|
+
expect('-1234'.numeric?).to be_truthy
|
14
|
+
expect('-123.4'.numeric?).to be_truthy
|
15
|
+
expect('-123,4'.numeric?).to be_truthy
|
16
|
+
expect('-1234.03'.numeric?).to be_truthy
|
17
|
+
expect('-1234,03'.numeric?).to be_truthy
|
18
|
+
expect('+1234'.numeric?).to be_truthy
|
19
|
+
expect('+123.4'.numeric?).to be_truthy
|
20
|
+
expect('+123,4'.numeric?).to be_truthy
|
21
|
+
expect('+1234.03'.numeric?).to be_truthy
|
22
|
+
expect('+1234,03'.numeric?).to be_truthy
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
expect(
|
25
|
+
it 'returns false if value seted is NOT a valid ruby number' do
|
26
|
+
expect('1234,'.numeric?).to be_falsey
|
27
|
+
expect('1234.'.numeric?).to be_falsey
|
28
|
+
expect('1,234.03'.numeric?).to be_falsey
|
29
|
+
expect('1.234.03'.numeric?).to be_falsey
|
30
|
+
expect('1,234,03'.numeric?).to be_falsey
|
31
|
+
expect('12.340,03'.numeric?).to be_falsey
|
32
|
+
expect('1234ab'.numeric?).to be_falsey
|
33
|
+
expect('ab1213'.numeric?).to be_falsey
|
34
|
+
expect('ffab'.numeric?).to be_falsey
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
37
|
+
it 'converts value seted to valid ruby number' do
|
38
|
+
expect('1234'.to_number).to eql(1234.0)
|
39
|
+
expect('123.4'.to_number).to eql(123.4)
|
40
|
+
expect('123,4'.to_number).to eql(123.4)
|
41
|
+
expect('1234.03'.to_number).to eql(1234.03)
|
42
|
+
expect('1234,03'.to_number).to eql(1234.03)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
expect(
|
47
|
-
expect(
|
48
|
-
expect(
|
49
|
-
expect(
|
50
|
-
expect(
|
51
|
-
expect(
|
52
|
-
expect(
|
53
|
-
expect(
|
54
|
-
expect(
|
45
|
+
it 'returns nil when is not possible convert value seted' do
|
46
|
+
expect('1234,'.to_number).to be_nil
|
47
|
+
expect('1234.'.to_number).to be_nil
|
48
|
+
expect('1,234.03'.to_number).to be_nil
|
49
|
+
expect('1.234.03'.to_number).to be_nil
|
50
|
+
expect('1,234,03'.to_number).to be_nil
|
51
|
+
expect('12.340,03'.to_number).to be_nil
|
52
|
+
expect('1234ab'.to_number).to be_nil
|
53
|
+
expect('ab1213'.to_number).to be_nil
|
54
|
+
expect('ffab'.to_number).to be_nil
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
describe Number do
|
59
|
-
it
|
60
|
-
expect(1234.to_currency).to eql(
|
61
|
-
expect(123.4.to_currency).to eql(
|
62
|
-
expect(1234.03.to_currency).to eql(
|
63
|
-
expect(1234.03.to_currency(options = {:
|
64
|
-
expect(1234.03.to_currency(options = {:
|
65
|
-
expect(1234.03.to_currency(options = {:
|
66
|
-
expect(1234.03.to_currency(options = {:
|
59
|
+
it 'converts value seted to currency value' do
|
60
|
+
expect(1234.to_currency).to eql('1.234,00')
|
61
|
+
expect(123.4.to_currency).to eql('123,40')
|
62
|
+
expect(1234.03.to_currency).to eql('1.234,03')
|
63
|
+
expect(1234.03.to_currency(options = { unit: 'R$ ' })).to eql('R$ 1.234,03')
|
64
|
+
expect(1234.03.to_currency(options = { unit: 'R$ ', separator: '.' })).to eql('R$ 1.234.03')
|
65
|
+
expect(1234.03.to_currency(options = { unit: 'R$ ', separator: '.', delimiter: ',' })).to eql('R$ 1,234.03')
|
66
|
+
expect(1234.03.to_currency(options = { unit: 'R$ ', precision: 3 })).to eql('R$ 1.234,030')
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
70
|
-
expect(1234.with_delimiter).to eql(
|
71
|
-
expect(123.4.with_delimiter).to eql(
|
72
|
-
expect(1234.03.with_delimiter).to eql(
|
69
|
+
it 'converts value seted using delimiter and separator' do
|
70
|
+
expect(1234.with_delimiter).to eql('1,234')
|
71
|
+
expect(123.4.with_delimiter).to eql('123.4')
|
72
|
+
expect(1234.03.with_delimiter).to eql('1,234.03')
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
76
|
-
expect(1234.with_precision).to eql(
|
77
|
-
expect(123.4.with_precision).to eql(
|
78
|
-
expect(1234.03.with_precision).to eql(
|
75
|
+
it 'converts value seted using precision' do
|
76
|
+
expect(1234.with_precision).to eql('1234.000')
|
77
|
+
expect(123.4.with_precision).to eql('123.400')
|
78
|
+
expect(1234.03.with_precision).to eql('1234.030')
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
82
|
-
end
|
82
|
+
end
|