br_danfe 2.0.0 → 3.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/config.yml +19 -12
  3. data/.octocov.yml +18 -0
  4. data/Gemfile.lock +23 -20
  5. data/config/locales/pt-BR.yml +4 -3
  6. data/lib/br_danfe/danfe_lib/nfce_lib/header.rb +1 -5
  7. data/lib/br_danfe/danfe_lib/nfce_lib/recipient.rb +1 -1
  8. data/lib/br_danfe/danfe_lib/nfe_lib/dest.rb +2 -10
  9. data/lib/br_danfe/danfe_lib/nfe_lib/document.rb +5 -5
  10. data/lib/br_danfe/danfe_lib/nfe_lib/emit_header.rb +9 -1
  11. data/lib/br_danfe/danfe_lib/nfe_lib/entrega.rb +2 -10
  12. data/lib/br_danfe/danfe_lib/nfe_lib/transp.rb +1 -1
  13. data/lib/br_danfe/helper.rb +4 -0
  14. data/lib/br_danfe/version.rb +1 -1
  15. data/spec/br_danfe/cce_lib/document_spec.rb +12 -0
  16. data/spec/br_danfe/danfe_lib/nfce_lib/document_spec.rb +12 -0
  17. data/spec/br_danfe/danfe_lib/nfe_lib/document_spec.rb +19 -7
  18. data/spec/br_danfe/danfe_lib/nfe_lib/emit_header_spec.rb +63 -0
  19. data/spec/br_danfe/helper_spec.rb +25 -0
  20. data/spec/fixtures/nfe/lib/emit_header#render-nfe_key.pdf +16 -16
  21. data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +16 -16
  22. data/spec/fixtures/nfe/lib/emit_header#render-with_cpf.pdf +1075 -2
  23. data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +16 -16
  24. data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +14 -14
  25. data/spec/fixtures/nfe/lib/entrega#render-v2.00.pdf +0 -0
  26. data/spec/fixtures/nfe/lib/entrega#render-with-address-bigger.pdf +0 -0
  27. data/spec/fixtures/nfe/lib/entrega#render-with_cpf.pdf +0 -0
  28. data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +17 -17
  29. data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +15 -15
  30. data/spec/fixtures/nfe/v2.00/nfe_with_entrega.xml.fixture.pdf +16 -16
  31. data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +24 -24
  32. data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +15 -15
  33. data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +19 -19
  34. data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +15 -15
  35. data/spec/fixtures/nfe/v3.10/multiples.xmls.on.the.same.pdf.pdf +19 -19
  36. data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +15 -15
  37. data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +19 -19
  38. data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +15 -15
  39. data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +23 -23
  40. data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +19 -19
  41. data/spec/spec_helper.rb +9 -1
  42. metadata +8 -12
  43. data/lib/br_danfe/danfe_lib/nfce_lib/helper.rb +0 -11
  44. data/spec/br_danfe/danfe_lib/nfce_lib/helper_spec.rb +0 -28
  45. /data/spec/fixtures/nfe/lib/{document#lcnpj-blank.pdf → document#lcnpj_cpf-blank.pdf} +0 -0
  46. /data/spec/fixtures/nfe/lib/{document#lcnpj-invalid.pdf → document#lcnpj_cpf-invalid.pdf} +0 -0
  47. /data/spec/fixtures/nfe/lib/{document#lcnpj-valid.pdf → document#lcnpj_cpf-valid.pdf} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6957c52fda8133d7dbb9ddf4ae9f29f20bb45bb6ec41127c546ae93bd2221f2c
4
- data.tar.gz: 2b5031a95eb542e75f457723dee23d193f8f3407d22ba26dd85ded6400f55c35
3
+ metadata.gz: 1dc56c9e0a8e9af673a10afd8a3a2119ec9ba30e812c0e1fb3fea3af011fdeb1
4
+ data.tar.gz: 94ad7e6a029b10d402592d44641604ab70866fb475557263d4de52a90b455cf1
5
5
  SHA512:
6
- metadata.gz: 5ec5cf3a1c2ded1acc9c010c440328052a6a9660f1aaddd0bf1dcd1b1ea7ddd42f356ca433462743bb2f5443d75fd383f91d8aba8437f8fbc183f24c78a4f017
7
- data.tar.gz: 49b1f817299513b9ba693b2b19bb0d23971578c433193e980824046ae9900a69d63207b422f93046d9c68dba14874a9414c8e8039598baf6c478fce8f384cc9f
6
+ metadata.gz: 8a190a8b4d59d7d6f92c95221b238a26bf6df6bf572ad23f63c271875647fac1784c593935a7e0b85a28b122580a4f92e8c0c9945a45424701328bc2603b4388
7
+ data.tar.gz: c3d07094ba6483b6380ecca1c9da357f24ae9a24b47933e6e2de6a538078691337fcc3ee1159af3320d3a8fc23e27b211c7800b5516044bcc72aae76a5743946
@@ -1,13 +1,16 @@
1
1
  name: Tests
2
2
 
3
- on: [push]
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
4
7
 
5
8
  jobs:
6
9
  linter:
7
10
  strategy:
8
11
  fail-fast: false # I understand this is to run on all versions.
9
12
  matrix:
10
- ruby: ['3.3.5']
13
+ ruby: ['4.0']
11
14
 
12
15
  runs-on: ubuntu-latest
13
16
 
@@ -25,10 +28,15 @@ jobs:
25
28
  strategy:
26
29
  fail-fast: false # I understand this is to run on all versions.
27
30
  matrix:
28
- ruby: ['3.3.5']
31
+ ruby: ['4.0']
29
32
 
30
33
  runs-on: ubuntu-latest
31
34
 
35
+ permissions:
36
+ contents: read
37
+ pull-requests: write
38
+ actions: read
39
+
32
40
  steps:
33
41
  - uses: actions/checkout@v3
34
42
 
@@ -37,13 +45,12 @@ jobs:
37
45
  ruby-version: ${{ matrix.ruby }}
38
46
  bundler-cache: true
39
47
 
40
- - run: |
41
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
42
- chmod +x ./cc-test-reporter
48
+ - run: bundle exec rspec
49
+
50
+ - uses: actions/upload-artifact@v4
51
+ with:
52
+ name: coverage-html
53
+ path: coverage/
43
54
 
44
- - run: |
45
- ./cc-test-reporter before-build
46
- bundle exec rspec
47
- ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
48
- env:
49
- CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
55
+ - uses: k1LoW/octocov-action@v1
56
+ if: ${{ !github.event.pull_request.head.repo.fork }}
data/.octocov.yml ADDED
@@ -0,0 +1,18 @@
1
+ coverage:
2
+ paths:
3
+ - coverage/.resultset.json
4
+
5
+ comment:
6
+ if: is_pull_request
7
+
8
+ summary:
9
+ if: is_pull_request
10
+
11
+ report:
12
+ if: is_default_branch
13
+ datastores:
14
+ - artifact://${GITHUB_REPOSITORY}
15
+
16
+ diff:
17
+ datastores:
18
+ - artifact://${GITHUB_REPOSITORY}
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_danfe (2.0.0)
4
+ br_danfe (3.0.0)
5
5
  barby (= 0.6.9)
6
6
  br_documents (>= 0.1.3)
7
7
  i18n (>= 0.8.6)
@@ -14,35 +14,37 @@ GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
16
  Ascii85 (1.1.0)
17
- activemodel (7.1.3)
18
- activesupport (= 7.1.3)
19
- activesupport (7.1.3)
17
+ activemodel (8.1.4.1)
18
+ activesupport (= 8.1.4.1)
19
+ activesupport (8.1.4.1)
20
20
  base64
21
21
  bigdecimal
22
- concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ concurrent-ruby (~> 1.0, >= 1.3.1)
23
23
  connection_pool (>= 2.2.5)
24
24
  drb
25
25
  i18n (>= 1.6, < 2)
26
+ json
27
+ logger (>= 1.4.2)
26
28
  minitest (>= 5.1)
27
- mutex_m
28
- tzinfo (~> 2.0)
29
+ securerandom (>= 0.3)
30
+ tzinfo (~> 2.0, >= 2.0.5)
31
+ uri (>= 0.13.1)
29
32
  afm (0.2.2)
30
33
  ast (2.4.3)
31
34
  barby (0.6.9)
32
- base64 (0.2.0)
33
- bigdecimal (3.1.6)
35
+ base64 (0.3.0)
36
+ bigdecimal (3.3.1)
34
37
  br_documents (0.2.5)
35
38
  activemodel (>= 4.0.0)
36
39
  i18n (>= 0.6.5)
37
40
  byebug (11.1.3)
38
41
  chunky_png (1.4.0)
39
42
  coderay (1.1.3)
40
- concurrent-ruby (1.3.1)
41
- connection_pool (2.4.1)
43
+ concurrent-ruby (1.3.8)
44
+ connection_pool (3.0.3)
42
45
  diff-lcs (1.5.1)
43
46
  docile (1.4.1)
44
- drb (2.2.0)
45
- ruby2_keywords
47
+ drb (2.2.3)
46
48
  ffi (1.17.0)
47
49
  formatador (1.1.0)
48
50
  guard (2.19.0)
@@ -60,7 +62,7 @@ GEM
60
62
  guard-compat (~> 1.1)
61
63
  rspec (>= 2.99.0, < 4.0)
62
64
  hashery (2.1.2)
63
- i18n (1.14.5)
65
+ i18n (1.15.2)
64
66
  concurrent-ruby (~> 1.0)
65
67
  json (2.11.3)
66
68
  language_server-protocol (3.17.0.4)
@@ -68,12 +70,12 @@ GEM
68
70
  listen (3.9.0)
69
71
  rb-fsevent (~> 0.10, >= 0.10.3)
70
72
  rb-inotify (~> 0.9, >= 0.9.10)
73
+ logger (1.7.0)
71
74
  lumberjack (1.2.10)
72
75
  matrix (0.4.2)
73
76
  method_source (1.1.0)
74
77
  mini_portile2 (2.8.7)
75
- minitest (5.21.2)
76
- mutex_m (0.2.0)
78
+ minitest (5.27.0)
77
79
  nenv (0.3.0)
78
80
  nokogiri (1.16.7)
79
81
  mini_portile2 (~> 2.8.2)
@@ -157,7 +159,7 @@ GEM
157
159
  rubocop-factory_bot (~> 2.22)
158
160
  ruby-progressbar (1.13.0)
159
161
  ruby-rc4 (0.1.5)
160
- ruby2_keywords (0.0.5)
162
+ securerandom (0.4.1)
161
163
  shellany (0.0.1)
162
164
  simplecov (0.22.0)
163
165
  docile (~> 1.1)
@@ -170,9 +172,10 @@ GEM
170
172
  bigdecimal (~> 3.1)
171
173
  tzinfo (2.0.6)
172
174
  concurrent-ruby (~> 1.0)
173
- unicode-display_width (3.1.4)
174
- unicode-emoji (~> 4.0, >= 4.0.4)
175
- unicode-emoji (4.0.4)
175
+ unicode-display_width (3.3.0)
176
+ unicode-emoji (~> 4.3)
177
+ unicode-emoji (4.3.0)
178
+ uri (1.1.2)
176
179
 
177
180
  PLATFORMS
178
181
  ruby
@@ -47,7 +47,8 @@ pt-BR:
47
47
  IM: "INSCRIÇÃO MUNICIPAL"
48
48
  IE: "INSCRIÇÃO ESTADUAL"
49
49
  IEST: "INSC.ESTADUAL DO SUBST. TRIBUTÁRIO"
50
- CNPJ: "CNPJ"
50
+ CNPJ: "CNPJ/CPF"
51
+ CPF: "CNPJ/CPF"
51
52
  dup:
52
53
  title: "FATURA / DUPLICATAS"
53
54
  nDup: "NRO"
@@ -146,8 +147,8 @@ pt-BR:
146
147
  document: "NF-e\nN°. %{nNF}\nSÉRIE %{serie}"
147
148
  entrega:
148
149
  title: "INFORMAÇÕES DO LOCAL DE ENTREGA"
149
- CNPJ: "CNPJ"
150
- CPF: "CPF"
150
+ CNPJ: "CNPJ/CPF"
151
+ CPF: "CNPJ/CPF"
151
152
  xNome: "NOME/RAZÃO SOCIAL"
152
153
  xLgr: "ENDEREÇO"
153
154
  nro: "NÚMERO"
@@ -30,7 +30,7 @@ module BrDanfe
30
30
  @pdf.text_box cnpj(@xml['emit/CNPJ']), at: [x_position, @pdf.cursor], height: 9, size: 9, align: :left, overflow: :shrink_to_fit
31
31
  @pdf.move_down 9
32
32
 
33
- @pdf.text_box BrDanfe::DanfeLib::NfceLib::Helper.address(@xml.css('enderEmit')), at: [x_position, @pdf.cursor], height: 20, size: 9, align: :left, overflow: :shrink_to_fit
33
+ @pdf.text_box BrDanfe::Helper.address(@xml.css('enderEmit')), at: [x_position, @pdf.cursor], height: 20, size: 9, align: :left, overflow: :shrink_to_fit
34
34
  @pdf.move_down 20
35
35
  @pdf.render_blank_line if count_name_lines(@xml['emit/xNome']) == one_line
36
36
  end
@@ -39,10 +39,6 @@ module BrDanfe
39
39
  @logo.present? ? 2.2.cm : 0
40
40
  end
41
41
 
42
- def width_box
43
- @logo.present? ? 4.5.cm : 6.7.cm
44
- end
45
-
46
42
  def cnpj(info)
47
43
  cnpj = BrDocuments::CnpjCpf::Cnpj.new info
48
44
  "CNPJ: #{cnpj.valid? ? cnpj.formatted : ''}"
@@ -14,7 +14,7 @@ module BrDanfe
14
14
  render_document
15
15
 
16
16
  @pdf.text @xml['dest/xNome'], options
17
- @pdf.text BrDanfe::DanfeLib::NfceLib::Helper.address(@xml.css('enderDest')), options
17
+ @pdf.text BrDanfe::Helper.address(@xml.css('enderDest')), options
18
18
  else
19
19
  @pdf.text 'CONSUMIDOR NÃO IDENTIFICADO', options
20
20
  end
@@ -34,16 +34,8 @@ module BrDanfe
34
34
  end
35
35
 
36
36
  def render_cnpj_cpf
37
- if @xml['dest/CNPJ'] == ''
38
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'dest.CPF', cpf
39
- else
40
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'dest/CNPJ'
41
- end
42
- end
43
-
44
- def cpf
45
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['dest/CPF'])
46
- cpf.formatted
37
+ xpath = @xml['dest/CNPJ'].present? ? 'dest/CNPJ' : 'dest/CPF'
38
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
47
39
  end
48
40
 
49
41
  def render_line2
@@ -64,12 +64,12 @@ module BrDanfe
64
64
  i18n_lbox(h, w, x, y, i18n, data, options)
65
65
  end
66
66
 
67
- def lcnpj(h, w, x, y, xml, xpath, options = {})
67
+ def lcnpj_cpf(h, w, x, y, xml, xpath, options = {})
68
68
  i18n = xpath.tr('/', '.')
69
-
70
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(xml[xpath])
71
- data = if cnpj.valid?
72
- cnpj.formatted
69
+ document_class = xpath.include?('CNPJ') ? BrDocuments::CnpjCpf::Cnpj : BrDocuments::CnpjCpf::Cpf
70
+ cnpj_cpf = document_class.new(xml[xpath])
71
+ data = if cnpj_cpf.valid?
72
+ cnpj_cpf.formatted
73
73
  else
74
74
  ''
75
75
  end
@@ -108,7 +108,15 @@ module BrDanfe
108
108
 
109
109
  @pdf.lie LINE_HEIGHT, 6.36, 0.75, y_second_line, @xml, 'enderEmit/UF', 'emit/IE'
110
110
  @pdf.lie LINE_HEIGHT, 6.86, 7.11, y_second_line, @xml, 'enderDest/UF', 'emit/IEST'
111
- @pdf.lcnpj LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, 'emit/CNPJ'
111
+ @pdf.lcnpj_cpf LINE_HEIGHT, 6.34, 13.97, y_second_line, @xml, cnpj_cpf
112
+ end
113
+
114
+ def cnpj_cpf
115
+ if @xml['emit/CNPJ'].present?
116
+ 'emit/CNPJ'
117
+ else
118
+ 'emit/CPF'
119
+ end
112
120
  end
113
121
  end
114
122
  end
@@ -39,16 +39,8 @@ module BrDanfe
39
39
  end
40
40
 
41
41
  def render_cnpj_cpf
42
- if @xml['entrega/CNPJ'] == ''
43
- @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'entrega.CPF', cpf
44
- else
45
- @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'entrega/CNPJ'
46
- end
47
- end
48
-
49
- def cpf
50
- cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['entrega/CPF'])
51
- cpf.formatted
42
+ xpath = @xml['entrega/CNPJ'].present? ? 'entrega/CNPJ' : 'entrega/CPF'
43
+ @pdf.lcnpj_cpf LINE_HEIGHT, 4.37, 12.57, @l1, @xml, xpath
52
44
  end
53
45
 
54
46
  def render_line2
@@ -25,7 +25,7 @@ module BrDanfe
25
25
  @pdf.lbox LINE_HEIGHT, 1.78, 12.06, @l1, @xml, 'veicTransp/RNTC'
26
26
  @pdf.i18n_lbox LINE_HEIGHT, 2.29, 13.84, @l1, 'veicTransp.placa', plate
27
27
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l1, @xml, 'veicTransp/UF'
28
- @pdf.lcnpj LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
28
+ @pdf.lcnpj_cpf LINE_HEIGHT, 3.44, 16.89, @l1, @xml, 'transporta/CNPJ'
29
29
  @pdf.lbox LINE_HEIGHT, 8.52, 0.75, @l2, @xml, 'transporta/xEnder'
30
30
  @pdf.lbox LINE_HEIGHT, 6.86, 9.27, @l2, @xml, 'transporta/xMun'
31
31
  @pdf.lbox LINE_HEIGHT, 0.76, 16.13, @l2, @xml, 'transporta/UF'
@@ -37,5 +37,9 @@ module BrDanfe
37
37
  def self.format_cep(cep)
38
38
  cep.sub(/(\d{2})(\d{3})(\d{3})/, '\\1.\\2-\\3')
39
39
  end
40
+
41
+ def self.address(ender_tag)
42
+ "#{ender_tag.css('xLgr').text}, #{ender_tag.css('nro').text}, #{ender_tag.css('xBairro').text}, #{ender_tag.css('xMun').text} - #{ender_tag.css('UF').text}"
43
+ end
40
44
  end
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module BrDanfe
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -112,4 +112,16 @@ describe BrDanfe::CceLib::Document do
112
112
  end
113
113
  end
114
114
  end
115
+
116
+ describe 'delegating unknown methods to the underlying Prawn document' do
117
+ context 'when the underlying document also does not know the method' do
118
+ it 'raises NoMethodError' do
119
+ expect { subject.this_method_does_not_exist }.to raise_error(NoMethodError)
120
+ end
121
+
122
+ it 'does not respond to it' do
123
+ expect(subject.respond_to?(:this_method_does_not_exist)).to be_falsey
124
+ end
125
+ end
126
+ end
115
127
  end
@@ -16,4 +16,16 @@ describe BrDanfe::DanfeLib::NfceLib::ProductList do
16
16
 
17
17
  expect("#{base_dir}document#render.pdf").to have_same_content_of file: output_pdf
18
18
  end
19
+
20
+ describe 'delegating unknown methods to the underlying Prawn document' do
21
+ context 'when the underlying document also does not know the method' do
22
+ it 'raises NoMethodError' do
23
+ expect { subject.this_method_does_not_exist }.to raise_error(NoMethodError)
24
+ end
25
+
26
+ it 'does not respond to it' do
27
+ expect(subject.respond_to?(:this_method_does_not_exist)).to be_falsey
28
+ end
29
+ end
30
+ end
19
31
  end
@@ -114,7 +114,7 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
114
114
  end
115
115
  end
116
116
 
117
- describe '#lcnpj' do
117
+ describe '#lcnpj_cpf' do
118
118
  before do
119
119
  subject.render
120
120
  FileUtils.rm_f(output_pdf)
@@ -138,10 +138,10 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
138
138
  it 'renders a box with a formated CNPJ to the pdf' do
139
139
  expect(File.exist?(output_pdf)).to be_falsey
140
140
 
141
- subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
141
+ subject.lcnpj_cpf 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
142
142
  subject.render_file output_pdf
143
143
 
144
- expect("#{base_dir}document#lcnpj-valid.pdf").to have_same_content_of file: output_pdf
144
+ expect("#{base_dir}document#lcnpj_cpf-valid.pdf").to have_same_content_of file: output_pdf
145
145
  end
146
146
  end
147
147
 
@@ -163,10 +163,10 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
163
163
  it 'renders a blank box to the pdf' do
164
164
  expect(File.exist?(output_pdf)).to be_falsey
165
165
 
166
- subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
166
+ subject.lcnpj_cpf 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
167
167
  subject.render_file output_pdf
168
168
 
169
- expect("#{base_dir}document#lcnpj-invalid.pdf").to have_same_content_of file: output_pdf
169
+ expect("#{base_dir}document#lcnpj_cpf-invalid.pdf").to have_same_content_of file: output_pdf
170
170
  end
171
171
  end
172
172
 
@@ -187,10 +187,22 @@ describe BrDanfe::DanfeLib::NfeLib::Document do
187
187
  it 'renders a blank box to the pdf' do
188
188
  expect(File.exist?(output_pdf)).to be_falsey
189
189
 
190
- subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
190
+ subject.lcnpj_cpf 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
191
191
  subject.render_file output_pdf
192
192
 
193
- expect("#{base_dir}document#lcnpj-blank.pdf").to have_same_content_of file: output_pdf
193
+ expect("#{base_dir}document#lcnpj_cpf-blank.pdf").to have_same_content_of file: output_pdf
194
+ end
195
+ end
196
+ end
197
+
198
+ describe 'delegating unknown methods to the underlying Prawn document' do
199
+ context 'when the underlying document also does not know the method' do
200
+ it 'raises NoMethodError' do
201
+ expect { subject.this_method_does_not_exist }.to raise_error(NoMethodError)
202
+ end
203
+
204
+ it 'does not respond to it' do
205
+ expect(subject.respond_to?(:this_method_does_not_exist)).to be_falsey
194
206
  end
195
207
  end
196
208
  end
@@ -114,5 +114,68 @@ describe BrDanfe::DanfeLib::NfeLib::EmitHeader do
114
114
  end
115
115
  end
116
116
  end
117
+
118
+ context 'when emitter has CPF instead of CNPJ' do
119
+ let(:xml_as_string) do
120
+ <<~XML
121
+ <nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
122
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
123
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
124
+ <ide>
125
+ <tpNF>1</tpNF>
126
+ <nNF>1</nNF>
127
+ <serie>1</serie>
128
+ <natOp>Vendas de producao do estabelecimento</natOp>
129
+ </ide>
130
+ <emit>
131
+ <xNome>Nome do Remetente</xNome>
132
+ <CPF>86893723008</CPF>
133
+ <IE>526926313553</IE>
134
+ <enderEmit>
135
+ <xLgr>Rua do Remetente, Casa</xLgr>
136
+ <nro>123</nro>
137
+ <xBairro>Bairro do Remetente</xBairro>
138
+ <xMun>SAO PAULO</xMun>
139
+ <UF>SP</UF>
140
+ <CEP>12345678</CEP>
141
+ <fone>1112345678</fone>
142
+ <email>foo@bar.com</email>
143
+ </enderEmit>
144
+ </emit>
145
+ <det nItem="1">
146
+ <prod>
147
+ <detExport>
148
+ <exportInd>
149
+ <chNFe>41211285493849000105550020000027171182910239</chNFe>
150
+ </exportInd>
151
+ </detExport>
152
+ </prod>
153
+ </det>
154
+ </infNFe>
155
+ </NFe>
156
+ <protNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
157
+ <infProt Id="ID325110012866320">
158
+ <chNFe>25111012345678901234550020000134151000134151</chNFe>
159
+ <dhRecbto>2011-10-29T14:37:09</dhRecbto>
160
+ <nProt>325110012866320</nProt>
161
+ </infProt>
162
+ </protNFe>
163
+ </nfeProc>
164
+ XML
165
+ end
166
+
167
+ before do
168
+ subject.render 1, 3.96, 1
169
+ FileUtils.rm_f(output_pdf)
170
+ end
171
+
172
+ it 'renders xml with CPF to the pdf' do
173
+ expect(File.exist?(output_pdf)).to be_falsey
174
+
175
+ pdf.render_file output_pdf
176
+
177
+ expect("#{base_dir}emit_header#render-with_cpf.pdf").to have_same_content_of file: output_pdf
178
+ end
179
+ end
117
180
  end
118
181
  end
@@ -225,4 +225,29 @@ describe BrDanfe::Helper do
225
225
  expect(described_class.format_cep('12345678')).to eql '12.345-678'
226
226
  end
227
227
  end
228
+
229
+ describe '.address' do
230
+ let(:xml) do
231
+ xml = <<~XML
232
+ <enderDest>
233
+ <xLgr>Rua Tijucas</xLgr>
234
+ <nro>99</nro>
235
+ <xCpl>dwdwa</xCpl>
236
+ <xBairro>Centro</xBairro>
237
+ <cMun>4218004</cMun>
238
+ <xMun>TIJUCAS</xMun>
239
+ <UF>SC</UF>
240
+ <CEP>88200000</CEP>
241
+ <cPais>1058</cPais>
242
+ <xPais>Brasil</xPais>
243
+ </enderDest>
244
+ XML
245
+
246
+ BrDanfe::XML.new(xml)
247
+ end
248
+
249
+ it 'returns a formated address string' do
250
+ expect(described_class.address(xml)).to eql 'Rua Tijucas, 99, Centro, TIJUCAS - SC'
251
+ end
252
+ end
228
253
  end
@@ -17,7 +17,7 @@ endobj
17
17
  >>
18
18
  endobj
19
19
  4 0 obj
20
- << /Length 11058
20
+ << /Length 11066
21
21
  >>
22
22
  stream
23
23
  q
@@ -677,7 +677,7 @@ S
677
677
  BT
678
678
  398.0 685.49554 Td
679
679
  /F1.0 6 Tf
680
- <434e504a> Tj
680
+ <434e504a2f435046> Tj
681
681
  ET
682
682
 
683
683
 
@@ -1056,24 +1056,24 @@ xref
1056
1056
  0000000109 00000 n
1057
1057
  0000000158 00000 n
1058
1058
  0000000215 00000 n
1059
- 0000011326 00000 n
1060
- 0000011659 00000 n
1061
- 0000011824 00000 n
1062
- 0000011992 00000 n
1063
- 0000014379 00000 n
1064
- 0000014753 00000 n
1065
- 0000026482 00000 n
1066
- 0000026693 00000 n
1067
- 0000027315 00000 n
1068
- 0000027657 00000 n
1069
- 0000049438 00000 n
1070
- 0000049651 00000 n
1071
- 0000050314 00000 n
1059
+ 0000011334 00000 n
1060
+ 0000011667 00000 n
1061
+ 0000011832 00000 n
1062
+ 0000012000 00000 n
1063
+ 0000014387 00000 n
1064
+ 0000014761 00000 n
1065
+ 0000026490 00000 n
1066
+ 0000026701 00000 n
1067
+ 0000027323 00000 n
1068
+ 0000027665 00000 n
1069
+ 0000049446 00000 n
1070
+ 0000049659 00000 n
1071
+ 0000050322 00000 n
1072
1072
  trailer
1073
1073
  << /Info 1 0 R
1074
1074
  /Root 2 0 R
1075
1075
  /Size 18
1076
1076
  >>
1077
1077
  startxref
1078
- 50866
1078
+ 50874
1079
1079
  %%EOF
@@ -17,7 +17,7 @@ endobj
17
17
  >>
18
18
  endobj
19
19
  4 0 obj
20
- << /Length 11058
20
+ << /Length 11066
21
21
  >>
22
22
  stream
23
23
  q
@@ -677,7 +677,7 @@ S
677
677
  BT
678
678
  398.0 685.49554 Td
679
679
  /F1.0 6 Tf
680
- <434e504a> Tj
680
+ <434e504a2f435046> Tj
681
681
  ET
682
682
 
683
683
 
@@ -1056,24 +1056,24 @@ xref
1056
1056
  0000000109 00000 n
1057
1057
  0000000158 00000 n
1058
1058
  0000000215 00000 n
1059
- 0000011326 00000 n
1060
- 0000011659 00000 n
1061
- 0000011824 00000 n
1062
- 0000011992 00000 n
1063
- 0000014379 00000 n
1064
- 0000014753 00000 n
1065
- 0000026482 00000 n
1066
- 0000026693 00000 n
1067
- 0000027315 00000 n
1068
- 0000027657 00000 n
1069
- 0000049438 00000 n
1070
- 0000049651 00000 n
1071
- 0000050314 00000 n
1059
+ 0000011334 00000 n
1060
+ 0000011667 00000 n
1061
+ 0000011832 00000 n
1062
+ 0000012000 00000 n
1063
+ 0000014387 00000 n
1064
+ 0000014761 00000 n
1065
+ 0000026490 00000 n
1066
+ 0000026701 00000 n
1067
+ 0000027323 00000 n
1068
+ 0000027665 00000 n
1069
+ 0000049446 00000 n
1070
+ 0000049659 00000 n
1071
+ 0000050322 00000 n
1072
1072
  trailer
1073
1073
  << /Info 1 0 R
1074
1074
  /Root 2 0 R
1075
1075
  /Size 18
1076
1076
  >>
1077
1077
  startxref
1078
- 50866
1078
+ 50874
1079
1079
  %%EOF