br_danfe 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +113 -0
- data/Gemfile.lock +40 -19
- data/Rakefile +3 -3
- data/br_danfe.gemspec +7 -7
- data/lib/br_danfe.rb +14 -14
- data/lib/br_danfe/cce.rb +1 -0
- data/lib/br_danfe/cce_lib/barcode.rb +3 -2
- data/lib/br_danfe/cce_lib/correction.rb +3 -2
- data/lib/br_danfe/cce_lib/document.rb +15 -5
- data/lib/br_danfe/cce_lib/footer.rb +1 -1
- data/lib/br_danfe/cce_lib/header.rb +1 -1
- data/lib/br_danfe/cce_lib/nfe_key.rb +4 -3
- data/lib/br_danfe/cce_lib/protocol.rb +4 -3
- data/lib/br_danfe/danfe.rb +17 -17
- data/lib/br_danfe/danfe_lib/cep.rb +1 -1
- data/lib/br_danfe/danfe_lib/cst.rb +8 -6
- data/lib/br_danfe/danfe_lib/dest.rb +21 -23
- data/lib/br_danfe/danfe_lib/det_body.rb +20 -20
- data/lib/br_danfe/danfe_lib/document.rb +49 -36
- data/lib/br_danfe/danfe_lib/dup.rb +11 -10
- data/lib/br_danfe/danfe_lib/emit_header.rb +38 -34
- data/lib/br_danfe/danfe_lib/helper.rb +23 -23
- data/lib/br_danfe/danfe_lib/icmstot.rb +12 -12
- data/lib/br_danfe/danfe_lib/infadic.rb +1 -0
- data/lib/br_danfe/danfe_lib/issqn.rb +6 -6
- data/lib/br_danfe/danfe_lib/options.rb +6 -5
- data/lib/br_danfe/danfe_lib/phone.rb +2 -2
- data/lib/br_danfe/danfe_lib/ticket.rb +6 -4
- data/lib/br_danfe/danfe_lib/transp.rb +27 -26
- data/lib/br_danfe/danfe_lib/vol.rb +9 -8
- data/lib/br_danfe/danfe_lib/xml.rb +6 -6
- data/lib/br_danfe/danfe_lib/xprod.rb +22 -23
- data/lib/br_danfe/uf.rb +1 -4
- data/lib/br_danfe/version.rb +1 -1
- data/spec/features/cce_spec.rb +6 -6
- data/spec/features/danfe_spec.rb +25 -25
- data/spec/fixtures/cce/lib/barcode#render.pdf +5 -1
- data/spec/fixtures/cce/lib/correction#render.pdf +6 -2
- data/spec/fixtures/cce/lib/document#box.pdf +5 -1
- data/spec/fixtures/cce/lib/document#box.with.block.pdf +6 -2
- data/spec/fixtures/cce/lib/document#text.align.pdf +6 -2
- data/spec/fixtures/cce/lib/document#text.pad.pdf +6 -2
- data/spec/fixtures/cce/lib/document#text.simple.pdf +6 -2
- data/spec/fixtures/cce/lib/document#text.size.pdf +6 -2
- data/spec/fixtures/cce/lib/document#text.style.pdf +6 -2
- data/spec/fixtures/cce/lib/footer#render.pdf +6 -2
- data/spec/fixtures/cce/lib/header#render.pdf +6 -2
- data/spec/fixtures/cce/lib/nfe_key#render.pdf +7 -3
- data/spec/fixtures/cce/lib/protocol#render.pdf +7 -3
- data/spec/fixtures/cce/v1.00/cce.fixture.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-v2.00.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-v3.10.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-v4.00.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-with-address-bigger.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-with_cnpj.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-with_cpf.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-with_ie.pdf +7 -3
- data/spec/fixtures/nfe/lib/dest#render-without-address-complement.pdf +7 -3
- data/spec/fixtures/nfe/lib/det_body#render-csosn.pdf +383 -379
- data/spec/fixtures/nfe/lib/det_body#render-cst.pdf +233 -229
- data/spec/fixtures/nfe/lib/det_body#render-fci.pdf +158 -154
- data/spec/fixtures/nfe/lib/det_body#render-icms_st.pdf +158 -154
- data/spec/fixtures/nfe/lib/det_body#render-quantity_with_custom_precision.pdf +158 -154
- data/spec/fixtures/nfe/lib/det_body#render-three_pages.pdf +3697 -3685
- data/spec/fixtures/nfe/lib/det_body#render-two_pages.pdf +3540 -3532
- data/spec/fixtures/nfe/lib/det_body#render-unit_price_with_custom_precision.pdf +158 -154
- data/spec/fixtures/nfe/lib/det_body#render-with_infadprod.pdf +158 -154
- data/spec/fixtures/nfe/lib/det_body#render-with_issqn.pdf +1665 -1657
- data/spec/fixtures/nfe/lib/det_body#render-without_issqn.pdf +1665 -1657
- data/spec/fixtures/nfe/lib/document#lcnpj-blank.pdf +6 -2
- data/spec/fixtures/nfe/lib/document#lcnpj-invalid.pdf +6 -2
- data/spec/fixtures/nfe/lib/document#lcnpj-valid.pdf +6 -2
- data/spec/fixtures/nfe/lib/document#lie-blank-uf-invalid.pdf +6 -2
- data/spec/fixtures/nfe/lib/document#lie-blank.pdf +6 -2
- data/spec/fixtures/nfe/lib/document#lie-invalid.pdf +6 -2
- data/spec/fixtures/nfe/lib/document#lie-valid.pdf +6 -2
- data/spec/fixtures/nfe/lib/dup#render.pdf +8 -4
- data/spec/fixtures/nfe/lib/emit_header#render-second_page.pdf +9 -5
- data/spec/fixtures/nfe/lib/emit_header#render-with_logo.pdf +9 -5
- data/spec/fixtures/nfe/lib/emit_header#render-without_logo.pdf +7 -3
- data/spec/fixtures/nfe/lib/icmstot#render.pdf +7 -3
- data/spec/fixtures/nfe/lib/infadic#render-all_the_informations.pdf +8 -4
- data/spec/fixtures/nfe/lib/infadic#render-difal.pdf +7 -3
- data/spec/fixtures/nfe/lib/infadic#render-extra_volume.pdf +8 -4
- data/spec/fixtures/nfe/lib/infadic#render-with_complementary_information.pdf +7 -3
- data/spec/fixtures/nfe/lib/infadic#render-with_fisco_additional_information.pdf +7 -3
- data/spec/fixtures/nfe/lib/infadic#render-with_street_data.pdf +7 -3
- data/spec/fixtures/nfe/lib/infadic#render.pdf +7 -3
- data/spec/fixtures/nfe/lib/infadic_vol#render-extra_volume.pdf +7 -3
- data/spec/fixtures/nfe/lib/issqn#render-with_issqn.pdf +7 -3
- data/spec/fixtures/nfe/lib/issqn#render-with_one_issqn_value.pdf +7 -3
- data/spec/fixtures/nfe/lib/issqn#render-without_issqn.pdf +5 -1
- data/spec/fixtures/nfe/lib/ticket#render.pdf +6 -2
- data/spec/fixtures/nfe/lib/transp#render-modfrete_0.pdf +7 -3
- data/spec/fixtures/nfe/lib/transp#render-modfrete_1.pdf +7 -3
- data/spec/fixtures/nfe/lib/transp#render-modfrete_2.pdf +7 -3
- data/spec/fixtures/nfe/lib/transp#render-modfrete_3.pdf +7 -3
- data/spec/fixtures/nfe/lib/transp#render-modfrete_4.pdf +7 -3
- data/spec/fixtures/nfe/lib/transp#render-modfrete_9.pdf +7 -3
- data/spec/fixtures/nfe/lib/transp#render.pdf +7 -3
- data/spec/fixtures/nfe/lib/vol#render-blank-boxes.pdf +6 -2
- data/spec/fixtures/nfe/lib/vol#render.pdf +6 -2
- data/spec/fixtures/nfe/v2.00/custom_options.fixture.pdf +317 -313
- data/spec/fixtures/nfe/v2.00/nfe_simples_nacional.xml.fixture.pdf +315 -311
- data/spec/fixtures/nfe/v2.00/nfe_with_extra_volumes.xml.fixture.pdf +1297 -1289
- data/spec/fixtures/nfe/v2.00/nfe_with_fci.xml.fixture.pdf +165 -161
- data/spec/fixtures/nfe/v2.00/nfe_with_ns.xml.fixture.pdf +1297 -1289
- data/spec/fixtures/nfe/v2.00/nfe_without_ns.xml.fixture.pdf +314 -310
- data/spec/fixtures/nfe/v3.10/nfe_simples_nacional.xml.fixture.pdf +765 -761
- data/spec/fixtures/nfe/v3.10/with_footer.fixture.pdf +1222 -1214
- data/spec/fixtures/nfe/v3.10/with_issqn.fixture.pdf +1222 -1214
- data/spec/fixtures/nfe/v3.10/with_three_pages.fixture.pdf +4004 -3992
- data/spec/fixtures/nfe/v3.10/without_issqn.fixture.pdf +1522 -1514
- data/spec/lib/cce_lib/barcode_spec.rb +5 -5
- data/spec/lib/cce_lib/correction_spec.rb +5 -5
- data/spec/lib/cce_lib/document_spec.rb +23 -23
- data/spec/lib/cce_lib/footer_spec.rb +4 -4
- data/spec/lib/cce_lib/header_spec.rb +4 -4
- data/spec/lib/cce_lib/nfe_key_spec.rb +5 -5
- data/spec/lib/cce_lib/protocol_spec.rb +5 -5
- data/spec/lib/danfe_lib/cep_spec.rb +5 -5
- data/spec/lib/danfe_lib/cst_spec.rb +8 -8
- data/spec/lib/danfe_lib/dest_spec.rb +23 -23
- data/spec/lib/danfe_lib/det_body_spec.rb +26 -26
- data/spec/lib/danfe_lib/document_spec.rb +25 -25
- data/spec/lib/danfe_lib/dup_spec.rb +4 -4
- data/spec/lib/danfe_lib/emit_header_spec.rb +13 -13
- data/spec/lib/danfe_lib/helper_spec.rb +74 -74
- data/spec/lib/danfe_lib/icmstot_spec.rb +4 -4
- data/spec/lib/danfe_lib/infadic_spec.rb +6 -13
- data/spec/lib/danfe_lib/infadic_vol_spec.rb +1 -4
- data/spec/lib/danfe_lib/issqn_spec.rb +11 -11
- data/spec/lib/danfe_lib/logo_options_spec.rb +18 -18
- data/spec/lib/danfe_lib/options_spec.rb +7 -7
- data/spec/lib/danfe_lib/phone_spec.rb +10 -10
- data/spec/lib/danfe_lib/plate_spec.rb +9 -9
- data/spec/lib/danfe_lib/ticket_spec.rb +4 -4
- data/spec/lib/danfe_lib/transp_spec.rb +10 -10
- data/spec/lib/danfe_lib/vol_spec.rb +7 -7
- data/spec/lib/danfe_lib/xml_spec.rb +5 -5
- data/spec/lib/danfe_lib/xprod_spec.rb +48 -50
- data/spec/lib/uf_spec.rb +12 -12
- data/spec/support/have_same_content_of.rb +6 -6
- metadata +40 -10
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::DetBody do
|
4
|
-
let(:base_dir) {
|
4
|
+
let(:base_dir) { './spec/fixtures/nfe/lib/' }
|
5
5
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
|
7
7
|
let(:pdf) { BrDanfe::DanfeLib::Document.new }
|
@@ -56,13 +56,13 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
56
56
|
|
57
57
|
subject { described_class.new(pdf, xml) }
|
58
58
|
|
59
|
-
describe
|
59
|
+
describe '#render' do
|
60
60
|
before do
|
61
61
|
subject.render has_issqn
|
62
62
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
63
63
|
end
|
64
64
|
|
65
|
-
context
|
65
|
+
context 'with CSOSN' do
|
66
66
|
let(:products) do
|
67
67
|
<<-eos
|
68
68
|
<det nItem="1">
|
@@ -155,7 +155,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
155
155
|
eos
|
156
156
|
end
|
157
157
|
|
158
|
-
it
|
158
|
+
it 'renders xml to the pdf' do
|
159
159
|
expect(File.exist?(output_pdf)).to be_falsey
|
160
160
|
|
161
161
|
pdf.render_file output_pdf
|
@@ -164,7 +164,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
context
|
167
|
+
context 'with CST' do
|
168
168
|
let(:products) do
|
169
169
|
<<-eos
|
170
170
|
<det nItem="1">
|
@@ -242,7 +242,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
242
242
|
eos
|
243
243
|
end
|
244
244
|
|
245
|
-
it
|
245
|
+
it 'renders xml to the pdf' do
|
246
246
|
expect(File.exist?(output_pdf)).to be_falsey
|
247
247
|
|
248
248
|
pdf.render_file output_pdf
|
@@ -251,7 +251,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
254
|
-
context
|
254
|
+
context 'with FCI' do
|
255
255
|
let(:products) do
|
256
256
|
<<-eos
|
257
257
|
<det nItem="1">
|
@@ -279,7 +279,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
279
279
|
eos
|
280
280
|
end
|
281
281
|
|
282
|
-
it
|
282
|
+
it 'renders xml to the pdf' do
|
283
283
|
expect(File.exist?(output_pdf)).to be_falsey
|
284
284
|
|
285
285
|
pdf.render_file output_pdf
|
@@ -288,7 +288,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
|
-
context
|
291
|
+
context 'with ICMS ST' do
|
292
292
|
let(:products) do
|
293
293
|
<<-eos
|
294
294
|
<det nItem="1">
|
@@ -318,7 +318,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
318
318
|
eos
|
319
319
|
end
|
320
320
|
|
321
|
-
it
|
321
|
+
it 'renders xml to the pdf' do
|
322
322
|
expect(File.exist?(output_pdf)).to be_falsey
|
323
323
|
|
324
324
|
pdf.render_file output_pdf
|
@@ -327,7 +327,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
327
327
|
end
|
328
328
|
end
|
329
329
|
|
330
|
-
context
|
330
|
+
context 'when the unit price of the product has a custom precision' do
|
331
331
|
let(:products) do
|
332
332
|
<<-eos
|
333
333
|
<det nItem="1">
|
@@ -345,7 +345,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
345
345
|
eos
|
346
346
|
end
|
347
347
|
|
348
|
-
it
|
348
|
+
it 'renders xml to the pdf' do
|
349
349
|
expect(File.exist?(output_pdf)).to be_falsey
|
350
350
|
|
351
351
|
pdf.render_file output_pdf
|
@@ -354,7 +354,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
354
354
|
end
|
355
355
|
end
|
356
356
|
|
357
|
-
context
|
357
|
+
context 'when the quantity of the product has a custom precision' do
|
358
358
|
let(:products) do
|
359
359
|
<<-eos
|
360
360
|
<det nItem="1">
|
@@ -372,7 +372,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
372
372
|
eos
|
373
373
|
end
|
374
374
|
|
375
|
-
it
|
375
|
+
it 'renders xml to the pdf' do
|
376
376
|
expect(File.exist?(output_pdf)).to be_falsey
|
377
377
|
|
378
378
|
pdf.render_file output_pdf
|
@@ -381,11 +381,11 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
384
|
-
context
|
384
|
+
context 'when there is ISSQN' do
|
385
385
|
let(:has_issqn) { true }
|
386
386
|
let(:products) { "#{product_1}\n#{product_2}" * 10 }
|
387
387
|
|
388
|
-
it
|
388
|
+
it 'renders xml to the pdf' do
|
389
389
|
expect(File.exist?(output_pdf)).to be_falsey
|
390
390
|
|
391
391
|
pdf.render_file output_pdf
|
@@ -397,7 +397,7 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
397
397
|
context "when there isn't ISSQN" do
|
398
398
|
let(:products) { "#{product_1}\n#{product_2}" * 10 }
|
399
399
|
|
400
|
-
it
|
400
|
+
it 'renders xml to the pdf' do
|
401
401
|
expect(File.exist?(output_pdf)).to be_falsey
|
402
402
|
|
403
403
|
pdf.render_file output_pdf
|
@@ -406,10 +406,10 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
406
406
|
end
|
407
407
|
end
|
408
408
|
|
409
|
-
context
|
410
|
-
let(:products) {
|
409
|
+
context 'with infAdProd' do
|
410
|
+
let(:products) { product_2.to_s }
|
411
411
|
|
412
|
-
it
|
412
|
+
it 'renders xml to the pdf' do
|
413
413
|
expect(File.exist?(output_pdf)).to be_falsey
|
414
414
|
|
415
415
|
pdf.render_file output_pdf
|
@@ -418,11 +418,11 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
418
418
|
end
|
419
419
|
end
|
420
420
|
|
421
|
-
context
|
422
|
-
context
|
421
|
+
context 'when the product table occupies more than one page' do
|
422
|
+
context 'when the product table occupies two pages' do
|
423
423
|
let(:products) { ("#{product_1}\n#{product_2}" * 22) + "\n#{product_1}" }
|
424
424
|
|
425
|
-
it
|
425
|
+
it 'renders xml to the pdf' do
|
426
426
|
expect(File.exist?(output_pdf)).to be_falsey
|
427
427
|
|
428
428
|
pdf.render_file output_pdf
|
@@ -431,10 +431,10 @@ describe BrDanfe::DanfeLib::DetBody do
|
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
434
|
-
context
|
434
|
+
context 'when the product table occupies three pages' do
|
435
435
|
let(:products) { ("#{product_1}\n#{product_2}" * 23) }
|
436
436
|
|
437
|
-
it
|
437
|
+
it 'renders xml to the pdf' do
|
438
438
|
expect(File.exist?(output_pdf)).to be_falsey
|
439
439
|
|
440
440
|
pdf.render_file output_pdf
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::Document do
|
4
|
-
let(:base_dir) {
|
4
|
+
let(:base_dir) { './spec/fixtures/nfe/lib/' }
|
5
5
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
|
7
7
|
let(:xml) { BrDanfe::DanfeLib::XML.new(xml_as_string) }
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe '#lie' do
|
10
10
|
before do
|
11
11
|
subject.render
|
12
12
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
13
13
|
end
|
14
14
|
|
15
|
-
context
|
15
|
+
context 'when IE is valid' do
|
16
16
|
let(:xml_as_string) do
|
17
17
|
<<-eos
|
18
18
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -28,17 +28,17 @@ describe BrDanfe::DanfeLib::Document do
|
|
28
28
|
eos
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'renders a box with a formated IE to the pdf' do
|
32
32
|
expect(File.exist?(output_pdf)).to be_falsey
|
33
33
|
|
34
|
-
subject.lie 0.80, 3.94, 0.75, 1.85, xml,
|
34
|
+
subject.lie 0.80, 3.94, 0.75, 1.85, xml, 'transporta/UF', 'transporta/IE'
|
35
35
|
subject.render_file output_pdf
|
36
36
|
|
37
37
|
expect("#{base_dir}document#lie-valid.pdf").to have_same_content_of file: output_pdf
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
41
|
+
context 'when IE is invalid' do
|
42
42
|
let(:xml_as_string) do
|
43
43
|
<<-eos
|
44
44
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -54,17 +54,17 @@ describe BrDanfe::DanfeLib::Document do
|
|
54
54
|
eos
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'renders a blank box to the pdf' do
|
58
58
|
expect(File.exist?(output_pdf)).to be_falsey
|
59
59
|
|
60
|
-
subject.lie 0.80, 3.94, 0.75, 1.85, xml,
|
60
|
+
subject.lie 0.80, 3.94, 0.75, 1.85, xml, 'transporta/UF', 'transporta/IE'
|
61
61
|
subject.render_file output_pdf
|
62
62
|
|
63
63
|
expect("#{base_dir}document#lie-invalid.pdf").to have_same_content_of file: output_pdf
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
context
|
67
|
+
context 'when IE is blank' do
|
68
68
|
let(:xml_as_string) do
|
69
69
|
<<-eos
|
70
70
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -78,16 +78,16 @@ describe BrDanfe::DanfeLib::Document do
|
|
78
78
|
eos
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it 'renders a blank box to the pdf' do
|
82
82
|
expect(File.exist?(output_pdf)).to be_falsey
|
83
83
|
|
84
|
-
subject.lie 0.80, 3.94, 0.75, 1.85, xml,
|
84
|
+
subject.lie 0.80, 3.94, 0.75, 1.85, xml, 'transporta/UF', 'transporta/IE'
|
85
85
|
subject.render_file output_pdf
|
86
86
|
|
87
87
|
expect("#{base_dir}document#lie-blank.pdf").to have_same_content_of file: output_pdf
|
88
88
|
end
|
89
89
|
|
90
|
-
context
|
90
|
+
context 'when UF is invalid' do
|
91
91
|
let(:xml_as_string) do
|
92
92
|
<<-eos
|
93
93
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -102,10 +102,10 @@ describe BrDanfe::DanfeLib::Document do
|
|
102
102
|
eos
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'renders a blank box to the pdf' do
|
106
106
|
expect(File.exist?(output_pdf)).to be_falsey
|
107
107
|
|
108
|
-
subject.lie 0.80, 3.94, 0.75, 1.85, xml,
|
108
|
+
subject.lie 0.80, 3.94, 0.75, 1.85, xml, 'transporta/UF', 'transporta/IE'
|
109
109
|
subject.render_file output_pdf
|
110
110
|
|
111
111
|
expect("#{base_dir}document#lie-blank-uf-invalid.pdf").to have_same_content_of file: output_pdf
|
@@ -114,13 +114,13 @@ describe BrDanfe::DanfeLib::Document do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
describe
|
117
|
+
describe '#lcnpj' do
|
118
118
|
before do
|
119
119
|
subject.render
|
120
120
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
121
121
|
end
|
122
122
|
|
123
|
-
context
|
123
|
+
context 'when CNPJ is valid' do
|
124
124
|
let(:xml_as_string) do
|
125
125
|
<<-eos
|
126
126
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -135,17 +135,17 @@ describe BrDanfe::DanfeLib::Document do
|
|
135
135
|
eos
|
136
136
|
end
|
137
137
|
|
138
|
-
it
|
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,
|
141
|
+
subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
|
142
142
|
subject.render_file output_pdf
|
143
143
|
|
144
144
|
expect("#{base_dir}document#lcnpj-valid.pdf").to have_same_content_of file: output_pdf
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
context
|
148
|
+
context 'when CNPJ is invalid' do
|
149
149
|
let(:xml_as_string) do
|
150
150
|
<<-eos
|
151
151
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -160,17 +160,17 @@ describe BrDanfe::DanfeLib::Document do
|
|
160
160
|
eos
|
161
161
|
end
|
162
162
|
|
163
|
-
it
|
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,
|
166
|
+
subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
|
167
167
|
subject.render_file output_pdf
|
168
168
|
|
169
169
|
expect("#{base_dir}document#lcnpj-invalid.pdf").to have_same_content_of file: output_pdf
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
context
|
173
|
+
context 'when CNPJ is blank' do
|
174
174
|
let(:xml_as_string) do
|
175
175
|
<<-eos
|
176
176
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -184,10 +184,10 @@ describe BrDanfe::DanfeLib::Document do
|
|
184
184
|
eos
|
185
185
|
end
|
186
186
|
|
187
|
-
it
|
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,
|
190
|
+
subject.lcnpj 0.80, 3.94, 0.75, 1.85, xml, 'transporta/CNPJ'
|
191
191
|
subject.render_file output_pdf
|
192
192
|
|
193
193
|
expect("#{base_dir}document#lcnpj-blank.pdf").to have_same_content_of file: output_pdf
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::Dup do
|
4
|
-
let(:base_dir) {
|
4
|
+
let(:base_dir) { './spec/fixtures/nfe/lib/' }
|
5
5
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
|
7
7
|
let(:pdf) { BrDanfe::DanfeLib::Document.new }
|
@@ -9,7 +9,7 @@ describe BrDanfe::DanfeLib::Dup do
|
|
9
9
|
|
10
10
|
subject { described_class.new(pdf, xml) }
|
11
11
|
|
12
|
-
describe
|
12
|
+
describe '#render' do
|
13
13
|
let(:xml_as_string) do
|
14
14
|
<<-eos
|
15
15
|
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
|
@@ -41,7 +41,7 @@ describe BrDanfe::DanfeLib::Dup do
|
|
41
41
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'renders xml to the pdf' do
|
45
45
|
expect(File.exist?(output_pdf)).to be_falsey
|
46
46
|
|
47
47
|
pdf.render_file output_pdf
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::EmitHeader do
|
4
|
-
let(:base_dir) {
|
4
|
+
let(:base_dir) { './spec/fixtures/nfe/lib/' }
|
5
5
|
let(:output_pdf) { "#{base_dir}output.pdf" }
|
6
6
|
|
7
7
|
let(:pdf) { BrDanfe::DanfeLib::Document.new }
|
8
8
|
let(:xml) { BrDanfe::DanfeLib::XML.new(xml_as_string) }
|
9
|
-
let(:logo) {
|
9
|
+
let(:logo) { 'spec/fixtures/logo.png' }
|
10
10
|
|
11
11
|
subject { described_class.new(pdf, xml, logo, { width: 100, height: 100 }) }
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe '#render' do
|
14
14
|
let(:xml_as_string) do
|
15
15
|
<<-eos
|
16
16
|
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00">
|
@@ -51,14 +51,14 @@ describe BrDanfe::DanfeLib::EmitHeader do
|
|
51
51
|
eos
|
52
52
|
end
|
53
53
|
|
54
|
-
context
|
54
|
+
context 'render emitter on first page' do
|
55
55
|
before do
|
56
56
|
subject.render 1, 3.96
|
57
57
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
58
58
|
end
|
59
59
|
|
60
|
-
context
|
61
|
-
it
|
60
|
+
context 'with logo' do
|
61
|
+
it 'renders xml to the pdf' do
|
62
62
|
expect(File.exist?(output_pdf)).to be_falsey
|
63
63
|
|
64
64
|
pdf.render_file output_pdf
|
@@ -67,10 +67,10 @@ describe BrDanfe::DanfeLib::EmitHeader do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context
|
71
|
-
let(:logo) {
|
70
|
+
context 'without logo' do
|
71
|
+
let(:logo) { '' }
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'renders xml to the pdf' do
|
74
74
|
expect(File.exist?(output_pdf)).to be_falsey
|
75
75
|
|
76
76
|
pdf.render_file output_pdf
|
@@ -80,14 +80,14 @@ describe BrDanfe::DanfeLib::EmitHeader do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
context
|
83
|
+
context 'render emitter on second page' do
|
84
84
|
before do
|
85
85
|
subject.render 2, 1.85
|
86
86
|
File.delete(output_pdf) if File.exist?(output_pdf)
|
87
87
|
end
|
88
88
|
|
89
|
-
context
|
90
|
-
it
|
89
|
+
context 'with logo' do
|
90
|
+
it 'renders xml to the pdf' do
|
91
91
|
expect(File.exist?(output_pdf)).to be_falsey
|
92
92
|
|
93
93
|
pdf.render_file output_pdf
|
@@ -1,100 +1,100 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BrDanfe::DanfeLib::Helper do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(0.123)).to eq
|
7
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(0.1234)).to eq
|
8
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(0.12345)).to eq
|
9
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(0.1234567891)).to eq
|
4
|
+
describe '.numerify' do
|
5
|
+
it 'formats with the decimals' do
|
6
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(0.123)).to eq '0,123'
|
7
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(0.1234)).to eq '0,1234'
|
8
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(0.12345)).to eq '0,12345'
|
9
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(0.1234567891)).to eq '0,1234567891'
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(100)).to eq
|
12
|
+
it 'formats integers' do
|
13
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(100)).to eq '100,00'
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(123.45)).to eq
|
16
|
+
it 'formats decimals' do
|
17
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(123.45)).to eq '123,45'
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(1000)).to eq
|
20
|
+
it 'formats thousands' do
|
21
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(1000)).to eq '1.000,00'
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(
|
24
|
+
it 'formats millions' do
|
25
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(1_000_000)).to eq '1.000.000,00'
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
29
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(123.4)).to eq
|
28
|
+
it 'formats using two as min decimal precision' do
|
29
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(123.4)).to eq '123,40'
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(0)).to eq
|
32
|
+
it 'formats 0 to 0,00' do
|
33
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(0)).to eq '0,00'
|
34
34
|
end
|
35
35
|
|
36
36
|
it "doesn't format nil value" do
|
37
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(nil)).to eq
|
37
|
+
expect(BrDanfe::DanfeLib::Helper.numerify(nil)).to eq ''
|
38
38
|
end
|
39
39
|
|
40
40
|
it "doesn't format blank value" do
|
41
|
-
expect(BrDanfe::DanfeLib::Helper.numerify(
|
41
|
+
expect(BrDanfe::DanfeLib::Helper.numerify('')).to eq ''
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
46
|
-
it
|
47
|
-
string =
|
48
|
-
expect(BrDanfe::DanfeLib::Helper.format_datetime(string)).to eq
|
45
|
+
describe '.format_datetime' do
|
46
|
+
it 'returns a formated string' do
|
47
|
+
string = '2013-10-18T13:54:04'
|
48
|
+
expect(BrDanfe::DanfeLib::Helper.format_datetime(string)).to eq '18/10/2013 13:54:04'
|
49
49
|
end
|
50
50
|
|
51
|
-
describe
|
52
|
-
it
|
53
|
-
expect(BrDanfe::DanfeLib::Helper.format_datetime(
|
51
|
+
describe 'when the source is blank' do
|
52
|
+
it 'is empty' do
|
53
|
+
expect(BrDanfe::DanfeLib::Helper.format_datetime('')).to eq ''
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe
|
59
|
-
it
|
60
|
-
string =
|
61
|
-
expect(BrDanfe::DanfeLib::Helper.format_date(string)).to eq
|
58
|
+
describe '.format_date' do
|
59
|
+
it 'returns a formated string' do
|
60
|
+
string = '2013-10-18T13:54:04'
|
61
|
+
expect(BrDanfe::DanfeLib::Helper.format_date(string)).to eq '18/10/2013'
|
62
62
|
end
|
63
63
|
|
64
|
-
describe
|
65
|
-
it
|
66
|
-
expect(BrDanfe::DanfeLib::Helper.format_date(
|
64
|
+
describe 'when the source is blank' do
|
65
|
+
it 'is empty' do
|
66
|
+
expect(BrDanfe::DanfeLib::Helper.format_date('')).to eq ''
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
72
|
-
describe
|
73
|
-
let(:param) {
|
71
|
+
describe '.format_time' do
|
72
|
+
describe 'when param is a complete datetime' do
|
73
|
+
let(:param) { '2013-10-18T16:54:04-03:00' }
|
74
74
|
|
75
|
-
it
|
76
|
-
expect(BrDanfe::DanfeLib::Helper.format_time(param)).to eq
|
75
|
+
it 'is a formated time string in localtime' do
|
76
|
+
expect(BrDanfe::DanfeLib::Helper.format_time(param)).to eq '16:54:04'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe
|
81
|
-
let(:param) {
|
80
|
+
describe 'when param is only a time' do
|
81
|
+
let(:param) { '14:23:02' }
|
82
82
|
|
83
|
-
it
|
84
|
-
expect(BrDanfe::DanfeLib::Helper.format_time(param)).to eq
|
83
|
+
it 'is a formated time string' do
|
84
|
+
expect(BrDanfe::DanfeLib::Helper.format_time(param)).to eq '14:23:02'
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
89
|
-
let(:param) {
|
88
|
+
describe 'when param is blank' do
|
89
|
+
let(:param) { '' }
|
90
90
|
|
91
|
-
it
|
92
|
-
expect(BrDanfe::DanfeLib::Helper.format_time(param)).to eq
|
91
|
+
it 'is empty' do
|
92
|
+
expect(BrDanfe::DanfeLib::Helper.format_time(param)).to eq ''
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
describe
|
97
|
+
describe '.no_fiscal_value?' do
|
98
98
|
let(:xml_homologation) do
|
99
99
|
xml = <<-eos
|
100
100
|
<nfeProc>
|
@@ -149,46 +149,46 @@ describe BrDanfe::DanfeLib::Helper do
|
|
149
149
|
Nokogiri::XML(xml)
|
150
150
|
end
|
151
151
|
|
152
|
-
context
|
153
|
-
it
|
154
|
-
expect(BrDanfe::DanfeLib::Helper.
|
152
|
+
context 'when XML is unauthorized' do
|
153
|
+
it 'returns true' do
|
154
|
+
expect(BrDanfe::DanfeLib::Helper.no_fiscal_value?(xml_unauthorized)).to eq true
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
context
|
159
|
-
it
|
160
|
-
expect(BrDanfe::DanfeLib::Helper.
|
158
|
+
context 'when XML is in homologation environment' do
|
159
|
+
it 'returns true' do
|
160
|
+
expect(BrDanfe::DanfeLib::Helper.no_fiscal_value?(xml_homologation)).to eq true
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
context
|
165
|
-
it
|
166
|
-
expect(BrDanfe::DanfeLib::Helper.
|
164
|
+
context 'when XML is authorized' do
|
165
|
+
it 'returns false' do
|
166
|
+
expect(BrDanfe::DanfeLib::Helper.no_fiscal_value?(xml_authorized)).to eq false
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
-
describe
|
171
|
+
describe '.address_is_too_big' do
|
172
172
|
let(:pdf) { BrDanfe::DanfeLib::Document.new }
|
173
173
|
|
174
|
-
context
|
175
|
-
let(:address) {
|
174
|
+
context 'when the address is too big for the street field at DANFE' do
|
175
|
+
let(:address) { 'Rua do governo do estado 1125 - Em anexo ao super mercado maior do bairro' }
|
176
176
|
|
177
|
-
it
|
177
|
+
it 'returns true' do
|
178
178
|
expect(BrDanfe::DanfeLib::Helper.address_is_too_big(pdf, address)).to be true
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
context
|
183
|
-
let(:address) {
|
182
|
+
context 'when the address fits in the street field in DANFE' do
|
183
|
+
let(:address) { 'Rua do governo do estado 1125 - Salas 1 e 2' }
|
184
184
|
|
185
|
-
it
|
185
|
+
it 'returns false' do
|
186
186
|
expect(BrDanfe::DanfeLib::Helper.address_is_too_big(pdf, address)).to be false
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
describe
|
191
|
+
describe '.generate_address' do
|
192
192
|
let(:xml) do
|
193
193
|
<<-eos
|
194
194
|
<enderDest>
|
@@ -203,9 +203,9 @@ describe BrDanfe::DanfeLib::Helper do
|
|
203
203
|
Nokogiri::XML(xml)
|
204
204
|
end
|
205
205
|
|
206
|
-
it
|
206
|
+
it 'returns the address with the street, number and complement' do
|
207
207
|
expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
|
208
|
-
.to eq
|
208
|
+
.to eq 'Rua do governo do estado 1125 - Em anexo ao super mercado maior do bairro'
|
209
209
|
end
|
210
210
|
|
211
211
|
context "when recipient address hasn't complement" do
|
@@ -219,9 +219,9 @@ describe BrDanfe::DanfeLib::Helper do
|
|
219
219
|
eos
|
220
220
|
end
|
221
221
|
|
222
|
-
it
|
222
|
+
it 'returns the address with the street and number' do
|
223
223
|
expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
|
224
|
-
.to eq
|
224
|
+
.to eq 'Rua do governo do estado 1125'
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
@@ -236,9 +236,9 @@ describe BrDanfe::DanfeLib::Helper do
|
|
236
236
|
eos
|
237
237
|
end
|
238
238
|
|
239
|
-
it
|
239
|
+
it 'returns the address with the street only' do
|
240
240
|
expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
|
241
|
-
.to eq
|
241
|
+
.to eq 'Rua do governo do estado'
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
@@ -253,9 +253,9 @@ describe BrDanfe::DanfeLib::Helper do
|
|
253
253
|
eos
|
254
254
|
end
|
255
255
|
|
256
|
-
it
|
256
|
+
it 'returns the address with the street and complement' do
|
257
257
|
expect(BrDanfe::DanfeLib::Helper.generate_address(xml_street))
|
258
|
-
.to eq
|
258
|
+
.to eq 'Rua do governo do estado - Em anexo ao super mercado maior do bairro'
|
259
259
|
end
|
260
260
|
end
|
261
261
|
end
|