onix2 1.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 (240) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +209 -0
  3. data/README.markdown +69 -0
  4. data/TODO +14 -0
  5. data/dtd/2.1r3/iso-amsa.ent +173 -0
  6. data/dtd/2.1r3/iso-amsb.ent +146 -0
  7. data/dtd/2.1r3/iso-amsc.ent +49 -0
  8. data/dtd/2.1r3/iso-amsn.ent +117 -0
  9. data/dtd/2.1r3/iso-amso.ent +77 -0
  10. data/dtd/2.1r3/iso-amsr.ent +205 -0
  11. data/dtd/2.1r3/iso-box.ent +67 -0
  12. data/dtd/2.1r3/iso-cyr1.ent +94 -0
  13. data/dtd/2.1r3/iso-cyr2.ent +53 -0
  14. data/dtd/2.1r3/iso-dia.ent +41 -0
  15. data/dtd/2.1r3/iso-grk3.ent +70 -0
  16. data/dtd/2.1r3/iso-lat1.ent +89 -0
  17. data/dtd/2.1r3/iso-lat2.ent +148 -0
  18. data/dtd/2.1r3/iso-mfrk.ent +79 -0
  19. data/dtd/2.1r3/iso-mopf.ent +53 -0
  20. data/dtd/2.1r3/iso-mscr.ent +79 -0
  21. data/dtd/2.1r3/iso-num.ent +103 -0
  22. data/dtd/2.1r3/iso-num.old.ent +103 -0
  23. data/dtd/2.1r3/iso-pub.ent +110 -0
  24. data/dtd/2.1r3/iso-tech.ent +183 -0
  25. data/dtd/2.1r3/onix-international.dtd +1012 -0
  26. data/dtd/2.1r3/onix-xhtml.elt +672 -0
  27. data/dtd/2.1r3/reference.elt +4758 -0
  28. data/dtd/2.1r3/xhtml-special.ent +79 -0
  29. data/dtd/2.1r3/xhtml-symbol.ent +242 -0
  30. data/lib/onix2.rb +85 -0
  31. data/lib/onix2/addressee_identifier.rb +29 -0
  32. data/lib/onix2/apa_product.rb +785 -0
  33. data/lib/onix2/audience_range.rb +37 -0
  34. data/lib/onix2/code_list_extractor.rb +69 -0
  35. data/lib/onix2/contributor.rb +55 -0
  36. data/lib/onix2/discount_coded.rb +29 -0
  37. data/lib/onix2/header.rb +68 -0
  38. data/lib/onix2/imprint.rb +31 -0
  39. data/lib/onix2/language.rb +29 -0
  40. data/lib/onix2/lists.rb +134 -0
  41. data/lib/onix2/market_representation.rb +38 -0
  42. data/lib/onix2/measure.rb +29 -0
  43. data/lib/onix2/media_file.rb +33 -0
  44. data/lib/onix2/other_text.rb +35 -0
  45. data/lib/onix2/price.rb +47 -0
  46. data/lib/onix2/product.rb +97 -0
  47. data/lib/onix2/product_identifier.rb +27 -0
  48. data/lib/onix2/publisher.rb +33 -0
  49. data/lib/onix2/reader.rb +157 -0
  50. data/lib/onix2/sales_restriction.rb +25 -0
  51. data/lib/onix2/sales_rights.rb +28 -0
  52. data/lib/onix2/sender_identifier.rb +29 -0
  53. data/lib/onix2/series.rb +28 -0
  54. data/lib/onix2/series_identifier.rb +27 -0
  55. data/lib/onix2/simple_product.rb +47 -0
  56. data/lib/onix2/stock.rb +29 -0
  57. data/lib/onix2/subject.rb +33 -0
  58. data/lib/onix2/supply_detail.rb +53 -0
  59. data/lib/onix2/title.rb +33 -0
  60. data/lib/onix2/version.rb +3 -0
  61. data/lib/onix2/website.rb +29 -0
  62. data/lib/onix2/writer.rb +86 -0
  63. data/spec/addressee_identifier_spec.rb +33 -0
  64. data/spec/apa_product_spec.rb +116 -0
  65. data/spec/audience_range_spec.rb +44 -0
  66. data/spec/contributor_spec.rb +38 -0
  67. data/spec/discount_coded_spec.rb +34 -0
  68. data/spec/header_spec.rb +153 -0
  69. data/spec/imprint_spec.rb +31 -0
  70. data/spec/language_spec.rb +38 -0
  71. data/spec/lists_spec.rb +33 -0
  72. data/spec/market_representation_spec.rb +33 -0
  73. data/spec/measure_spec.rb +38 -0
  74. data/spec/media_file_spec.rb +38 -0
  75. data/spec/other_text_spec.rb +33 -0
  76. data/spec/price_spec.rb +52 -0
  77. data/spec/product_identifier_spec.rb +34 -0
  78. data/spec/product_spec.rb +102 -0
  79. data/spec/publisher_spec.rb +33 -0
  80. data/spec/reader_spec.rb +155 -0
  81. data/spec/sales_restriction_spec.rb +27 -0
  82. data/spec/sender_identifier.rb +33 -0
  83. data/spec/series_identifier_spec.rb +33 -0
  84. data/spec/series_spec.rb +47 -0
  85. data/spec/spec_helper.rb +15 -0
  86. data/spec/stock_spec.rb +39 -0
  87. data/spec/subject_spec.rb +34 -0
  88. data/spec/supply_detail_spec.rb +97 -0
  89. data/spec/title_spec.rb +38 -0
  90. data/spec/website_spec.rb +33 -0
  91. data/spec/writer_spec.rb +78 -0
  92. data/support/codes/001.tsv +10 -0
  93. data/support/codes/002.tsv +5 -0
  94. data/support/codes/003.tsv +7 -0
  95. data/support/codes/005.tsv +13 -0
  96. data/support/codes/006.tsv +76 -0
  97. data/support/codes/007.tsv +123 -0
  98. data/support/codes/008.tsv +7 -0
  99. data/support/codes/009.tsv +7 -0
  100. data/support/codes/010.tsv +34 -0
  101. data/support/codes/011.tsv +11 -0
  102. data/support/codes/012.tsv +11 -0
  103. data/support/codes/013.tsv +7 -0
  104. data/support/codes/014.tsv +4 -0
  105. data/support/codes/015.tsv +13 -0
  106. data/support/codes/016.tsv +6 -0
  107. data/support/codes/017.tsv +90 -0
  108. data/support/codes/018.tsv +3 -0
  109. data/support/codes/019.tsv +7 -0
  110. data/support/codes/020.tsv +0 -0
  111. data/support/codes/021.tsv +31 -0
  112. data/support/codes/022.tsv +9 -0
  113. data/support/codes/023.tsv +9 -0
  114. data/support/codes/024.tsv +11 -0
  115. data/support/codes/025.tsv +29 -0
  116. data/support/codes/026.tsv +75 -0
  117. data/support/codes/027.tsv +75 -0
  118. data/support/codes/028.tsv +8 -0
  119. data/support/codes/029.tsv +16 -0
  120. data/support/codes/030.tsv +15 -0
  121. data/support/codes/031.tsv +3 -0
  122. data/support/codes/032.tsv +2 -0
  123. data/support/codes/033.tsv +36 -0
  124. data/support/codes/034.tsv +14 -0
  125. data/support/codes/035.tsv +6 -0
  126. data/support/codes/036.tsv +3 -0
  127. data/support/codes/037.tsv +6 -0
  128. data/support/codes/038.tsv +36 -0
  129. data/support/codes/039.tsv +8 -0
  130. data/support/codes/040.tsv +6 -0
  131. data/support/codes/041.tsv +6 -0
  132. data/support/codes/042.tsv +16 -0
  133. data/support/codes/043.tsv +4 -0
  134. data/support/codes/044.tsv +13 -0
  135. data/support/codes/045.tsv +12 -0
  136. data/support/codes/046.tsv +3 -0
  137. data/support/codes/047.tsv +4 -0
  138. data/support/codes/048.tsv +11 -0
  139. data/support/codes/049.tsv +84 -0
  140. data/support/codes/050.tsv +8 -0
  141. data/support/codes/051.tsv +27 -0
  142. data/support/codes/052.tsv +1 -0
  143. data/support/codes/053.tsv +3 -0
  144. data/support/codes/054.tsv +23 -0
  145. data/support/codes/055.tsv +13 -0
  146. data/support/codes/056.tsv +2 -0
  147. data/support/codes/057.tsv +5 -0
  148. data/support/codes/058.tsv +21 -0
  149. data/support/codes/059.tsv +4 -0
  150. data/support/codes/060.tsv +2 -0
  151. data/support/codes/061.tsv +3 -0
  152. data/support/codes/062.tsv +5 -0
  153. data/support/codes/063.tsv +0 -0
  154. data/support/codes/064.tsv +13 -0
  155. data/support/codes/065.tsv +25 -0
  156. data/support/codes/066.tsv +4 -0
  157. data/support/codes/067.tsv +2 -0
  158. data/support/codes/068.tsv +15 -0
  159. data/support/codes/069.tsv +4 -0
  160. data/support/codes/070.tsv +2 -0
  161. data/support/codes/071.tsv +9 -0
  162. data/support/codes/072.tsv +7 -0
  163. data/support/codes/073.tsv +36 -0
  164. data/support/codes/074.tsv +489 -0
  165. data/support/codes/075.tsv +2 -0
  166. data/support/codes/076.tsv +12 -0
  167. data/support/codes/077.tsv +19 -0
  168. data/support/codes/078.tsv +148 -0
  169. data/support/codes/079.tsv +17 -0
  170. data/support/codes/080.tsv +19 -0
  171. data/support/codes/081.tsv +11 -0
  172. data/support/codes/082.tsv +17 -0
  173. data/support/codes/083.tsv +68 -0
  174. data/support/codes/084.tsv +10 -0
  175. data/support/codes/085.tsv +23 -0
  176. data/support/codes/086.tsv +5 -0
  177. data/support/codes/087.tsv +6 -0
  178. data/support/codes/088.tsv +0 -0
  179. data/support/codes/089.tsv +1 -0
  180. data/support/codes/090.tsv +11 -0
  181. data/support/codes/091.tsv +248 -0
  182. data/support/codes/092.tsv +7 -0
  183. data/support/codes/093.tsv +13 -0
  184. data/support/codes/094.tsv +3 -0
  185. data/support/codes/095.tsv +3 -0
  186. data/support/codes/096.tsv +185 -0
  187. data/support/codes/097.tsv +1 -0
  188. data/support/codes/098.tsv +21 -0
  189. data/support/codes/099.tsv +24 -0
  190. data/support/codes/100.tsv +4 -0
  191. data/support/codes/101.tsv +2 -0
  192. data/support/codes/102.tsv +3 -0
  193. data/support/codes/121.tsv +127 -0
  194. data/support/codes/138.tsv +6 -0
  195. data/support/codes/139.tsv +70 -0
  196. data/support/codes/140.tsv +7 -0
  197. data/support/codes/141.tsv +10 -0
  198. data/support/codes/142.tsv +12 -0
  199. data/support/codes/143.tsv +7 -0
  200. data/support/codes/144.tsv +4 -0
  201. data/support/codes/145.tsv +5 -0
  202. data/support/codes/146.tsv +3 -0
  203. data/support/codes/147.tsv +7 -0
  204. data/support/codes/148.tsv +3 -0
  205. data/support/codes/149.tsv +4 -0
  206. data/support/codes/150.tsv +124 -0
  207. data/support/codes/151.tsv +7 -0
  208. data/support/codes/152.tsv +2 -0
  209. data/support/codes/153.tsv +14 -0
  210. data/support/codes/154.tsv +9 -0
  211. data/support/codes/155.tsv +5 -0
  212. data/support/codes/156.tsv +4 -0
  213. data/support/codes/157.tsv +4 -0
  214. data/support/codes/158.tsv +24 -0
  215. data/support/codes/159.tsv +6 -0
  216. data/support/codes/160.tsv +0 -0
  217. data/support/codes/161.tsv +3 -0
  218. data/support/codes/162.tsv +3 -0
  219. data/support/codes/163.tsv +7 -0
  220. data/support/codes/164.tsv +2 -0
  221. data/support/codes/165.tsv +2 -0
  222. data/support/codes/166.tsv +2 -0
  223. data/support/codes/167.tsv +3 -0
  224. data/support/codes/168.tsv +2 -0
  225. data/support/codes/169.tsv +3 -0
  226. data/support/codes/170.tsv +0 -0
  227. data/support/codes/171.tsv +2 -0
  228. data/support/codes/172.tsv +1 -0
  229. data/support/codes/173.tsv +2 -0
  230. data/support/codes/174.tsv +2 -0
  231. data/support/codes/175.tsv +175 -0
  232. data/support/codes/176.tsv +12 -0
  233. data/support/codes/177.tsv +2 -0
  234. data/support/codes/178.tsv +17 -0
  235. data/support/entities.txt +1499 -0
  236. data/support/extract.rb +25 -0
  237. data/support/switch-onix-2.1-short-to-reference.xsl +24 -0
  238. data/support/switch-onix-tagnames-1.1.xsl +25 -0
  239. data/support/switch-onix-tagnames-2.0.xsl +37 -0
  240. metadata +440 -0
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::AddresseeIdentifier do
6
+
7
+ Given(:doc) { load_xml "addressee.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:id) { ONIX2::AddresseeIdentifier.from_xml(doc) }
11
+ Then { id.to_xml.to_s.start_with? "<AddresseeIdentifier>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:id) { ONIX2::AddresseeIdentifier.from_xml(doc) }
16
+
17
+ Then { id.addressee_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::AddresseeIdentifier.new }
23
+ describe :addressee_id_type= do
24
+ When { id.addressee_id_type = 1 }
25
+ Then { id.to_xml.to_s.include? "<AddresseeIDType>01</AddresseeIDType>" }
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,116 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ # TODO: get rid of it or fix specs
6
+
7
+ # describe "ONIX2::APAProduct" do
8
+
9
+ # Given(:doc) { load_xml "product.xml" }
10
+
11
+ # describe "should provide read access to attributes" do
12
+ # Given(:product) { ONIX2::Product.from_xml(doc) }
13
+ # Given(:apa) { ONIX2::APAProduct.new(product) }
14
+
15
+ # Then { apa.record_reference == "365-9780194351898" }
16
+ # Then { apa.notification_type == 3 }
17
+ # Then { apa.product_form == "BC" }
18
+ # Then { apa.number_of_pages == 100 }
19
+ # Then { apa.bic_main_subject == "EB" }
20
+ # Then { apa.publishing_status == 4 }
21
+ # Then { apa.publication_date == Date.civil(1998,9,1) }
22
+ # Then { apa.pack_quantity == 12 }
23
+ # end
24
+
25
+ # context "should provide write access to attributes" do
26
+ # Given(:apa) { ONIX2::APAProduct.new }
27
+ # describe :notification_type= do
28
+ # When { apa.notification_type = 3 }
29
+ # Then { apa.to_xml.to_s.include? "<NotificationType>03</NotificationType>" }
30
+ # end
31
+ # describe :record_reference= do
32
+ # When { apa.record_reference = "365-9780194351898" }
33
+ # Then { apa.to_xml.to_s.include? "<RecordReference>365-9780194351898</RecordReference>" }
34
+ # end
35
+ # describe :product_form= do
36
+ # When { apa.product_form = "BC" }
37
+ # Then { apa.to_xml.to_s.include? "<ProductForm>BC</ProductForm>" }
38
+ # end
39
+ # describe :number_of_pages= do
40
+ # When { apa.number_of_pages = 100 }
41
+ # Then { apa.to_xml.to_s.include? "<NumberOfPages>100</NumberOfPages>" }
42
+ # end
43
+ # describe :bic_main_subject= do
44
+ # When { apa.bic_main_subject = "EB" }
45
+ # Then { apa.to_xml.to_s.include? "<BICMainSubject>EB</BICMainSubject>" }
46
+ # end
47
+ # describe :publishing_status= do
48
+ # When { apa.publishing_status = 4 }
49
+ # Then { apa.to_xml.to_s.include? "<PublishingStatus>04</PublishingStatus>" }
50
+ # end
51
+ # describe :publication_date= do
52
+ # When { apa.publication_date = Date.civil(1998,9,1) }
53
+ # Then { apa.to_xml.to_s.include? "<PublicationDate>19980901</PublicationDate>" }
54
+ # end
55
+ # describe :pack_quantity= do
56
+ # When { apa.pack_quantity = 12 }
57
+ # Then { apa.to_xml.to_s.include? "<PackQuantity>12</PackQuantity>" }
58
+ # end
59
+ # end
60
+
61
+ # end
62
+
63
+ # describe ONIX2::APAProduct, "series method" do
64
+ # describe "should set the nested series value on the underlying product class" do
65
+ # Given(:apa) { ONIX2::APAProduct.new }
66
+
67
+ # When { apa.series = "Harry Potter" }
68
+ # Then { apa.series == "Harry Potter" }
69
+ # Then { apa.to_xml.to_s.include? "<TitleOfSeries>Harry Potter</TitleOfSeries>" }
70
+ # end
71
+ # end
72
+
73
+ # describe ONIX2::APAProduct, "price method" do
74
+ # Given(:doc) { load_xml "usd.xml" }
75
+
76
+ # describe "should return the first price in the file, regardless of type" do
77
+ # Given(:product) { ONIX2::Product.from_xml(doc) }
78
+ # Given(:apa) { ONIX2::APAProduct.new(product) }
79
+
80
+ # Then { apa.price == BigDecimal.new("99.95") }
81
+ # end
82
+ # end
83
+
84
+ # describe ONIX2::APAProduct, "rrp_exc_sales_tax method" do
85
+ # Given(:doc) { load_xml "usd.xml" }
86
+
87
+ # describe "should return the first price in the file of type 1" do
88
+ # Given(:product) { ONIX2::Product.from_xml(doc) }
89
+ # Given(:apa) { ONIX2::APAProduct.new(product) }
90
+
91
+ # Then { apa.rrp_exc_sales_tax == BigDecimal.new("99.95") }
92
+ # end
93
+ # end
94
+
95
+ # describe ONIX2::APAProduct, "proprietry_discount_code_for_rrp method" do
96
+ # Given(:doc) { load_xml "product.xml" }
97
+
98
+ # describe "should return the first price in the file, regardless of type" do
99
+ # Given(:product) { ONIX2::Product.from_xml(doc) }
100
+ # Given(:apa) { ONIX2::APAProduct.new(product) }
101
+
102
+ # Then { apa.proprietry_discount_code_for_rrp == "123" }
103
+ # end
104
+ # end
105
+
106
+ # describe ONIX2::APAProduct, "proprietry_discount_code_for_rrp= method" do
107
+ # Given(:doc) { load_xml "product.xml" }
108
+
109
+ # describe "should set the discount code on the RRP" do
110
+ # Given(:product) { ONIX2::Product.from_xml(doc) }
111
+ # Given(:apa) { ONIX2::APAProduct.new(product) }
112
+
113
+ # When { apa.proprietry_discount_code_for_rrp = "123" }
114
+ # Then { apa.to_xml.to_s.include? "<DiscountCode>123</DiscountCode>" }
115
+ # end
116
+ # end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::AudienceRange do
6
+
7
+ Given(:doc) { load_xml "audience_range.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:aud) { ONIX2::AudienceRange.from_xml(doc) }
11
+ Then { aud.to_xml.to_s.start_with? "<AudienceRange>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:aud) { ONIX2::AudienceRange.from_xml(doc) }
16
+
17
+ Then { aud.audience_range_qualifier == 11 }
18
+ Then { aud.audience_range_precisions.size == 2 }
19
+ Then { aud.audience_range_precisions[0] == 3 }
20
+ Then { aud.audience_range_precisions[1] == 4 }
21
+ Then { aud.audience_range_values.size == 2 }
22
+ Then { aud.audience_range_values[0] == 3 }
23
+ Then { aud.audience_range_values[1] == 5 }
24
+ end
25
+
26
+ context "should provide write access to first level attributes" do
27
+ Given(:aud) { ONIX2::AudienceRange.new }
28
+ describe :audience_range_qualifier= do
29
+ When { aud.audience_range_qualifier = 2 }
30
+ Then { aud.to_xml.to_s.include? "<AudienceRangeQualifier>02</AudienceRangeQualifier>" }
31
+ end
32
+ describe :audience_range_precisions= do
33
+ When { aud.audience_range_precisions[0] = 888 }
34
+ When { aud.audience_range_precisions[1] = 12 }
35
+ Then { aud.to_xml.to_s.include? "<AudienceRangePrecision>88</AudienceRangePrecision>" }
36
+ Then { aud.to_xml.to_s.include? "<AudienceRangePrecision>12</AudienceRangePrecision>" }
37
+ end
38
+ describe :audience_range_values= do
39
+ When { aud.audience_range_values[0] = 999 }
40
+ Then { aud.to_xml.to_s.include? "<AudienceRangeValue>99</AudienceRangeValue>" }
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Contributor do
6
+
7
+ Given(:doc) { load_xml "contributor.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:header) { ONIX2::Contributor.from_xml(doc) }
11
+ Then { header.to_xml.to_s.start_with? "<Contributor>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:contrib) { ONIX2::Contributor.from_xml(doc) }
16
+
17
+ Then { contrib.contributor_role == "A01" }
18
+ Then { contrib.person_name_inverted == "SHAPIRO" }
19
+ Then { contrib.sequence_number == 1 }
20
+ end
21
+
22
+ context "should provide write access to first level attributes" do
23
+ Given(:contrib) { ONIX2::Contributor.new }
24
+ describe :contributor_role= do
25
+ When { contrib.contributor_role = "A02" }
26
+ Then { contrib.to_xml.to_s.include? "<ContributorRole>A02</ContributorRole>" }
27
+ end
28
+ describe :person_name_inverted= do
29
+ When { contrib.person_name_inverted = "Healy, James" }
30
+ Then { contrib.to_xml.to_s.include? "<PersonNameInverted>Healy, James</PersonNameInverted>" }
31
+ end
32
+ describe :sequence_number= do
33
+ When { contrib.sequence_number = 1 }
34
+ Then { contrib.to_xml.to_s.include? "<SequenceNumber>1</SequenceNumber>" }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::DiscountCoded do
6
+
7
+ Given(:doc) { load_xml "discount_coded.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:dc) { ONIX2::DiscountCoded.from_xml(doc) }
11
+ Then { dc.to_xml.to_s.start_with? "<DiscountCoded>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:dc) { ONIX2::DiscountCoded.from_xml(doc) }
16
+
17
+ Then { dc.discount_code_type == 2 }
18
+ Then { dc.discount_code_type_name == "IngramDC" }
19
+ Then { dc.discount_code == "AHACP033" }
20
+ end
21
+
22
+ context "should provide write access to first level attributes" do
23
+ Given(:dc) { ONIX2::DiscountCoded.new }
24
+ describe :discount_code_type= do
25
+ When { dc.discount_code_type = 1 }
26
+ Then { dc.to_xml.to_s.include? "<DiscountCodeType>01</DiscountCodeType>" }
27
+ end
28
+ describe :discount_code= do
29
+ When { dc.discount_code = "AHGFCP056" }
30
+ Then { dc.to_xml.to_s.include? "<DiscountCode>AHGFCP056</DiscountCode>" }
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,153 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Header do
6
+
7
+ Given(:doc) { load_xml "header.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:header) { ONIX2::Header.from_xml(doc) }
11
+ Then { header.to_xml.to_s.start_with? "<Header>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:header) { ONIX2::Header.from_xml(doc) }
16
+
17
+ Then { header.from_ean_number == "1111111111111" }
18
+ Then { header.from_san == "1111111" }
19
+ Then { header.from_company == "Text Company" }
20
+ Then { header.from_email == "james@rainbowbooks.com.au" }
21
+ Then { header.from_person == "James" }
22
+ Then { header.to_ean_number == "2222222222222" }
23
+ Then { header.to_san == "2222222" }
24
+ Then { header.to_company == "Company 2" }
25
+ Then { header.to_person == "Chris" }
26
+ Then { header.message_note == "A Message" }
27
+ Then { header.message_repeat == 1 }
28
+ Then { header.sent_date == Date.civil(2008,5,19) }
29
+ Then { header.default_language_of_text == "aaa" }
30
+ Then { header.default_price_type_code == 1 }
31
+ Then { header.default_currency_code == "ccc" }
32
+ Then { header.default_linear_unit == "dd" }
33
+ Then { header.default_weight_unit == "ee" }
34
+ Then { header.default_class_of_trade == "f" }
35
+ end
36
+
37
+ context "should provide write access to first level attributes" do
38
+ Given(:header) { ONIX2::Header.new }
39
+ describe :from_ean_number= do
40
+ When { header.from_ean_number = "1111111111111" }
41
+ Then { header.to_xml.to_s.include? "<FromEANNumber>1111111111111</FromEANNumber>" }
42
+ end
43
+ describe :from_san= do
44
+ When { header.from_san = "1111111" }
45
+ Then { header.to_xml.to_s.include? "<FromSAN>1111111</FromSAN>" }
46
+ end
47
+ describe :from_company= do
48
+ When { header.from_company = "Text Company" }
49
+ Then { header.to_xml.to_s.include? "<FromCompany>Text Company</FromCompany>" }
50
+ end
51
+ describe :from_email= do
52
+ When { header.from_email = "james@rainbowbooks.com.au" }
53
+ Then { header.to_xml.to_s.include? "<FromEmail>james@rainbowbooks.com.au</FromEmail>" }
54
+ end
55
+ describe :from_person= do
56
+ When { header.from_person = "James" }
57
+ Then { header.to_xml.to_s.include? "<FromPerson>James</FromPerson>" }
58
+ end
59
+ describe :to_ean_number= do
60
+ When { header.to_ean_number = "2222222222222" }
61
+ Then { header.to_xml.to_s.include? "<ToEANNumber>2222222222222</ToEANNumber>" }
62
+ end
63
+ describe :to_san= do
64
+ When { header.to_san = "2222222" }
65
+ Then { header.to_xml.to_s.include? "<ToSAN>2222222</ToSAN>" }
66
+ end
67
+ describe :to_company= do
68
+ When { header.to_company = "Company 2" }
69
+ Then { header.to_xml.to_s.include? "<ToCompany>Company 2</ToCompany>" }
70
+ end
71
+ describe :to_person= do
72
+ When { header.to_person = "Chris" }
73
+ Then { header.to_xml.to_s.include? "<ToPerson>Chris</ToPerson>" }
74
+ end
75
+ describe :message_note= do
76
+ When { header.message_note = "A Message" }
77
+ Then { header.to_xml.to_s.include? "<MessageNote>A Message</MessageNote>" }
78
+ end
79
+ describe :message_repeat= do
80
+ When { header.message_repeat = 1 }
81
+ Then { header.to_xml.to_s.include? "<MessageRepeat>1</MessageRepeat>" }
82
+ end
83
+ describe :sent_date= do
84
+ When { header.sent_date = Date.civil(2008,5,19) }
85
+ Then { header.to_xml.to_s.include? "<SentDate>20080519</SentDate>" }
86
+ end
87
+ describe :default_language_of_text= do
88
+ When { header.default_language_of_text = "aaa" }
89
+ Then { header.to_xml.to_s.include? "<DefaultLanguageOfText>aaa</DefaultLanguageOfText>" }
90
+ end
91
+ describe :default_price_type_code= do
92
+ When { header.default_price_type_code = 1 }
93
+ Then { header.to_xml.to_s.include? "<DefaultPriceTypeCode>01</DefaultPriceTypeCode>" }
94
+ end
95
+ describe :default_currency_code= do
96
+ When { header.default_currency_code = "ccc" }
97
+ Then { header.to_xml.to_s.include? "<DefaultCurrencyCode>ccc</DefaultCurrencyCode>" }
98
+ end
99
+ describe :default_class_of_trade= do
100
+ When { header.default_class_of_trade = "f" }
101
+ Then { header.to_xml.to_s.include? "<DefaultClassOfTrade>f</DefaultClassOfTrade>" }
102
+ end
103
+ end
104
+
105
+ context "should correctly handle text with & < and >" do
106
+ Given(:header) { ONIX2::Header.new }
107
+
108
+ describe "with &" do
109
+ When { header.from_company = "James & Healy" }
110
+ Then { header.to_xml.to_s.include?("James &amp; Healy") }
111
+ end
112
+
113
+ describe "with <" do
114
+ When { header.from_company = "James < Healy" }
115
+ Then { header.to_xml.to_s.include?("James &lt; Healy") }
116
+ end
117
+
118
+ describe "with >" do
119
+ When { header.from_company = "James > Healy" }
120
+ Then { header.to_xml.to_s.include?("James &gt; Healy") }
121
+ end
122
+ end
123
+
124
+ describe "should provide read access to sender IDs" do
125
+ Given(:header) { ONIX2::Header.from_xml(doc) }
126
+ Then { header.sender_identifiers.size == 2 }
127
+ end
128
+
129
+ context "should provide write access to addressee IDs" do
130
+ Given(:addressee_identifier1) { ONIX2::AddresseeIdentifier.new(addressee_id_type: 1) }
131
+ Given(:addressee_identifier2) { ONIX2::AddresseeIdentifier.new(id_value: 20002) }
132
+ Given(:header) { ONIX2::Header.new }
133
+
134
+ describe :addressee_identifiers= do
135
+ When { header.addressee_identifiers = [addressee_identifier1, addressee_identifier2] }
136
+
137
+ Then { header.to_xml.to_s.include? "<AddresseeIDType>01</AddresseeIDType>" }
138
+ Then { header.to_xml.to_s.include? "<IDValue>20002</IDValue>" }
139
+ end
140
+ end
141
+
142
+ end
143
+
144
+ describe ONIX2::Header do
145
+
146
+ Given(:doc) { load_xml "header_invalid_sentdate.xml" }
147
+
148
+ context "should correctly handle headers with an invalid sent date" do
149
+ Given(:header) { ONIX2::Header.from_xml(doc) }
150
+ Then { header.sent_date.nil? }
151
+ end
152
+
153
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe ONIX2::Imprint do
6
+
7
+ Given(:doc) { load_xml "imprint.xml" }
8
+
9
+ describe "should correctly convert to a string" do
10
+ Given(:imp) { ONIX2::Imprint.from_xml(doc) }
11
+ Then { imp.to_xml.to_s.start_with? "<Imprint>" }
12
+ end
13
+
14
+ describe "should provide read access to first level attributes" do
15
+ Given(:imp) { ONIX2::Imprint.from_xml(doc) }
16
+ Then { imp.imprint_name == "Oxford University Press UK" }
17
+ end
18
+
19
+ context "should provide write access to first level attributes" do
20
+ Given(:imp) { ONIX2::Imprint.new }
21
+ describe :imprint_name= do
22
+ When { imp.imprint_name = "Paulist Press" }
23
+ Then { imp.to_xml.to_s.include? "<ImprintName>Paulist Press</ImprintName>" }
24
+ end
25
+ describe :name_code_type= do
26
+ When { imp.name_code_type = 1 }
27
+ Then { imp.to_xml.to_s.include? "<NameCodeType>01</NameCodeType>" }
28
+ end
29
+ end
30
+
31
+ end