br_danfe 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -0
  3. data/lib/br_danfe/dest.rb +10 -2
  4. data/lib/br_danfe/document.rb +10 -2
  5. data/lib/br_danfe/emit.rb +1 -1
  6. data/lib/br_danfe/helper.rb +30 -6
  7. data/lib/br_danfe/version.rb +1 -1
  8. data/lib/br_danfe/xml.rb +4 -0
  9. data/spec/features/br_danfe_spec.rb +111 -81
  10. data/spec/fixtures/lib/dest.pdf +279 -0
  11. data/spec/fixtures/{nfe_simples_nacional.xml → v2.00/nfe_simples_nacional.xml} +0 -0
  12. data/spec/fixtures/{nfe_simples_nacional.xml.fixture.pdf → v2.00/nfe_simples_nacional.xml.fixture.pdf} +4 -18
  13. data/spec/fixtures/{nfe_with_cpf.xml → v2.00/nfe_with_cpf.xml} +0 -0
  14. data/spec/fixtures/{nfe_with_cpf.xml.fixture.pdf → v2.00/nfe_with_cpf.xml.fixture.pdf} +4 -18
  15. data/spec/fixtures/{nfe_with_extra_volumes.xml → v2.00/nfe_with_extra_volumes.xml} +0 -0
  16. data/spec/fixtures/{nfe_with_extra_volumes.xml.fixture.pdf → v2.00/nfe_with_extra_volumes.xml.fixture.pdf} +6 -13
  17. data/spec/fixtures/{nfe_with_fci.xml → v2.00/nfe_with_fci.xml} +0 -0
  18. data/spec/fixtures/{nfe_with_fci.xml.fixture.pdf → v2.00/nfe_with_fci.xml.fixture.pdf} +4 -18
  19. data/spec/fixtures/{nfe_with_logo.xml → v2.00/nfe_with_logo.xml} +0 -0
  20. data/spec/fixtures/{nfe_with_logo.xml.fixture.pdf → v2.00/nfe_with_logo.xml.fixture.pdf} +6 -20
  21. data/spec/fixtures/{nfe_with_logo.xml.logo.png → v2.00/nfe_with_logo.xml.logo.png} +0 -0
  22. data/spec/fixtures/{nfe_with_ns.xml → v2.00/nfe_with_ns.xml} +0 -0
  23. data/spec/fixtures/{nfe_with_ns.xml.fixture.pdf → v2.00/nfe_with_ns.xml.fixture.pdf} +6 -13
  24. data/spec/fixtures/{nfe_without_ns.xml → v2.00/nfe_without_ns.xml} +0 -0
  25. data/spec/fixtures/{nfe_without_ns.xml.fixture.pdf → v2.00/nfe_without_ns.xml.fixture.pdf} +4 -18
  26. data/spec/fixtures/v3.10/nfe_simples_nacional.xml +1 -0
  27. data/spec/fixtures/v3.10/nfe_simples_nacional.xml.fixture.pdf +2619 -0
  28. data/spec/lib/dest_spec.rb +99 -0
  29. data/spec/lib/helper_spec.rb +46 -1
  30. data/spec/lib/xml_spec.rb +37 -0
  31. metadata +42 -32
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe BrDanfe::Dest do
4
+ let(:base_dir) { "./spec/fixtures/lib/"}
5
+ let(:output_pdf) { "#{base_dir}output.pdf" }
6
+
7
+ let(:pdf) { BrDanfe::Document.new }
8
+ let(:xml) { BrDanfe::XML.new(xml_as_string) }
9
+
10
+ subject { described_class.new(pdf, xml) }
11
+
12
+ describe "#render" do
13
+ before do
14
+ subject.render
15
+ File.delete(output_pdf) if File.exist?(output_pdf)
16
+ end
17
+
18
+ context "when nf-e's version is 2.00" do
19
+ let(:xml_as_string) do
20
+ <<-eos
21
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
22
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="2.00">
23
+ <ide>
24
+ <dEmi>2011-10-29</dEmi>
25
+ <dSaiEnt>2011-10-30</dSaiEnt>
26
+ <hSaiEnt>15:32:45</hSaiEnt>
27
+ </ide>
28
+ <dest>
29
+ <CNPJ>82743287000880</CNPJ>
30
+ <xNome>Schneider Electric Brasil Ltda</xNome>
31
+ <enderDest>
32
+ <xLgr>Av da Saudade</xLgr>
33
+ <nro>1125</nro>
34
+ <xBairro>Frutal</xBairro>
35
+ <cMun>3552403</cMun>
36
+ <xMun>SUMARE</xMun>
37
+ <UF>SP</UF>
38
+ <CEP>13171320</CEP>
39
+ <cPais>1058</cPais>
40
+ <xPais>BRASIL</xPais>
41
+ <fone>1921046300</fone>
42
+ </enderDest>
43
+ <IE>671008375110</IE>
44
+ </dest>
45
+ </infNFe>
46
+ </NFe>
47
+ eos
48
+ end
49
+
50
+ it "renders xml to the pdf" do
51
+ expect(File.exist?(output_pdf)).to be_falsey
52
+
53
+ pdf.render_file output_pdf
54
+
55
+ expect("#{base_dir}dest.pdf").to be_same_file_as(output_pdf)
56
+ end
57
+ end
58
+
59
+ context "when nf-e's version is 3.10" do
60
+ let(:xml_as_string) do
61
+ <<-eos
62
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
63
+ <infNFe Id="NFe25111012345678901234550020000134151000134151" versao="3.10">
64
+ <ide>
65
+ <dEmi>2011-10-29</dEmi>
66
+ <dhSaiEnt>2011-10-30T12:32:45-03:00</dhSaiEnt>
67
+ </ide>
68
+ <dest>
69
+ <CNPJ>82743287000880</CNPJ>
70
+ <xNome>Schneider Electric Brasil Ltda</xNome>
71
+ <enderDest>
72
+ <xLgr>Av da Saudade</xLgr>
73
+ <nro>1125</nro>
74
+ <xBairro>Frutal</xBairro>
75
+ <cMun>3552403</cMun>
76
+ <xMun>SUMARE</xMun>
77
+ <UF>SP</UF>
78
+ <CEP>13171320</CEP>
79
+ <cPais>1058</cPais>
80
+ <xPais>BRASIL</xPais>
81
+ <fone>1921046300</fone>
82
+ </enderDest>
83
+ <IE>671008375110</IE>
84
+ </dest>
85
+ </infNFe>
86
+ </NFe>
87
+ eos
88
+ end
89
+
90
+ it "renders xml to the pdf" do
91
+ expect(File.exist?(output_pdf)).to be_falsey
92
+
93
+ pdf.render_file output_pdf
94
+
95
+ expect("#{base_dir}dest.pdf").to be_same_file_as(output_pdf)
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,10 +1,55 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe BrDanfe::Helper do
4
+ describe ".format_datetime" do
5
+ it "returns a formated string" do
6
+ string = "2013-10-18T13:54:04"
7
+ expect(BrDanfe::Helper.format_datetime(string)).to eq "18/10/2013 13:54:04"
8
+ end
9
+
10
+ describe "when the source is blank" do
11
+ it "is empty" do
12
+ expect(BrDanfe::Helper.format_datetime("")).to eq ""
13
+ end
14
+ end
15
+ end
16
+
4
17
  describe ".format_date" do
