br_boleto 0.1.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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +145 -0
  4. data/History.txt +4 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +156 -0
  7. data/Rakefile +8 -0
  8. data/br_boleto.gemspec +26 -0
  9. data/lib/br_boleto.rb +87 -0
  10. data/lib/br_boleto/calculos/digitos.rb +35 -0
  11. data/lib/br_boleto/calculos/fator_vencimento.rb +129 -0
  12. data/lib/br_boleto/calculos/fatores_de_multiplicacao.rb +67 -0
  13. data/lib/br_boleto/calculos/linha_digitavel.rb +158 -0
  14. data/lib/br_boleto/calculos/modulo10.rb +83 -0
  15. data/lib/br_boleto/calculos/modulo11.rb +54 -0
  16. data/lib/br_boleto/calculos/modulo11_fator3197.rb +88 -0
  17. data/lib/br_boleto/calculos/modulo11_fator_de2a7.rb +97 -0
  18. data/lib/br_boleto/calculos/modulo11_fator_de2a9.rb +83 -0
  19. data/lib/br_boleto/calculos/modulo11_fator_de2a9_resto_zero.rb +29 -0
  20. data/lib/br_boleto/calculos/modulo11_fator_de9a2.rb +65 -0
  21. data/lib/br_boleto/calculos/modulo11_fator_de9a2_resto_x.rb +55 -0
  22. data/lib/br_boleto/calculos/modulo_numero_de_controle.rb +117 -0
  23. data/lib/br_boleto/core/boleto.rb +558 -0
  24. data/lib/br_boleto/core/sicoob.rb +169 -0
  25. data/lib/br_boleto/version.rb +8 -0
  26. data/test/br_boleto/calculos/digitos_test.rb +15 -0
  27. data/test/br_boleto/calculos/fator_vencimento_test.rb +56 -0
  28. data/test/br_boleto/calculos/fatores_de_multiplicacao_test.rb +66 -0
  29. data/test/br_boleto/calculos/linha_digitavel_test.rb +58 -0
  30. data/test/br_boleto/calculos/modulo10_test.rb +54 -0
  31. data/test/br_boleto/calculos/modulo11_fator3197_test.rb +43 -0
  32. data/test/br_boleto/calculos/modulo11_fator_de2a7_test.rb +44 -0
  33. data/test/br_boleto/calculos/modulo11_fator_de2a9_resto_zero_test.rb +40 -0
  34. data/test/br_boleto/calculos/modulo11_fator_de2a9_test.rb +68 -0
  35. data/test/br_boleto/calculos/modulo11_fator_de9a2_resto_x_test.rb +38 -0
  36. data/test/br_boleto/calculos/modulo11_fator_de9a2_test.rb +32 -0
  37. data/test/br_boleto/calculos/modulo11_test.rb +28 -0
  38. data/test/br_boleto/calculos/modulo_numero_de_controle_test.rb +38 -0
  39. data/test/br_boleto/core/boleto_test.rb +221 -0
  40. data/test/br_boleto/core/sicoob_test.rb +138 -0
  41. data/test/factories/boleto.rb +22 -0
  42. data/test/factories/boleto_sicoob.rb +23 -0
  43. data/test/inheritance/boleto_test.rb +15 -0
  44. data/test/inheritance/sicoob_test.rb +25 -0
  45. data/test/test_helper.rb +37 -0
  46. metadata +151 -0
