cxml-ruby 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
 
3
- <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.0.11/InvoiceDetail.dtd">
3
+ <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.037/InvoiceDetail.dtd">
4
4
 
5
5
  <cXML version="1.0" payloadID="1240598937@SUBDOMAIN.coupahost.com" timestamp="2018-05-04T01:24:51-07:00">
6
6
 
@@ -176,11 +176,9 @@
176
176
 
177
177
  <DiscountPercent percent="1" />
178
178
 
179
- <DiscountDueDays>1</DiscountDueDays>
180
179
 
181
180
  </Discount>
182
181
 
183
- <NetDueDays>1</NetDueDays>
184
182
 
185
183
  </PaymentTerm>
186
184
 
@@ -7,5 +7,6 @@
7
7
  <Description xml:lang="en">AGENDA MAGAZINE RACK A4 CHARCOAL 25990</Description>
8
8
  <UnitOfMeasure>EA</UnitOfMeasure>
9
9
  <UnitPrice> <Money currency="GBP">5.35</Money> </UnitPrice>
10
+ <Classification domain="UNSPSC">44000000</Classification>
10
11
  </ItemDetail>
11
12
  </ItemIn>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0"?>
2
- <cxml version="1.2.011" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
2
+ <cxml version="1.2.020" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
3
3
  <Header>
4
4
  <From>
5
5
  <Credential domain="NetworkID">
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <cXML version="1.2.011" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
2
+ <cXML version="1.2.020" payloadID="1346769469000.process.162998590@officedepot.com" timestamp="2012-09-04T02:37:49-05:00">
3
3
  <Response>
4
4
  <Status code="200" text="OK"/>
5
5
  <PunchOutSetupResponse>
@@ -1,5 +1,5 @@
1
- <cXML version="1.2.011" payloadID="1352382581000.process.454701738@domain.com" timestamp="2012-11-08T01:49:41-05:00">
1
+ <cXML version="1.2.020" payloadID="1352382581000.process.454701738@domain.com" timestamp="2012-11-08T01:49:41-05:00">
2
2
  <Response>
3
3
  <Status code="400" text="java.lang.Exception: missing required parameter 'document'"/>
4
4
  </Response>
5
- </cXML>
5
+ </cXML>
@@ -50,34 +50,54 @@ describe CXML::InvoiceDetailRequest do
50
50
  data = CXML::Parser.new(data: fixture('invoice_taxes_at_line.xml')).parse
51
51
  doc = CXML::Document.new(data)
52
52
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
53
+ next unless test_for_xmllint
54
+
55
+ lint_doc_with_dtd(doc).should be true
53
56
  end
54
57
  it 'serializes the same output' do
55
58
  data = CXML::Parser.new(data: fixture('invoice_backed_and_unbacked_by_pos.xml')).parse
56
59
  doc = CXML::Document.new(data)
57
60
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
61
+ next unless test_for_xmllint
62
+
63
+ lint_doc_with_dtd(doc).should be true
58
64
  end
59
65
  it 'serializes the same output' do
60
66
  data = CXML::Parser.new(data: fixture('invoice_backed_by_multiple_pos.xml')).parse
61
67
  doc = CXML::Document.new(data)
62
68
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
69
+ next unless test_for_xmllint
70
+
71
+ lint_doc_with_dtd(doc).should be true
63
72
  end
64
73
  it 'serializes the same output' do
65
74
  data = CXML::Parser.new(data: fixture('invoice_taxes_at_line_multiple_taxes.xml')).parse
66
75
  doc = CXML::Document.new(data)
67
76
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
77
+ next unless test_for_xmllint
78
+
79
+ lint_doc_with_dtd(doc).should be true
68
80
  end
69
81
  it 'serializes the same output' do
70
82
  fixture_xml = fixture('invoice_taxes_at_total.xml')
71
83
  data = CXML::Parser.new(data: fixture_xml).parse
72
84
  doc = CXML::Document.new(data)
73
85
  CXML::Parser.new(data: doc.to_xml).parse.should eq(data)
86
+ next unless test_for_xmllint
87
+
88
+ lint_doc_with_dtd(doc).should be true
74
89
  end
75
90
  it 'serializes from an instance' do
76
91
  money = CXML::Money.new(amount: '5', currency: 'USD')
77
92
  summary = CXML::InvoiceDetailSummary.new(gross_amount: CXML::GrossAmount.new(money: money))
78
93
  instance = described_class.new(invoice_detail_summary: summary)
79
94
  data = CXML::Request.new(invoice_detail_request: instance)
80
- doc = CXML::Document.new(request: data)
95
+ doc = CXML::Document.new(
96
+ request: data,
97
+ header: CXML::Header.new,
98
+ dtd: 'InvoiceDetail',
99
+ payload_id: 'foo'
100
+ )
81
101
  parsed = CXML::Parser.new(data: doc.to_xml).parse
82
102
  parsed[:request][:invoice_detail_request]
83
103
  .should eq(instance.serializable_hash)
data/spec/item_in_spec.rb CHANGED
@@ -35,5 +35,10 @@ describe CXML::ItemIn do
35
35
  item_in_output_data[:item_id].should_not be_empty
36
36
  item_in_output_data[:item_detail].should_not be_empty
37
37
  end
38
+ it 'validates against the DTD' do
39
+ next unless test_for_xmllint
40
+
41
+ lint_doc_with_dtd(CXML::Document.new.from_xml(output_xml)).should be true
42
+ end
38
43
  end
39
44
  end
File without changes
@@ -36,5 +36,10 @@ describe CXML::PunchOutOrderMessage do
36
36
  punch_out_order_message_output_data[:buyer_cookie].should_not be_empty
37
37
  punch_out_order_message_output_data.should include(:item_in)
38
38
  end
39
+ it 'validates against the DTD' do
40
+ next unless test_for_xmllint
41
+
42
+ lint_doc_with_dtd(CXML::Document.new.from_xml(output_xml)).should be true
43
+ end
39
44
  end
40
45
  end
@@ -19,6 +19,11 @@ describe CXML::OrderRequest do
19
19
  order_request_output_data[:item_out].should be_a Array
20
20
  order_request_output_data[:item_out].length.should eq 2
21
21
  end
22
+ it 'validates against the DTD' do
23
+ next unless test_for_xmllint
24
+
25
+ lint_doc_with_dtd(doc).should be true
26
+ end
22
27
  end
23
28
  describe '#initialize' do
24
29
  it 'sets the required nodes' do
@@ -27,7 +32,7 @@ describe CXML::OrderRequest do
27
32
  order_request.items_out.first.should_not be_nil
28
33
  end
29
34
  it 'sets the required nodes via another order request' do
30
- request = CXML::Document.new.from_xml(fixture('order_request.cxml')).request
35
+ request = CXML::Document.new.from_xml(fixture('order_request.xml')).request
31
36
  request.order_request.order_request_header.should_not be_nil
32
37
  request.order_request.order_request_header.order_id.should_not be_nil
33
38
  request.order_request.items_out.first.should_not be_nil
data/spec/sender_spec.rb CHANGED
@@ -26,5 +26,11 @@ describe CXML::Sender do
26
26
  sender_output_data[:user_agent].should_not be_empty
27
27
  sender_output_data[:credential].should_not be_empty
28
28
  end
29
+
30
+ it 'validates against the DTD' do
31
+ next unless test_for_xmllint
32
+
33
+ lint_doc_with_dtd(CXML::Document.new.from_xml(output_xml)).should be true
34
+ end
29
35
  end
30
36
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.expect_with(:rspec) { |c| c.syntax = :should }
12
+ config.default_formatter = 'doc' if config.files_to_run.one?
12
13
  end
13
14
 
14
15
  def fixture_path(filename = nil)
@@ -19,3 +20,29 @@ end
19
20
  def fixture(file)
20
21
  File.read(File.join(fixture_path, file))
21
22
  end
23
+
24
+ def dtd_path_from_url(url)
25
+ return 'spec/fixtures/1.2.037-cXML.dtd' unless url
26
+
27
+ match = url.match(%r{/(\d+\.\d+\.\d+)/(\w+\.dtd)}).to_a
28
+ file = 'spec/fixtures/' + match.last(2).join('-')
29
+ return file if File.exist?(file)
30
+
31
+ system("curl #{url} -O && mv #{match.last} #{file}")
32
+ file
33
+ end
34
+
35
+ def test_for_xmllint
36
+ return true if system('type xmllint > /dev/null 2>&1')
37
+
38
+ puts 'skipping DTD validation without xmllint'
39
+ false
40
+ end
41
+
42
+ def lint_doc_with_dtd(doc)
43
+ file = "spec/output/#{rand}.xml"
44
+ File.open(file, 'w') { |f| f.puts doc.to_xml }
45
+ linted = system("xmllint --noout --dtdvalid #{dtd_path_from_url(doc.dtd_url)} #{file}")
46
+ File.delete(file) if File.exist?(file)
47
+ linted
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Beckman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-30 00:00:00.000000000 Z
12
+ date: 2020-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ox
@@ -108,6 +108,7 @@ files:
108
108
  - lib/cxml/browser_form_post.rb