5
18
  it "returns a formated string" do
6
19
  string = "2013-10-18T13:54:04"
7
- expect(BrDanfe::Helper.format_date(string)).to eq "18/10/2013 13:54:04"
20
+ expect(BrDanfe::Helper.format_date(string)).to eq "18/10/2013"
21
+ end
22
+
23
+ describe "when the source is blank" do
24
+ it "is empty" do
25
+ expect(BrDanfe::Helper.format_date("")).to eq ""
26
+ end
27
+ end
28
+ end
29
+
30
+ describe ".format_time" do
31
+ describe "when param is a complete datetime" do
32
+ let(:param) { "2013-10-18T16:54:04-03:00" }
33
+
34
+ it "is a formated time string in UTC" do
35
+ expect(BrDanfe::Helper.format_time(param)).to eq "19:54:04"
36
+ end
37
+ end
38
+
39
+ describe "when param is only a time" do
40
+ let(:param) { "14:23:02" }
41
+
42
+ it "is a formated time string" do
43
+ expect(BrDanfe::Helper.format_time(param)).to eq "14:23:02"
44
+ end
45
+ end
46
+
47
+ describe "when param is blank" do
48
+ let(:param) { "" }
49
+
50
+ it "is empty" do
51
+ expect(BrDanfe::Helper.format_time(param)).to eq ""
52
+ end
8
53
  end
9
54
  end
10
55
 
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe BrDanfe::XML do
4
+ subject { BrDanfe::XML.new(xml_as_string) }
5
+
6
+ describe "#version_310?" do
7
+ describe "when xml's version is 3.10" do
8
+ let(:xml_as_string) do
9
+ <<-eos
10
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
11
+ <infNFe versao="3.10" Id="NFe35150162013294000143550010000000011000000017">
12
+ </infNFe>
13
+ </NFe>
14
+ eos
15
+ end
16
+
17
+ it "is true" do
18
+ expect(subject.version_310?).to be_truthy
19
+ end
20
+ end
21
+
22
+ describe "when xml's version isn't 3.10" do
23
+ let(:xml_as_string) do
24
+ <<-eos
25
+ <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
26
+ <infNFe versao="2.00" Id="NFe35131260891033000109550010000000011000000016">
27
+ </infNFe>
28
+ </NFe>
29
+ eos
30
+ end
31
+
32
+ it "is false" do
33
+ expect(subject.version_310?).to be_falsey
34
+ end
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: br_danfe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ASSEINFO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -160,27 +160,32 @@ files:
160
160
  - lib/br_danfe/xml.rb
161
161
  - lib/br_danfe/xprod.rb
162
162
  - spec/features/br_danfe_spec.rb
163
- - spec/fixtures/nfe_simples_nacional.xml
164
- - spec/fixtures/nfe_simples_nacional.xml.fixture.pdf
165
- - spec/fixtures/nfe_with_cpf.xml
166
- - spec/fixtures/nfe_with_cpf.xml.fixture.pdf
167
- - spec/fixtures/nfe_with_extra_volumes.xml
168
- - spec/fixtures/nfe_with_extra_volumes.xml.fixture.pdf
169
- - spec/fixtures/nfe_with_fci.xml
170
- - spec/fixtures/nfe_with_fci.xml.fixture.pdf
171
- - spec/fixtures/nfe_with_logo.xml
172
- - spec/fixtures/nfe_with_logo.xml.fixture.pdf
173
- - spec/fixtures/nfe_with_logo.xml.logo.png
174
- - spec/fixtures/nfe_with_ns.xml
175
- - spec/fixtures/nfe_with_ns.xml.fixture.pdf
176
- - spec/fixtures/nfe_without_ns.xml
177
- - spec/fixtures/nfe_without_ns.xml.fixture.pdf
163
+ - spec/fixtures/lib/dest.pdf
164
+ - spec/fixtures/v2.00/nfe_simples_nacional.xml
165
+ - spec/fixtures/v2.00/nfe_simples_nacional.xml.fixture.pdf
166
+ - spec/fixtures/v2.00/nfe_with_cpf.xml
167
+ - spec/fixtures/v2.00/nfe_with_cpf.xml.fixture.pdf
168
+ - spec/fixtures/v2.00/nfe_with_extra_volumes.xml
169
+ - spec/fixtures/v2.00/nfe_with_extra_volumes.xml.fixture.pdf
170
+ - spec/fixtures/v2.00/nfe_with_fci.xml
171
+ - spec/fixtures/v2.00/nfe_with_fci.xml.fixture.pdf
172
+ - spec/fixtures/v2.00/nfe_with_logo.xml
173
+ - spec/fixtures/v2.00/nfe_with_logo.xml.fixture.pdf
174
+ - spec/fixtures/v2.00/nfe_with_logo.xml.logo.png
175
+ - spec/fixtures/v2.00/nfe_with_ns.xml
176
+ - spec/fixtures/v2.00/nfe_with_ns.xml.fixture.pdf
177
+ - spec/fixtures/v2.00/nfe_without_ns.xml
178
+ - spec/fixtures/v2.00/nfe_without_ns.xml.fixture.pdf
179
+ - spec/fixtures/v3.10/nfe_simples_nacional.xml
180
+ - spec/fixtures/v3.10/nfe_simples_nacional.xml.fixture.pdf
178
181
  - spec/lib/cep_spec.rb