@@ -0,0 +1,138 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe BrBoleto::Core::Sicoob do
5
+ subject { BrBoleto::Core::Sicoob.new }
6
+ context "on validations" do
7
+ it { must validate_length_of(:agencia).is_at_most(4) }
8
+
9
+ it { must validate_length_of(:codigo_cedente).is_at_most(7) }
10
+
11
+ it { must validate_length_of(:numero_documento).is_at_most(7) }
12
+
13
+ it { must validate_inclusion_of(:carteira).in_array(%w(1 3)) }
14
+ it { wont allow_value(9).for(:carteira) }
15
+ it { wont allow_value(6).for(:carteira) }
16
+
17
+ it { must validate_numericality_of(:valor_documento).is_less_than_or_equal_to(99999999.99) }
18
+
19
+ end
20
+ context "#agencia" do
21
+ it "get value when have a value" do
22
+ subject.agencia = '215'
23
+ subject.agencia.must_equal '0215'
24
+ end
25
+
26
+ it "returns nil when is nil" do
27
+ subject.agencia = nil
28
+ subject.agencia.must_be_nil
29
+ end
30
+ end
31
+
32
+ context "#conta_corrente" do
33
+ it "when have a value" do
34
+ subject.codigo_cedente = '9201'
35
+ subject.codigo_cedente.must_equal '0009201'
36
+ end
37
+
38
+ it "when is nil" do
39
+ subject.codigo_cedente = nil
40
+ subject.codigo_cedente.must_be_nil
41
+ end
42
+ end
43
+
44
+ context "#numero_documento" do
45
+ it "when have a value" do
46
+ subject.numero_documento = '1'
47
+ subject.numero_documento.must_equal '0000001'
48
+ end
49
+
50
+ it "when is nil" do
51
+ subject.numero_documento = nil
52
+ subject.numero_documento.must_be_nil
53
+ end
54
+ end
55
+ describe "#carteira" do
56
+ it "when have a value" do
57
+ subject.carteira = '1'
58
+
59
+ subject.carteira.must_equal '1'
60
+ end
61
+
62
+ it "when is nil" do
63
+ subject.carteira = nil
64
+ subject.carteira.must_be_nil
65
+ end
66
+ end
67
+
68
+ describe "#codigo_banco" do
69
+ it{ subject.codigo_banco.must_equal '756' }
70
+ end
71
+
72
+ describe "#digito_codigo_banco" do
73
+ it { subject.digito_codigo_banco.must_equal '0' }
74
+ end
75
+
76
+ describe "#agencia_codigo_beneficiario" do
77
+ subject { FactoryGirl.build(:boleto_sicoob, agencia: 48, codigo_cedente: '7368') }
78
+
79
+ it { subject.agencia_codigo_cedente.must_equal '0048 / 0007368' }
80
+ end
81
+
82
+ describe "#digito_verificador_nosso_numero" do
83
+ it "deve calcular pelo Modulo11Fator3197" do
84
+ subject.agencia = 1
85
+ subject.codigo_cedente = 33
86
+ subject.numero_documento = 111
87
+ BrBoleto::Calculos::Modulo11Fator3197.expects(:new).with("000100000000330000111").returns("meu_resultado")
88
+ subject.digito_verificador_nosso_numero.must_equal "meu_resultado"
89
+ end
90
+ end
91
+
92
+ describe "#nosso_numero" do
93
+ subject { FactoryGirl.build(:boleto_sicoob, numero_documento: '68315') }
94
+
95
+ it "deve retornar o numero do documento com o digito_verificador_nosso_numero" do
96
+ subject.stubs(:digito_verificador_nosso_numero).returns('9')
97
+ subject.numero_documento = '3646'
98
+ subject.nosso_numero.must_equal "0003646-9"
99
+ end
100
+ end
101
+
102
+ describe "#codigo_de_barras_do_banco" do
103
+ subject do
104
+ FactoryGirl.build(:boleto_sicoob,
105
+ carteira: '1',
106
+ agencia: '78',
107
+ codigo_cedente: '66',
108
+ # modalidade_cobranca: '1',
109
+ # parcelas: '1'
110
+ )
111
+ end
112
+ it "name" do
113
+ subject.stubs(:nosso_numero).returns('1234567-8')
114
+ subject.codigo_de_barras_do_banco.must_equal "1007801000006612345678001"
115
+ end
116
+
117
+ end
118
+
119
+ describe "#codigo_de_barras" do
120
+ subject do
121
+ FactoryGirl.build(:boleto_sicoob) do |sicoob|
122
+ sicoob.agencia = 3069
123
+ sicoob.codigo_cedente = 828_190 # Para o sicoob é o código do cliente
124
+ sicoob.numero_documento = 100_10
125
+ sicoob.carteira = 1
126
+ sicoob.valor_documento = 93015.78
127
+ sicoob.data_vencimento = Date.parse('2020-02-17')
128
+ end
129
+ end
130
+
131
+ it { subject.codigo_de_barras.must_equal '75699816800093015781306901082819000100107001' }
132
+ it { subject.linha_digitavel.must_equal '75691.30698 01082.819002 01001.070018 9 81680009301578' }
133
+ end
134
+
135
+ describe "#carteiras_suportadas" do
136
+ it { subject.class.carteiras_suportadas.must_equal ["1","3"] }
137
+ end
138
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+
3
+ FactoryGirl.define do
4
+ factory :core_boleto, class: BrBoleto::Core::Boleto do
5
+ numero_documento '191075'
6
+ valor_documento 101.99
7
+ data_vencimento Date.new(2015, 07, 10)
8
+ carteira '175'
9
+ agencia '0098'
10
+ conta_corrente '98701'
11
+ cedente 'Nome da razao social'
12
+ sacado 'Teste'
13
+ documento_sacado '725.275.005-10'
14
+ endereco_sacado 'Rua teste, 23045'
15
+ instrucoes1 'Lembrar de algo 1'
16
+ instrucoes2 'Lembrar de algo 2'
17
+ instrucoes3 'Lembrar de algo 3'
18
+ instrucoes4 'Lembrar de algo 4'
19
+ instrucoes5 'Lembrar de algo 5'
20
+ instrucoes6 'Lembrar de algo 6'
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+
3
+ FactoryGirl.define do
4
+ factory :boleto_sicoob, class: BrBoleto::Core::Sicoob do
5
+ agencia 95
6
+ codigo_cedente 6532
7
+ numero_documento 1101
8
+ carteira 1
9
+ valor_documento 93015.78
10
+ data_vencimento Date.parse('2019-02-17')
11
+ conta_corrente '98701'
12
+ cedente 'Nome da razao social'
13
+ sacado 'Teste'
14
+ documento_sacado '725.275.005-10'
15
+ endereco_sacado 'Rua teste, 23045'
16
+ instrucoes1 'Lembrar de algo 1'
17
+ instrucoes2 'Lembrar de algo 2'
18
+ instrucoes3 'Lembrar de algo 3'
19
+ instrucoes4 'Lembrar de algo 4'
20
+ instrucoes5 'Lembrar de algo 5'
21
+ instrucoes6 'Lembrar de algo 6'
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class TesteBoleto < BrBoleto::Boleto
5
+ def self.valor_documento_tamanho_maximo
6
+ 9_999.99 # Default 99999999.99
7
+ end
8
+ end
9
+
10
+ describe TesteBoleto do
11
+ subject { TesteBoleto.new() }
12
+ context "on validations" do
13
+ it { must validate_numericality_of(:valor_documento).is_less_than_or_equal_to(9_999.99) }
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class TesteSicoob < BrBoleto::Sicoob
5
+ def self.valor_documento_tamanho_maximo
6
+ 456.50 # Default 99999999.99
7
+ end
8
+
9
+ def self.carteiras_suportadas
10
+ %w[1] # Default %w[1 3]
11
+ end
12
+ end
13
+
14
+ describe TesteSicoob do
15
+ subject { TesteSicoob.new() }
16
+
17
+ describe "on validations" do
18
+ it { must validate_numericality_of(:valor_documento).is_less_than_or_equal_to(456.50) }
19
+
20
+ it { must validate_inclusion_of(:carteira).in_array(%w(1)) }
21
+ it { wont allow_value(3).for(:carteira) }
22
+ it { wont allow_value(6).for(:carteira) }
23
+ it { wont allow_value(9).for(:carteira) }
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+ require 'bundler/setup'
3
+ Bundler.require(:default, :test)
4
+
5
+ ENV["RAILS_ENV"] = "test"
6
+ require "rails/test_help"
7
+ require 'minitest/autorun'
8
+ require "minitest/rails"
9
+ require 'minitest/matchers_vaccine'
10
+
11
+ require 'shoulda/matchers'
12
+ require "minitest/reporters"
13
+ require 'mocha/mini_test'
14
+
15
+
16
+ require 'factory_girl_rails'
17
+
18
+
19
+ Minitest::Reporters.use!
20
+
21
+ ActiveSupport::TestCase.test_order = :sorted
22
+
23
+ FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
24
+ FactoryGirl.find_definitions
25
+
26
+ class Module
27
+ include Minitest::Spec::DSL
28
+ end
29
+
30
+ class Object
31
+ alias context describe
32
+ end
33
+
34
+ class MiniTest::Spec
35
+ include Shoulda::Matchers::ActiveModel
36
+ include FactoryGirl::Syntax::Methods
37
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: br_boleto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bruno M. Mergen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ description: Emissão de Boletos Bancários em Ruby
56
+ email:
57
+ - brunomergen@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - History.txt
65
+ - LICENSE
66
+ - README.markdown
67
+ - Rakefile
68
+ - br_boleto.gemspec
69
+ - lib/br_boleto.rb
70
+ - lib/br_boleto/calculos/digitos.rb
71
+ - lib/br_boleto/calculos/fator_vencimento.rb
72
+ - lib/br_boleto/calculos/fatores_de_multiplicacao.rb
73
+ - lib/br_boleto/calculos/linha_digitavel.rb
74
+ - lib/br_boleto/calculos/modulo10.rb
75
+ - lib/br_boleto/calculos/modulo11.rb
76
+ - lib/br_boleto/calculos/modulo11_fator3197.rb
77
+ - lib/br_boleto/calculos/modulo11_fator_de2a7.rb
78
+ - lib/br_boleto/calculos/modulo11_fator_de2a9.rb
79
+ - lib/br_boleto/calculos/modulo11_fator_de2a9_resto_zero.rb
80
+ - lib/br_boleto/calculos/modulo11_fator_de9a2.rb
81
+ - lib/br_boleto/calculos/modulo11_fator_de9a2_resto_x.rb
82
+ - lib/br_boleto/calculos/modulo_numero_de_controle.rb
83
+ - lib/br_boleto/core/boleto.rb
84
+ - lib/br_boleto/core/sicoob.rb
85
+ - lib/br_boleto/version.rb
86
+ - test/br_boleto/calculos/digitos_test.rb
87
+ - test/br_boleto/calculos/fator_vencimento_test.rb
88
+ - test/br_boleto/calculos/fatores_de_multiplicacao_test.rb
89
+ - test/br_boleto/calculos/linha_digitavel_test.rb
90
+ - test/br_boleto/calculos/modulo10_test.rb
91
+ - test/br_boleto/calculos/modulo11_fator3197_test.rb
92
+ - test/br_boleto/calculos/modulo11_fator_de2a7_test.rb
93
+ - test/br_boleto/calculos/modulo11_fator_de2a9_resto_zero_test.rb
94
+ - test/br_boleto/calculos/modulo11_fator_de2a9_test.rb
95
+ - test/br_boleto/calculos/modulo11_fator_de9a2_resto_x_test.rb
96
+ - test/br_boleto/calculos/modulo11_fator_de9a2_test.rb
97
+ - test/br_boleto/calculos/modulo11_test.rb
98
+ - test/br_boleto/calculos/modulo_numero_de_controle_test.rb
99
+ - test/br_boleto/core/boleto_test.rb
100
+ - test/br_boleto/core/sicoob_test.rb
101
+ - test/factories/boleto.rb
102
+ - test/factories/boleto_sicoob.rb
103
+ - test/inheritance/boleto_test.rb
104
+ - test/inheritance/sicoob_test.rb
105
+ - test/test_helper.rb
106
+ homepage: https://github.com/Brunomm/br_boleto
107
+ licenses:
108
+ - BSD
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '2.1'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Emissão de Boletos Bancários em Ruby
130
+ test_files:
131
+ - test/br_boleto/calculos/digitos_test.rb
132
+ - test/br_boleto/calculos/fator_vencimento_test.rb
133
+ - test/br_boleto/calculos/fatores_de_multiplicacao_test.rb
134
+ - test/br_boleto/calculos/linha_digitavel_test.rb
135
+ - test/br_boleto/calculos/modulo10_test.rb
136
+ - test/br_boleto/calculos/modulo11_fator3197_test.rb
137
+ - test/br_boleto/calculos/modulo11_fator_de2a7_test.rb
138
+ - test/br_boleto/calculos/modulo11_fator_de2a9_resto_zero_test.rb
139
+ - test/br_boleto/calculos/modulo11_fator_de2a9_test.rb
140
+ - test/br_boleto/calculos/modulo11_fator_de9a2_resto_x_test.rb
141
+ - test/br_boleto/calculos/modulo11_fator_de9a2_test.rb
142
+ - test/br_boleto/calculos/modulo11_test.rb
143
+ - test/br_boleto/calculos/modulo_numero_de_controle_test.rb
144
+ - test/br_boleto/core/boleto_test.rb
145
+ - test/br_boleto/core/sicoob_test.rb
146
+ - test/factories/boleto.rb
147
+ - test/factories/boleto_sicoob.rb
148
+ - test/inheritance/boleto_test.rb
149
+ - test/inheritance/sicoob_test.rb
150
+ - test/test_helper.rb
151
+ has_rdoc: