onix2 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +209 -0
- data/README.markdown +69 -0
- data/TODO +14 -0
- data/dtd/2.1r3/iso-amsa.ent +173 -0
- data/dtd/2.1r3/iso-amsb.ent +146 -0
- data/dtd/2.1r3/iso-amsc.ent +49 -0
- data/dtd/2.1r3/iso-amsn.ent +117 -0
- data/dtd/2.1r3/iso-amso.ent +77 -0
- data/dtd/2.1r3/iso-amsr.ent +205 -0
- data/dtd/2.1r3/iso-box.ent +67 -0
- data/dtd/2.1r3/iso-cyr1.ent +94 -0
- data/dtd/2.1r3/iso-cyr2.ent +53 -0
- data/dtd/2.1r3/iso-dia.ent +41 -0
- data/dtd/2.1r3/iso-grk3.ent +70 -0
- data/dtd/2.1r3/iso-lat1.ent +89 -0
- data/dtd/2.1r3/iso-lat2.ent +148 -0
- data/dtd/2.1r3/iso-mfrk.ent +79 -0
- data/dtd/2.1r3/iso-mopf.ent +53 -0
- data/dtd/2.1r3/iso-mscr.ent +79 -0
- data/dtd/2.1r3/iso-num.ent +103 -0
- data/dtd/2.1r3/iso-num.old.ent +103 -0
- data/dtd/2.1r3/iso-pub.ent +110 -0
- data/dtd/2.1r3/iso-tech.ent +183 -0
- data/dtd/2.1r3/onix-international.dtd +1012 -0
- data/dtd/2.1r3/onix-xhtml.elt +672 -0
- data/dtd/2.1r3/reference.elt +4758 -0
- data/dtd/2.1r3/xhtml-special.ent +79 -0
- data/dtd/2.1r3/xhtml-symbol.ent +242 -0
- data/lib/onix2.rb +85 -0
- data/lib/onix2/addressee_identifier.rb +29 -0
- data/lib/onix2/apa_product.rb +785 -0
- data/lib/onix2/audience_range.rb +37 -0
- data/lib/onix2/code_list_extractor.rb +69 -0
- data/lib/onix2/contributor.rb +55 -0
- data/lib/onix2/discount_coded.rb +29 -0
- data/lib/onix2/header.rb +68 -0
- data/lib/onix2/imprint.rb +31 -0
- data/lib/onix2/language.rb +29 -0
- data/lib/onix2/lists.rb +134 -0
- data/lib/onix2/market_representation.rb +38 -0
- data/lib/onix2/measure.rb +29 -0
- data/lib/onix2/media_file.rb +33 -0
- data/lib/onix2/other_text.rb +35 -0
- data/lib/onix2/price.rb +47 -0
- data/lib/onix2/product.rb +97 -0
- data/lib/onix2/product_identifier.rb +27 -0
- data/lib/onix2/publisher.rb +33 -0
- data/lib/onix2/reader.rb +157 -0
- data/lib/onix2/sales_restriction.rb +25 -0
- data/lib/onix2/sales_rights.rb +28 -0
- data/lib/onix2/sender_identifier.rb +29 -0
- data/lib/onix2/series.rb +28 -0
- data/lib/onix2/series_identifier.rb +27 -0
- data/lib/onix2/simple_product.rb +47 -0
- data/lib/onix2/stock.rb +29 -0
- data/lib/onix2/subject.rb +33 -0
- data/lib/onix2/supply_detail.rb +53 -0
- data/lib/onix2/title.rb +33 -0
- data/lib/onix2/version.rb +3 -0
- data/lib/onix2/website.rb +29 -0
- data/lib/onix2/writer.rb +86 -0
- data/spec/addressee_identifier_spec.rb +33 -0
- data/spec/apa_product_spec.rb +116 -0
- data/spec/audience_range_spec.rb +44 -0
- data/spec/contributor_spec.rb +38 -0
- data/spec/discount_coded_spec.rb +34 -0
- data/spec/header_spec.rb +153 -0
- data/spec/imprint_spec.rb +31 -0
- data/spec/language_spec.rb +38 -0
- data/spec/lists_spec.rb +33 -0
- data/spec/market_representation_spec.rb +33 -0
- data/spec/measure_spec.rb +38 -0
- data/spec/media_file_spec.rb +38 -0
- data/spec/other_text_spec.rb +33 -0
- data/spec/price_spec.rb +52 -0
- data/spec/product_identifier_spec.rb +34 -0
- data/spec/product_spec.rb +102 -0
- data/spec/publisher_spec.rb +33 -0
- data/spec/reader_spec.rb +155 -0
- data/spec/sales_restriction_spec.rb +27 -0
- data/spec/sender_identifier.rb +33 -0
- data/spec/series_identifier_spec.rb +33 -0
- data/spec/series_spec.rb +47 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/stock_spec.rb +39 -0
- data/spec/subject_spec.rb +34 -0
- data/spec/supply_detail_spec.rb +97 -0
- data/spec/title_spec.rb +38 -0
- data/spec/website_spec.rb +33 -0
- data/spec/writer_spec.rb +78 -0
- data/support/codes/001.tsv +10 -0
- data/support/codes/002.tsv +5 -0
- data/support/codes/003.tsv +7 -0
- data/support/codes/005.tsv +13 -0
- data/support/codes/006.tsv +76 -0
- data/support/codes/007.tsv +123 -0
- data/support/codes/008.tsv +7 -0
- data/support/codes/009.tsv +7 -0
- data/support/codes/010.tsv +34 -0
- data/support/codes/011.tsv +11 -0
- data/support/codes/012.tsv +11 -0
- data/support/codes/013.tsv +7 -0
- data/support/codes/014.tsv +4 -0
- data/support/codes/015.tsv +13 -0
- data/support/codes/016.tsv +6 -0
- data/support/codes/017.tsv +90 -0
- data/support/codes/018.tsv +3 -0
- data/support/codes/019.tsv +7 -0
- data/support/codes/020.tsv +0 -0
- data/support/codes/021.tsv +31 -0
- data/support/codes/022.tsv +9 -0
- data/support/codes/023.tsv +9 -0
- data/support/codes/024.tsv +11 -0
- data/support/codes/025.tsv +29 -0
- data/support/codes/026.tsv +75 -0
- data/support/codes/027.tsv +75 -0
- data/support/codes/028.tsv +8 -0
- data/support/codes/029.tsv +16 -0
- data/support/codes/030.tsv +15 -0
- data/support/codes/031.tsv +3 -0
- data/support/codes/032.tsv +2 -0
- data/support/codes/033.tsv +36 -0
- data/support/codes/034.tsv +14 -0
- data/support/codes/035.tsv +6 -0
- data/support/codes/036.tsv +3 -0
- data/support/codes/037.tsv +6 -0
- data/support/codes/038.tsv +36 -0
- data/support/codes/039.tsv +8 -0
- data/support/codes/040.tsv +6 -0
- data/support/codes/041.tsv +6 -0
- data/support/codes/042.tsv +16 -0
- data/support/codes/043.tsv +4 -0
- data/support/codes/044.tsv +13 -0
- data/support/codes/045.tsv +12 -0
- data/support/codes/046.tsv +3 -0
- data/support/codes/047.tsv +4 -0
- data/support/codes/048.tsv +11 -0
- data/support/codes/049.tsv +84 -0
- data/support/codes/050.tsv +8 -0
- data/support/codes/051.tsv +27 -0
- data/support/codes/052.tsv +1 -0
- data/support/codes/053.tsv +3 -0
- data/support/codes/054.tsv +23 -0
- data/support/codes/055.tsv +13 -0
- data/support/codes/056.tsv +2 -0
- data/support/codes/057.tsv +5 -0
- data/support/codes/058.tsv +21 -0
- data/support/codes/059.tsv +4 -0
- data/support/codes/060.tsv +2 -0
- data/support/codes/061.tsv +3 -0
- data/support/codes/062.tsv +5 -0
- data/support/codes/063.tsv +0 -0
- data/support/codes/064.tsv +13 -0
- data/support/codes/065.tsv +25 -0
- data/support/codes/066.tsv +4 -0
- data/support/codes/067.tsv +2 -0
- data/support/codes/068.tsv +15 -0
- data/support/codes/069.tsv +4 -0
- data/support/codes/070.tsv +2 -0
- data/support/codes/071.tsv +9 -0
- data/support/codes/072.tsv +7 -0
- data/support/codes/073.tsv +36 -0
- data/support/codes/074.tsv +489 -0
- data/support/codes/075.tsv +2 -0
- data/support/codes/076.tsv +12 -0
- data/support/codes/077.tsv +19 -0
- data/support/codes/078.tsv +148 -0
- data/support/codes/079.tsv +17 -0
- data/support/codes/080.tsv +19 -0
- data/support/codes/081.tsv +11 -0
- data/support/codes/082.tsv +17 -0
- data/support/codes/083.tsv +68 -0
- data/support/codes/084.tsv +10 -0
- data/support/codes/085.tsv +23 -0
- data/support/codes/086.tsv +5 -0
- data/support/codes/087.tsv +6 -0
- data/support/codes/088.tsv +0 -0
- data/support/codes/089.tsv +1 -0
- data/support/codes/090.tsv +11 -0
- data/support/codes/091.tsv +248 -0
- data/support/codes/092.tsv +7 -0
- data/support/codes/093.tsv +13 -0
- data/support/codes/094.tsv +3 -0
- data/support/codes/095.tsv +3 -0
- data/support/codes/096.tsv +185 -0
- data/support/codes/097.tsv +1 -0
- data/support/codes/098.tsv +21 -0
- data/support/codes/099.tsv +24 -0
- data/support/codes/100.tsv +4 -0
- data/support/codes/101.tsv +2 -0
- data/support/codes/102.tsv +3 -0
- data/support/codes/121.tsv +127 -0
- data/support/codes/138.tsv +6 -0
- data/support/codes/139.tsv +70 -0
- data/support/codes/140.tsv +7 -0
- data/support/codes/141.tsv +10 -0
- data/support/codes/142.tsv +12 -0
- data/support/codes/143.tsv +7 -0
- data/support/codes/144.tsv +4 -0
- data/support/codes/145.tsv +5 -0
- data/support/codes/146.tsv +3 -0
- data/support/codes/147.tsv +7 -0
- data/support/codes/148.tsv +3 -0
- data/support/codes/149.tsv +4 -0
- data/support/codes/150.tsv +124 -0
- data/support/codes/151.tsv +7 -0
- data/support/codes/152.tsv +2 -0
- data/support/codes/153.tsv +14 -0
- data/support/codes/154.tsv +9 -0
- data/support/codes/155.tsv +5 -0
- data/support/codes/156.tsv +4 -0
- data/support/codes/157.tsv +4 -0
- data/support/codes/158.tsv +24 -0
- data/support/codes/159.tsv +6 -0
- data/support/codes/160.tsv +0 -0
- data/support/codes/161.tsv +3 -0
- data/support/codes/162.tsv +3 -0
- data/support/codes/163.tsv +7 -0
- data/support/codes/164.tsv +2 -0
- data/support/codes/165.tsv +2 -0
- data/support/codes/166.tsv +2 -0
- data/support/codes/167.tsv +3 -0
- data/support/codes/168.tsv +2 -0
- data/support/codes/169.tsv +3 -0
- data/support/codes/170.tsv +0 -0
- data/support/codes/171.tsv +2 -0
- data/support/codes/172.tsv +1 -0
- data/support/codes/173.tsv +2 -0
- data/support/codes/174.tsv +2 -0
- data/support/codes/175.tsv +175 -0
- data/support/codes/176.tsv +12 -0
- data/support/codes/177.tsv +2 -0
- data/support/codes/178.tsv +17 -0
- data/support/entities.txt +1499 -0
- data/support/extract.rb +25 -0
- data/support/switch-onix-2.1-short-to-reference.xsl +24 -0
- data/support/switch-onix-tagnames-1.1.xsl +25 -0
- data/support/switch-onix-tagnames-2.0.xsl +37 -0
- metadata +440 -0
data/spec/reader_spec.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
4
|
+
|
5
|
+
describe ONIX2::Reader do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@data_path = File.join(File.dirname(__FILE__),"..","data")
|
9
|
+
@file1 = File.join(@data_path, "9780194351898.xml")
|
10
|
+
@file2 = File.join(@data_path, "two_products.xml")
|
11
|
+
@long_file = File.join(@data_path, "Bookwise_July_2008.xml")
|
12
|
+
@entity_file = File.join(@data_path, "entities.xml")
|
13
|
+
@utf_16_file = File.join(@data_path, "utf_16.xml")
|
14
|
+
@iso_8859_1_file = File.join(@data_path, "iso_8859_1.xml")
|
15
|
+
@no_encoding_decl_file = File.join(@data_path, "aau.xml")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should initialize with a filename" do
|
19
|
+
reader = ONIX2::Reader.new(@file1)
|
20
|
+
expect(reader.instance_variable_get("@reader")).to be_a_kind_of(Nokogiri::XML::Reader)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should initialize with an IO object" do
|
24
|
+
File.open(@file1,"rb") do |f|
|
25
|
+
reader = ONIX2::Reader.new(f)
|
26
|
+
expect(reader.instance_variable_get("@reader")).to be_a_kind_of(Nokogiri::XML::Reader)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should provide access to various XML metadata from file" do
|
31
|
+
filename = File.join(@data_path, "reference_with_release_attrib.xml")
|
32
|
+
reader = ONIX2::Reader.new(filename)
|
33
|
+
expect(reader.release).to eql(BigDecimal.new("2.1"))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should provide access to the header in an ONIX file" do
|
37
|
+
reader = ONIX2::Reader.new(@file1)
|
38
|
+
expect(reader.header).to be_a_kind_of(ONIX2::Header)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should iterate over all product records in an ONIX file" do
|
42
|
+
reader = ONIX2::Reader.new(@file1)
|
43
|
+
counter = 0
|
44
|
+
reader.each do |product|
|
45
|
+
expect(product).to be_a_kind_of(ONIX2::Product)
|
46
|
+
counter += 1
|
47
|
+
end
|
48
|
+
|
49
|
+
expect(counter).to be_eql(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should iterate over all product records in an ONIX file" do
|
53
|
+
reader = ONIX2::Reader.new(@file2)
|
54
|
+
products = []
|
55
|
+
reader.each do |product|
|
56
|
+
products << product
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(products.size).to be_eql(2)
|
60
|
+
expect(products[0].record_reference).to be_eql("365-9780194351898")
|
61
|
+
expect(products[1].record_reference).to be_eql("9780754672326")
|
62
|
+
end
|
63
|
+
|
64
|
+
# libxml can handle the 3 standard entities fine (& < and ^gt;) but
|
65
|
+
# barfs when it encounters others. In theory other entities are defined in the
|
66
|
+
# ONIX DTD, but I can't work out how to get libxml to recognise them
|
67
|
+
it "should correctly parse a file that has an entity in it" do
|
68
|
+
reader = ONIX2::Reader.new(@entity_file)
|
69
|
+
|
70
|
+
products = []
|
71
|
+
reader.each do |product|
|
72
|
+
products << product
|
73
|
+
end
|
74
|
+
|
75
|
+
expect(products.size).to be_eql(1)
|
76
|
+
expect(products.first.titles.size).to be_eql(1)
|
77
|
+
expect(products.first.titles.first.title_text).to be_eql("High Noon\342\200\223in Nimbin")
|
78
|
+
expect(products.first.record_reference).to be_eql("9780732287573")
|
79
|
+
end
|
80
|
+
|
81
|
+
# for some reason I'm getting segfaults when I read a file with more than 7 records
|
82
|
+
it "should correctly parse a file with more than 7 records in in" do
|
83
|
+
reader = ONIX2::Reader.new(@long_file)
|
84
|
+
counter = 0
|
85
|
+
reader.each do |product|
|
86
|
+
counter += 1
|
87
|
+
end
|
88
|
+
|
89
|
+
expect(counter).to be_eql(346)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should transparently convert a iso-8859-1 file to utf-8" do
|
93
|
+
reader = ONIX2::Reader.new(@iso_8859_1_file)
|
94
|
+
reader.each do |product|
|
95
|
+
if RUBY_VERSION >= "1.9"
|
96
|
+
utf8 = Encoding.find("utf-8")
|
97
|
+
expect(product.contributors[0].person_name_inverted.encoding).to be_eql(utf8)
|
98
|
+
end
|
99
|
+
|
100
|
+
expect(product.contributors[0].person_name_inverted).to be_eql("Küng, Hans")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# This isn't ideal behaviour, but i'm somewhat hamstrung by nokogiri API. It'd
|
105
|
+
# be nice to have the option to replace unrecognised bytes with a valid char.
|
106
|
+
it "should raise an exception when an iso-8859-1 file isn't declared as such" do
|
107
|
+
reader = ONIX2::Reader.new(@no_encoding_decl_file)
|
108
|
+
expect {
|
109
|
+
reader.each do |product|
|
110
|
+
end
|
111
|
+
}.to raise_error(Nokogiri::XML::SyntaxError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should transparently convert an iso-8859-1 file to utf-8 when there's no declaration but the user manually specifies iso-8859-1" do
|
115
|
+
reader = ONIX2::Reader.new(@no_encoding_decl_file, :encoding => "iso-8859-1")
|
116
|
+
reader.each do |product|
|
117
|
+
if RUBY_VERSION >= "1.9"
|
118
|
+
utf8 = Encoding.find("utf-8")
|
119
|
+
expect(product.contributors[0].person_name_inverted.encoding).to be_eql(utf8)
|
120
|
+
end
|
121
|
+
|
122
|
+
expect(product.contributors[0].person_name_inverted).to be_eql("Melo,Patr¡cia")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should transparently convert a utf-16 file to utf-8" do
|
127
|
+
reader = ONIX2::Reader.new(@utf_16_file)
|
128
|
+
product = nil
|
129
|
+
reader.each do |p|
|
130
|
+
product = p
|
131
|
+
end
|
132
|
+
|
133
|
+
# ROXML appears to munge the string encodings
|
134
|
+
if RUBY_VERSION >= "1.9"
|
135
|
+
utf8 = Encoding.find("utf-8")
|
136
|
+
expect(product.contributors[0].person_name_inverted.encoding).to be_eql(utf8)
|
137
|
+
end
|
138
|
+
|
139
|
+
expect(product.contributors[0].person_name_inverted).to be_eql("Küng, Hans")
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should support returning an APAProduct using deprecated API" do
|
143
|
+
reader = ONIX2::Reader.new(@file1, ONIX2::APAProduct)
|
144
|
+
reader.each do |product|
|
145
|
+
expect(product).to be_a_kind_of(ONIX2::APAProduct)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should support returning an APAProduct using new API" do
|
150
|
+
reader = ONIX2::Reader.new(@file1, :product_class => ONIX2::APAProduct)
|
151
|
+
reader.each do |product|
|
152
|
+
expect(product).to be_a_kind_of(ONIX2::APAProduct)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "ONIX2::SalesRestriction" do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "sales_restriction.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:sr) { ONIX2::SalesRestriction.from_xml(doc) }
|
11
|
+
Then { sr.to_xml.to_s.start_with? "<SalesRestriction>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should provide read access to first level attributes" do
|
15
|
+
Given(:sr) { ONIX2::SalesRestriction.from_xml(doc) }
|
16
|
+
Then { sr.sales_restriction_type == 0 }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "should provide write access to first level attributes" do
|
20
|
+
Given(:sr) { ONIX2::SalesRestriction.new }
|
21
|
+
describe :sales_restriction_type= do
|
22
|
+
When { sr.sales_restriction_type = 1 }
|
23
|
+
Then { sr.to_xml.to_s.include? "<SalesRestrictionType>01</SalesRestrictionType>" }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ONIX2::SenderIdentifier do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "sender_identifier.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:id) { ONIX2::SenderIdentifier.from_xml(doc) }
|
11
|
+
Then { id.to_xml.to_s.start_with? "<SenderIdentifier>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should provide read access to first level attributes" do
|
15
|
+
Given(:id) { ONIX2::SenderIdentifier.from_xml(doc) }
|
16
|
+
|
17
|
+
Then { id.sender_id_type == 1 }
|
18
|
+
Then { id.id_value == "123456" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "should provide write access to first level attributes" do
|
22
|
+
Given(:id) { ONIX2::SenderIdentifier.new }
|
23
|
+
describe :sender_id_type= do
|
24
|
+
When { id.sender_id_type = 1 }
|
25
|
+
Then { id.to_xml.to_s.include? "<SenderIDType>01</SenderIDType>" }
|
26
|
+
end
|
27
|
+
describe :id_value= do
|
28
|
+
When { id.id_value = "54321" }
|
29
|
+
Then { id.to_xml.to_s.include? "<IDValue>54321</IDValue>" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ONIX2::SeriesIdentifier do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "series_identifier.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:series) { ONIX2::SeriesIdentifier.from_xml(doc) }
|
11
|
+
Then { series.to_xml.to_s.start_with? "<SeriesIdentifier>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should provide read access to first level attributes" do
|
15
|
+
Given(:series) { ONIX2::SeriesIdentifier.from_xml(doc) }
|
16
|
+
|
17
|
+
Then { series.series_id_type == 1 }
|
18
|
+
Then { series.id_value == "10001" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "should provide write access to first level attributes" do
|
22
|
+
Given(:series) { ONIX2::SeriesIdentifier.new }
|
23
|
+
describe :series_id_type= do
|
24
|
+
When { series.series_id_type = 9 }
|
25
|
+
Then { series.to_xml.to_s.include? "<SeriesIDType>09</SeriesIDType>" }
|
26
|
+
end
|
27
|
+
describe :id_value= do
|
28
|
+
When { series.id_value = 999 }
|
29
|
+
Then { series.to_xml.to_s.include? "<IDValue>999</IDValue>" }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/series_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ONIX2::Series do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "series.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:series) { ONIX2::Series.from_xml(doc) }
|
11
|
+
|
12
|
+
Then{ series.to_xml.to_s.start_with? "<Series>" }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "should provide read access to first level attributes" do
|
16
|
+
Given(:series) { ONIX2::Series.from_xml(doc) }
|
17
|
+
|
18
|
+
Then{ series.title_of_series == "Citizens and Their Governments" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "should provide write access to first level attributes" do
|
22
|
+
Given(:series) { ONIX2::Series.new }
|
23
|
+
describe :title_of_series= do
|
24
|
+
When { series.title_of_series = "Cool Science Careers" }
|
25
|
+
Then { series.to_xml.to_s.include? "<TitleOfSeries>Cool Science Careers</TitleOfSeries>" }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "should provide read access to series IDs" do
|
30
|
+
Given(:series) { ONIX2::Series.from_xml(doc) }
|
31
|
+
Then { series.series_identifiers.size == 2 }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "should provide write access to series IDs" do
|
35
|
+
Given(:series_identifier1) { ONIX2::SeriesIdentifier.new(series_id_type: 1, id_value: 10001) }
|
36
|
+
Given(:series_identifier2) { ONIX2::SeriesIdentifier.new(series_id_type: 2, id_value: 20002) }
|
37
|
+
Given(:series) { ONIX2::Series.new }
|
38
|
+
|
39
|
+
describe :series_identifiers= do
|
40
|
+
When { series.series_identifiers = [series_identifier1, series_identifier2] }
|
41
|
+
|
42
|
+
Then { series.to_xml.to_s.include? "<SeriesIDType>01</SeriesIDType>" }
|
43
|
+
Then { series.to_xml.to_s.include? "<IDValue>20002</IDValue>" }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
require "pry"
|
7
|
+
require 'date'
|
8
|
+
require 'stringio'
|
9
|
+
require 'rubygems'
|
10
|
+
require 'onix2'
|
11
|
+
require 'rspec/given'
|
12
|
+
|
13
|
+
def load_xml(file)
|
14
|
+
File.read(File.join(File.dirname(__FILE__), "..", "data", file))
|
15
|
+
end
|
data/spec/stock_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ONIX2::Stock do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "stock.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:s) { ONIX2::Stock.from_xml(doc) }
|
11
|
+
Then { s.to_xml.to_s.start_with? "<Stock>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should provide read access to first level attributes" do
|
15
|
+
Given(:s) { ONIX2::Stock.from_xml(doc) }
|
16
|
+
|
17
|
+
# note that these fields *should* be numeric according to the ONIX spec,
|
18
|
+
# however heaps of ONIX files in the wild have strings there.
|
19
|
+
Then { s.on_hand == "2862" }
|
20
|
+
Then { s.on_order == "0" }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "should provide write access to first level attributes" do
|
24
|
+
Given(:s) { ONIX2::Stock.new }
|
25
|
+
describe :on_hand= do
|
26
|
+
When { s.on_hand = "123" }
|
27
|
+
Then { s.to_xml.to_s.include? "<OnHand>123</OnHand>" }
|
28
|
+
end
|
29
|
+
describe :on_order= do
|
30
|
+
When { s.on_order = "011" }
|
31
|
+
Then { s.to_xml.to_s.include? "<OnOrder>011</OnOrder>" }
|
32
|
+
end
|
33
|
+
describe :on_order= do
|
34
|
+
When { s.on_order = 11 }
|
35
|
+
Then { s.to_xml.to_s.include? "<OnOrder>11</OnOrder>" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ONIX2::Subject do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "subject.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:sub) { ONIX2::Subject.from_xml(doc) }
|
11
|
+
Then { sub.to_xml.to_s.start_with? "<Subject>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should provide read access to first level attributes" do
|
15
|
+
Given(:sub) { ONIX2::Subject.from_xml(doc) }
|
16
|
+
|
17
|
+
Then { sub.subject_scheme_id == 3 }
|
18
|
+
Then { sub.subject_scheme_name == "RBA Subjects" }
|
19
|
+
Then { sub.subject_code == "AABB" }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "should provide write access to first level attributes" do
|
23
|
+
Given(:sub) { ONIX2::Subject.new }
|
24
|
+
describe :subject_scheme_id= do
|
25
|
+
When { sub.subject_scheme_id = 2 }
|
26
|
+
Then { sub.to_xml.to_s.include? "<SubjectSchemeIdentifier>02</SubjectSchemeIdentifier>" }
|
27
|
+
end
|
28
|
+
describe :subject_code= do
|
29
|
+
When { sub.subject_code = "ABCD" }
|
30
|
+
Then { sub.to_xml.to_s.include? "<SubjectCode>ABCD</SubjectCode>" }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe ONIX2::SupplyDetail do
|
6
|
+
|
7
|
+
Given(:doc) { load_xml "supply_detail.xml" }
|
8
|
+
|
9
|
+
describe "should correctly convert to a string" do
|
10
|
+
Given(:sd) { ONIX2::SupplyDetail.from_xml(doc) }
|
11
|
+
Then { sd.to_xml.to_s.start_with? "<SupplyDetail>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "should provide read access to first level attributes" do
|
15
|
+
Given(:sd) { ONIX2::SupplyDetail.from_xml(doc) }
|
16
|
+
|
17
|
+
Then { sd.supplier_name == "Rainbow Book Agencies" }
|
18
|
+
Then { sd.product_availability == 21 }
|
19
|
+
Then { sd.stock.is_a? Array }
|
20
|
+
Then { sd.stock.size == 1 }
|
21
|
+
Then { sd.pack_quantity == 16 }
|
22
|
+
Then { sd.prices.is_a? Array }
|
23
|
+
Then { sd.prices.size == 1 }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "should provide write access to first level attributes" do
|
27
|
+
Given(:sd) { ONIX2::SupplyDetail.new }
|
28
|
+
describe :supplier_name= do
|
29
|
+
When { sd.supplier_name = "RBA" }
|
30
|
+
Then { sd.to_xml.to_s.include? "<SupplierName>RBA</SupplierName>" }
|
31
|
+
end
|
32
|
+
describe :supplier_role= do
|
33
|
+
When { sd.supplier_role = 1 }
|
34
|
+
Then { sd.to_xml.to_s.include? "<SupplierRole>01</SupplierRole>" }
|
35
|
+
end
|
36
|
+
describe :availability_status_code= do
|
37
|
+
When { sd.availability_status_code = 2 }
|
38
|
+
Then { sd.to_xml.to_s.include? "<AvailabilityStatusCode>02</AvailabilityStatusCode>" }
|
39
|
+
end
|
40
|
+
describe :product_availability= do
|
41
|
+
When { sd.product_availability = 3 }
|
42
|
+
Then { sd.to_xml.to_s.include? "<ProductAvailability>03</ProductAvailability>" }
|
43
|
+
end
|
44
|
+
describe :pack_quantity= do
|
45
|
+
When { sd.pack_quantity = 12 }
|
46
|
+
Then { sd.to_xml.to_s.include? "<PackQuantity>12</PackQuantity>" }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "should provide read access to website IDs" do
|
51
|
+
Given(:sd) { ONIX2::SupplyDetail.from_xml(doc) }
|
52
|
+
Then { sd.websites.size == 2 }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "should provide write access to website IDs" do
|
56
|
+
Given(:website) { ONIX2::Website.new(website_role: 1) }
|
57
|
+
Given(:sd) { ONIX2::SupplyDetail.new }
|
58
|
+
|
59
|
+
describe :series_identifiers= do
|
60
|
+
When { sd.websites = [website] }
|
61
|
+
Then { sd.to_xml.to_s.include? "<WebsiteRole>01</WebsiteRole>" }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "should provide read access to stock IDs" do
|
66
|
+
Given(:sd) { ONIX2::SupplyDetail.from_xml(doc) }
|
67
|
+
Then { sd.stock.size == 1 }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "should provide write access to stock IDs" do
|
71
|
+
Given(:stock1) { ONIX2::Stock.new(on_hand: 1251) }
|
72
|
+
Given(:stock2) { ONIX2::Stock.new(on_hand: 52458, on_order: 0) }
|
73
|
+
Given(:sd) { ONIX2::SupplyDetail.new }
|
74
|
+
|
75
|
+
describe :series_identifiers= do
|
76
|
+
When { sd.stock = [stock1, stock2] }
|
77
|
+
Then { sd.to_xml.to_s.include? "<OnHand>1251</OnHand>" }
|
78
|
+
Then { sd.to_xml.to_s.include? "<OnOrder>0</OnOrder>" }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "should provide read access to price IDs" do
|
83
|
+
Given(:sd) { ONIX2::SupplyDetail.from_xml(doc) }
|
84
|
+
Then { sd.prices.size == 1 }
|
85
|
+
end
|
86
|
+
|
87
|
+
context "should provide write access to price IDs" do
|
88
|
+
Given(:price) { ONIX2::Price.new(price_amount: BigDecimal.new("0.59")) }
|
89
|
+
Given(:sd) { ONIX2::SupplyDetail.new }
|
90
|
+
|
91
|
+
describe :series_identifiers= do
|
92
|
+
When { sd.prices = [price] }
|
93
|
+
Then { sd.to_xml.to_s.include? "<PriceAmount>0.59</PriceAmount>" }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|