179
182
  - spec/lib/cst_spec.rb
183
+ - spec/lib/dest_spec.rb
180
184
  - spec/lib/helper_spec.rb
181
185
  - spec/lib/options_spec.rb
182
186
  - spec/lib/phone_spec.rb
183
187
  - spec/lib/plate_spec.rb
188
+ - spec/lib/xml_spec.rb
184
189
  - spec/lib/xprod_spec.rb
185
190
  - spec/spec_helper.rb
186
191
  - spec/support/be_same_file_as.rb
@@ -210,27 +215,32 @@ specification_version: 4
210
215
  summary: DANFE pdf generator for Brazilian invoices.
211
216
  test_files:
212
217
  - spec/features/br_danfe_spec.rb
213
- - spec/fixtures/nfe_simples_nacional.xml
214
- - spec/fixtures/nfe_simples_nacional.xml.fixture.pdf
215
- - spec/fixtures/nfe_with_cpf.xml
216
- - spec/fixtures/nfe_with_cpf.xml.fixture.pdf
217
- - spec/fixtures/nfe_with_extra_volumes.xml
218
- - spec/fixtures/nfe_with_extra_volumes.xml.fixture.pdf
219
- - spec/fixtures/nfe_with_fci.xml
220
- - spec/fixtures/nfe_with_fci.xml.fixture.pdf
221
- - spec/fixtures/nfe_with_logo.xml
222
- - spec/fixtures/nfe_with_logo.xml.fixture.pdf
223
- - spec/fixtures/nfe_with_logo.xml.logo.png
224
- - spec/fixtures/nfe_with_ns.xml
225
- - spec/fixtures/nfe_with_ns.xml.fixture.pdf
226
- - spec/fixtures/nfe_without_ns.xml
227
- - spec/fixtures/nfe_without_ns.xml.fixture.pdf
218
+ - spec/fixtures/lib/dest.pdf
219
+ - spec/fixtures/v2.00/nfe_simples_nacional.xml
220
+ - spec/fixtures/v2.00/nfe_simples_nacional.xml.fixture.pdf
221
+ - spec/fixtures/v2.00/nfe_with_cpf.xml
222
+ - spec/fixtures/v2.00/nfe_with_cpf.xml.fixture.pdf
223
+ - spec/fixtures/v2.00/nfe_with_extra_volumes.xml
224
+ - spec/fixtures/v2.00/nfe_with_extra_volumes.xml.fixture.pdf
225
+ - spec/fixtures/v2.00/nfe_with_fci.xml
226
+ - spec/fixtures/v2.00/nfe_with_fci.xml.fixture.pdf
227
+ - spec/fixtures/v2.00/nfe_with_logo.xml
228
+ - spec/fixtures/v2.00/nfe_with_logo.xml.fixture.pdf
229
+ - spec/fixtures/v2.00/nfe_with_logo.xml.logo.png
230
+ - spec/fixtures/v2.00/nfe_with_ns.xml
231
+ - spec/fixtures/v2.00/nfe_with_ns.xml.fixture.pdf
232
+ - spec/fixtures/v2.00/nfe_without_ns.xml
233
+ - spec/fixtures/v2.00/nfe_without_ns.xml.fixture.pdf
234
+ - spec/fixtures/v3.10/nfe_simples_nacional.xml
235
+ - spec/fixtures/v3.10/nfe_simples_nacional.xml.fixture.pdf
228
236
  - spec/lib/cep_spec.rb
229
237
  - spec/lib/cst_spec.rb
238
+ - spec/lib/dest_spec.rb
230
239
  - spec/lib/helper_spec.rb
231
240
  - spec/lib/options_spec.rb
232
241
  - spec/lib/phone_spec.rb
233
242
  - spec/lib/plate_spec.rb
243
+ - spec/lib/xml_spec.rb
234
244
  - spec/lib/xprod_spec.rb
235
245
  - spec/spec_helper.rb
236
246
  - spec/support/be_same_file_as.rb