109
109
  - lib/cxml/charge.rb
110
110
  - lib/cxml/classification.rb
111
+ - lib/cxml/comment.rb
111
112
  - lib/cxml/confirmation_header.rb
112
113
  - lib/cxml/confirmation_item.rb
113
114
  - lib/cxml/confirmation_request.rb
@@ -118,6 +119,7 @@ files:
118
119
  - lib/cxml/credential_mac.rb
119
120
  - lib/cxml/deducted_price.rb
120
121
  - lib/cxml/deduction_amount.rb
122
+ - lib/cxml/deposit_amount.rb
121
123
  - lib/cxml/description.rb
122
124
  - lib/cxml/discount.rb
123
125
  - lib/cxml/discount_percent.rb
@@ -204,6 +206,10 @@ files:
204
206
  - spec/cxml_spec.rb
205
207
  - spec/document_spec.rb
206
208
  - spec/fixtures/.gitkeep
209
+ - spec/fixtures/1.2.014-cXML.dtd
210
+ - spec/fixtures/1.2.020-InvoiceDetail.dtd
211
+ - spec/fixtures/1.2.020-cXML.dtd
212
+ - spec/fixtures/1.2.037-InvoiceDetail.dtd
207
213
  - spec/fixtures/envelope.xml
208
214
  - spec/fixtures/envelope2.xml
209
215
  - spec/fixtures/invoice_backed_and_unbacked_by_pos.xml
@@ -212,7 +218,7 @@ files:
212
218
  - spec/fixtures/invoice_taxes_at_line_multiple_taxes.xml
213
219
  - spec/fixtures/invoice_taxes_at_total.xml
214
220
  - spec/fixtures/item_in.xml
215
- - spec/fixtures/order_request.cxml
221
+ - spec/fixtures/order_request.xml
216
222
  - spec/fixtures/punch_out_order_message_doc.xml
217
223
  - spec/fixtures/punch_out_setup_request_doc.xml
218
224
  - spec/fixtures/punch_out_setup_request_doc_coupa.xml
@@ -227,6 +233,7 @@ files:
227
233
  - spec/item_id_spec.rb
228
234
  - spec/item_in_spec.rb
229
235
  - spec/money_spec.rb
236
+ - spec/output/.gitkeep
230
237
  - spec/parser_spec.rb
231
238
  - spec/protocol_spec.rb
232
239
  - spec/punch_out_order_message_header_spec.rb
@@ -267,6 +274,10 @@ test_files:
267
274
  - spec/cxml_spec.rb
268
275
  - spec/document_spec.rb
269
276
  - spec/fixtures/.gitkeep
277
+ - spec/fixtures/1.2.014-cXML.dtd
278
+ - spec/fixtures/1.2.020-InvoiceDetail.dtd
279
+ - spec/fixtures/1.2.020-cXML.dtd
280
+ - spec/fixtures/1.2.037-InvoiceDetail.dtd
270
281
  - spec/fixtures/envelope.xml
271
282
  - spec/fixtures/envelope2.xml
272
283
  - spec/fixtures/invoice_backed_and_unbacked_by_pos.xml
@@ -275,7 +286,7 @@ test_files:
275
286
  - spec/fixtures/invoice_taxes_at_line_multiple_taxes.xml
276
287
  - spec/fixtures/invoice_taxes_at_total.xml
277
288
  - spec/fixtures/item_in.xml
278
- - spec/fixtures/order_request.cxml
289
+ - spec/fixtures/order_request.xml
279
290
  - spec/fixtures/punch_out_order_message_doc.xml
280
291
  - spec/fixtures/punch_out_setup_request_doc.xml
281
292
  - spec/fixtures/punch_out_setup_request_doc_coupa.xml
@@ -290,6 +301,7 @@ test_files:
290
301
  - spec/item_id_spec.rb
291
302
  - spec/item_in_spec.rb
292
303
  - spec/money_spec.rb
304
+ - spec/output/.gitkeep
293
305
  - spec/parser_spec.rb
294
306
  - spec/protocol_spec.rb
295
307
  - spec/punch_out_order_message_header_spec.rb