mods 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,76 +3,141 @@ require 'spec_helper'
3
3
  describe "Mods <physicalDescription> Element" do
4
4
  before(:all) do
5
5
  @mods_rec = Mods::Record.new
6
- @extent_only = '<mods><physicalDescription><extent>extent</extent></physicalDescription></mods>'
7
- @form_and_extent = '<mods><physicalDescription>
8
- <form authority="smd">map</form>
9
- <form type="material">foo</form>
10
- <extent>1 map ; 22 x 18 cm.</extent>
11
- </physicalDescription></mods>'
12
- @forms_and_notes = '<mods><physicalDescription>
13
- <form authority="aat">Graphics</form>
14
- <form>plain form</form>
15
- <note displayLabel="Dimensions">dimension text</note>
16
- <note displayLabel="Condition">condition text</note>
17
- </physicalDescription></mods>'
18
- @digital = '<mods><physicalDescription>
19
- <reformattingQuality>preservation</reformattingQuality>
20
- <internetMediaType>image/jp2</internetMediaType>
21
- <digitalOrigin>reformatted digital</digitalOrigin>
22
- </physicalDescription></mods>'
6
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
23
7
  end
24
8
 
25
9
  context "basic physical_description terminology pieces" do
26
- before(:all) do
27
- @mods_rec.from_str(@form_and_extent)
28
- end
29
10
 
30
- it "extent child element" do
31
- @mods_rec.from_str(@extent_only)
32
- @mods_rec.physical_description.extent.map { |n| n.text }.should == ["extent"]
33
- end
11
+ context "WITH namespaces" do
34
12
 
35
- context "note child element" do
36
- before(:all) do
37
- @mods_rec.from_str(@forms_and_notes)
13
+ it "extent child element" do
14
+ @mods_rec.from_str("<mods #{@ns_decl}><physicalDescription><extent>extent</extent></physicalDescription></mods>")
15
+ @mods_rec.physical_description.extent.map { |n| n.text }.should == ["extent"]
38
16
  end
39
- it "should understand note element" do
40
- @mods_rec.physical_description.note.map { |n| n.text }.should == ["dimension text", "condition text"]
41
- end
42
- it "should understand displayLabel attribute on note element" do
43
- @mods_rec.physical_description.note.displayLabel.should == ["Dimensions", "Condition"]
44
- end
45
- end
46
17
 
47
- context "form child element" do
48
- before(:all) do
49
- @mods_rec.from_str(@form_and_extent)
18
+ context "note child element" do
19
+ before(:all) do
20
+ forms_and_notes = "<mods #{@ns_decl}><physicalDescription>
21
+ <form authority='aat'>Graphics</form>
22
+ <form>plain form</form>
23
+ <note displayLabel='Dimensions'>dimension text</note>
24
+ <note displayLabel='Condition'>condition text</note>
25
+ </physicalDescription></mods>"
26
+ @mods_rec.from_str(forms_and_notes)
27
+ end
28
+ it "should understand note element" do
29
+ @mods_rec.physical_description.note.map { |n| n.text }.should == ["dimension text", "condition text"]
30
+ end
31
+ it "should understand displayLabel attribute on note element" do
32
+ @mods_rec.physical_description.note.displayLabel.should == ["Dimensions", "Condition"]
33
+ end
50
34
  end
51
- it "should understand form element" do
52
- @mods_rec.physical_description.form.map { |n| n.text }.should == ["map", "foo"]
35
+
36
+ context "form child element" do
37
+ before(:all) do
38
+ forms_and_extent = "<mods #{@ns_decl}><physicalDescription>
39
+ <form authority='smd'>map</form>
40
+ <form type='material'>foo</form>
41
+ <extent>1 map ; 22 x 18 cm.</extent>
42
+ </physicalDescription></mods>"
43
+ @mods_rec.from_str(forms_and_extent)
44
+ end
45
+ it "should understand form element" do
46
+ @mods_rec.physical_description.form.map { |n| n.text }.should == ["map", "foo"]
47
+ end
48
+ it "should understand authority attribute on form element" do
49
+ @mods_rec.physical_description.form.authority.should == ["smd"]
50
+ end
51
+ it "should understand type attribute on form element" do
52
+ @mods_rec.physical_description.form.type_at.should == ["material"]
53
+ end
53
54
  end
54
- it "should understand authority attribute on form element" do
55
- @mods_rec.physical_description.form.authority.should == ["smd"]
55
+
56
+ context "digital materials" do
57
+ before(:all) do
58
+ digital = "<mods #{@ns_decl}><physicalDescription>
59
+ <reformattingQuality>preservation</reformattingQuality>
60
+ <internetMediaType>image/jp2</internetMediaType>
61
+ <digitalOrigin>reformatted digital</digitalOrigin>
62
+ </physicalDescription></mods>"
63
+ @mods_rec.from_str(digital)
64
+ end
65
+ it "should understand reformattingQuality child element" do
66
+ @mods_rec.physical_description.reformattingQuality.map { |n| n.text }.should == ["preservation"]
67
+ end
68
+ it "should understand digitalOrigin child element" do
69
+ @mods_rec.physical_description.digitalOrigin.map { |n| n.text }.should == ["reformatted digital"]
70
+ end
71
+ it "should understand internetMediaType child element" do
72
+ @mods_rec.physical_description.internetMediaType.map { |n| n.text }.should == ["image/jp2"]
73
+ end
56
74
  end
57
- it "should understand type attribute on form element" do
58
- @mods_rec.physical_description.form.type_at.should == ["material"]
75
+ end # WITH namespaces
76
+
77
+ context "WITHOUT namespaces" do
78
+ it "extent child element" do
79
+ @mods_rec.from_str('<mods><physicalDescription><extent>extent</extent></physicalDescription></mods>', false)
80
+ @mods_rec.physical_description.extent.map { |n| n.text }.should == ["extent"]
59
81
  end
60
- end
61
82
 
62
- context "digital materials" do
63
- before(:all) do
64
- @mods_rec.from_str(@digital)
65
- end
66
- it "should understand reformattingQuality child element" do
67
- @mods_rec.physical_description.reformattingQuality.map { |n| n.text }.should == ["preservation"]
83
+ context "note child element" do
84
+ before(:all) do
85
+ forms_and_notes = '<mods><physicalDescription>
86
+ <form authority="aat">Graphics</form>
87
+ <form>plain form</form>
88
+ <note displayLabel="Dimensions">dimension text</note>
89
+ <note displayLabel="Condition">condition text</note>
90
+ </physicalDescription></mods>'
91
+ @mods_rec.from_str(forms_and_notes, false)
92
+ end
93
+ it "should understand note element" do
94
+ @mods_rec.physical_description.note.map { |n| n.text }.should == ["dimension text", "condition text"]
95
+ end
96
+ it "should understand displayLabel attribute on note element" do
97
+ @mods_rec.physical_description.note.displayLabel.should == ["Dimensions", "Condition"]
98
+ end
68
99
  end
69
- it "should understand digitalOrigin child element" do
70
- @mods_rec.physical_description.digitalOrigin.map { |n| n.text }.should == ["reformatted digital"]
100
+
101
+ context "form child element" do
102
+ before(:all) do
103
+ forms_and_extent = '<mods><physicalDescription>
104
+ <form authority="smd">map</form>
105
+ <form type="material">foo</form>
106
+ <extent>1 map ; 22 x 18 cm.</extent>
107
+ </physicalDescription></mods>'
108
+ @mods_rec.from_str(forms_and_extent, false)
109
+ end
110
+ it "should understand form element" do
111
+ @mods_rec.physical_description.form.map { |n| n.text }.should == ["map", "foo"]
112
+ end
113
+ it "should understand authority attribute on form element" do
114
+ @mods_rec.physical_description.form.authority.should == ["smd"]
115
+ end
116
+ it "should understand type attribute on form element" do
117
+ @mods_rec.physical_description.form.type_at.should == ["material"]
118
+ end
71
119
  end
72
- it "should understand internetMediaType child element" do
73
- @mods_rec.physical_description.internetMediaType.map { |n| n.text }.should == ["image/jp2"]
120
+
121
+ context "digital materials" do
122
+ before(:all) do
123
+ digital = '<mods><physicalDescription>
124
+ <reformattingQuality>preservation</reformattingQuality>
125
+ <internetMediaType>image/jp2</internetMediaType>
126
+ <digitalOrigin>reformatted digital</digitalOrigin>
127
+ </physicalDescription></mods>'
128
+ @mods_rec.from_str(digital, false)
129
+ end
130
+ it "should understand reformattingQuality child element" do
131
+ @mods_rec.physical_description.reformattingQuality.map { |n| n.text }.should == ["preservation"]
132
+ end
133
+ it "should understand digitalOrigin child element" do
134
+ @mods_rec.physical_description.digitalOrigin.map { |n| n.text }.should == ["reformatted digital"]
135
+ end
136
+ it "should understand internetMediaType child element" do
137
+ @mods_rec.physical_description.internetMediaType.map { |n| n.text }.should == ["image/jp2"]
138
+ end
74
139
  end
75
- end
140
+ end # WITHOUT namespaces
76
141
 
77
142
  end # basic terminology pieces
78
143
 
data/spec/reader_spec.rb CHANGED
@@ -4,38 +4,93 @@ require 'spec_helper'
4
4
 
5
5
  describe "Mods::Reader" do
6
6
  before(:all) do
7
+ @ns_hash = {'m' => Mods::MODS_NS}
7
8
  # url is for a namespaced document
8
9
  @example_url = 'http://www.loc.gov/standards/mods/v3/mods99042030_linkedDataAdded.xml'
9
- @example_no_ns_str = '<mods><note>hi</note></mods>'
10
- @example_wrong_ns_str = '<mods xmlns="whoops"><note>hi</note></mods>'
11
- @from_no_ns_str = Mods::Reader.new.from_str(@example_no_ns_str)
12
- @from_wrong_ns_str = Mods::Reader.new.from_str(@example_wrong_ns_str)
10
+ @example_default_ns_str = '<mods xmlns="http://www.loc.gov/mods/v3"><note>default ns</note></mods>'
11
+ @example_ns_str = '<mods:mods xmlns:mods="http://www.loc.gov/mods/v3"><mods:note>ns</mods:note></mods:mods>'
12
+ @example_no_ns_str = '<mods><note>no ns</note></mods>'
13
+ @example_wrong_ns_str = '<mods xmlns="wrong"><note>wrong ns</note></mods>'
14
+ @doc_from_str_default_ns = Mods::Reader.new.from_str(@example_ns_str)
15
+ @doc_from_str_ns = Mods::Reader.new.from_str(@example_ns_str)
16
+ @doc_from_str_no_ns = Mods::Reader.new.from_str(@example_no_ns_str)
17
+ @doc_from_str_wrong_ns = Mods::Reader.new.from_str(@example_wrong_ns_str)
13
18
  @from_url = Mods::Reader.new.from_url(@example_url)
14
- @ns_hash = {'mods' => Mods::MODS_NS}
15
19
  end
16
20
 
17
21
  it "from_str should turn an xml string into a Nokogiri::XML::Document object" do
18
- @from_no_ns_str.class.should == Nokogiri::XML::Document
19
- @from_wrong_ns_str.class.should == Nokogiri::XML::Document
22
+ @doc_from_str_default_ns.class.should == Nokogiri::XML::Document
23
+ @doc_from_str_ns.class.should == Nokogiri::XML::Document
24
+ @doc_from_str_no_ns.class.should == Nokogiri::XML::Document
25
+ @doc_from_str_wrong_ns.class.should == Nokogiri::XML::Document
20
26
  end
21
27
 
22
28
  it "from_url should turn the contents at the url into a Nokogiri::XML::Document object" do
23
29
  @from_url.class.should == Nokogiri::XML::Document
24
30
  end
25
31
 
32
+ context "namespace awareness" do
33
+ it "should care about namespace by default" do
34
+ r = Mods::Reader.new
35
+ r.namespace_aware.should == true
36
+ @doc_from_str_default_ns.root.namespace.href.should == Mods::MODS_NS
37
+ @doc_from_str_default_ns.xpath('/m:mods/m:note', @ns_hash).text.should == "ns"
38
+ @doc_from_str_default_ns.xpath('/mods/note').size.should == 0
39
+ @doc_from_str_ns.root.namespace.href.should == Mods::MODS_NS
40
+ @doc_from_str_ns.xpath('/m:mods/m:note', @ns_hash).text.should == "ns"
41
+ @doc_from_str_ns.xpath('/mods/note').size.should == 0
42
+ @doc_from_str_no_ns.xpath('/m:mods/m:note', @ns_hash).size.should == 0
43
+ @doc_from_str_no_ns.xpath('/mods/note').text.should == "no ns"
44
+ @doc_from_str_wrong_ns.root.namespace.href.should == "wrong"
45
+ @doc_from_str_wrong_ns.xpath('/m:mods/m:note', @ns_hash).size.should == 0
46
+ @doc_from_str_wrong_ns.xpath('/mods/note').size.should == 0
47
+ end
48
+
49
+ it "should be allowed not to care about namespaces" do
50
+ r = Mods::Reader.new(false)
51
+ r.namespace_aware.should == false
52
+ my_from_str_ns = r.from_str(@example_ns_str)
53
+ my_from_str_ns.xpath('/m:mods/m:note', @ns_hash).size.should == 0
54
+ my_from_str_ns.xpath('/mods/note').text.should == "ns"
55
+ my_from_str_no_ns = r.from_str(@example_no_ns_str)
56
+ my_from_str_no_ns.xpath('/m:mods/m:note', @ns_hash).size.should == 0
57
+ my_from_str_no_ns.xpath('/mods/note').text.should == "no ns"
58
+ my_from_str_wrong_ns = r.from_str(@example_wrong_ns_str)
59
+ my_from_str_wrong_ns.xpath('/m:mods/m:note', @ns_hash).size.should == 0
60
+ my_from_str_wrong_ns.xpath('/mods/note').text.should == "wrong ns"
61
+ end
62
+ end
63
+
64
+ it "should do something useful when it gets unparseable XML" do
65
+ pending "need to implement error handling for bad xml"
66
+ end
67
+
26
68
  context "normalizing mods" do
27
69
  it "should not lose UTF-8 encoding" do
28
70
  utf_mods = '<?xml version="1.0" encoding="UTF-8"?>
29
- <mods:mods xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/1999/xlink"
71
+ <mods:mods xmlns:mods="http://www.loc.gov/mods/v3"
30
72
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.3"
31
73
  xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-3.xsd">
32
- <mods:name authority="local" type="personal">
33
- <mods:namePart>Gravé par Denise Macquart.</mods:namePart>
34
- </mods:name>
74
+ <mods:name authority="local" type="personal">
75
+ <mods:namePart>Gravé par Denise Macquart.</mods:namePart>
76
+ </mods:name>
35
77
  </mods:mods>'
36
78
  reader = Mods::Reader.new.from_str(utf_mods)
37
79
  reader.encoding.should eql("UTF-8")
38
80
  end
81
+ it "should remove xsi:schemaLocation attribute from mods element if removing namespaces" do
82
+ str = '<ns3:mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.loc.gov/mods/v3" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
83
+ <ns3:note>be very frightened</ns3:note></ns3:mods>'
84
+ ng_xml = Nokogiri::XML(str)
85
+ # Nokogiri treats namespaced attributes differently in jruby than in ruby
86
+ (ng_xml.root.has_attribute?('schemaLocation') || ng_xml.root.has_attribute?('xsi:schemaLocation')).should == true
87
+ r = Mods::Reader.new
88
+ r.namespace_aware = false
89
+ r.from_nk_node(ng_xml)
90
+ # the below are different depending on jruby or ruby ... oy
91
+ r.mods_ng_xml.root.attributes.keys.should_not include('schemaLocation')
92
+ r.mods_ng_xml.root.attributes.keys.should_not include('xsi:schemaLocation')
93
+ end
39
94
  end
40
95
 
41
96
  context "from_nk_node" do
@@ -61,63 +116,23 @@ describe "Mods::Reader" do
61
116
  </GetRecord>
62
117
  </OAI-PMH>'
63
118
  ng_xml = Nokogiri::XML(oai_resp)
64
- @mods_node = ng_xml.xpath('//mods:mods', @ns_hash).first
119
+ @mods_node = ng_xml.xpath('//m:mods', @ns_hash).first
65
120
  @r = Mods::Reader.new
66
121
  @mods_ng_doc = @r.from_nk_node(@mods_node)
67
122
  end
68
123
  it "should turn the Nokogiri::XML::Node into a Nokogiri::XML::Document object" do
69
124
  @mods_ng_doc.should be_kind_of(Nokogiri::XML::Document)
70
125
  end
71
- it "should not care about namespace by default" do
72
- @mods_ng_doc.xpath('/mods/titleInfo/title').text.should == "boo"
126
+ it "should care about namespace by default" do
127
+ @mods_ng_doc.xpath('/m:mods/m:titleInfo/m:title', @ns_hash).text.should == "boo"
73
128
  end
74
- it "should be able to care about namespaces" do
75
- @r.namespace_aware = true
76
- @mods_ng_doc = @r.from_nk_node(@mods_node)
77
- @mods_ng_doc.xpath('/mods:mods/mods:titleInfo/mods:title', @ns_hash).text.should == "boo"
129
+ it "should be able not to care about namespaces" do
78
130
  @r.namespace_aware = false
79
- end
80
-
81
- end
82
-
83
- context "namespace awareness" do
84
- it "should not care about namespace by default" do
85
- r = Mods::Reader.new
86
- r.namespace_aware.should == false
87
- @from_no_ns_str.xpath('/mods/note').text.should == "hi"
88
- @from_wrong_ns_str.xpath('/mods/note').text.should == "hi"
89
- # @from_no_ns_str.xpath('/mods:mods/mods:note', @ns_hash).text.should == ""
90
- # @from_wrong_ns_str.xpath('/mods:mods/mods:note', @ns_hash).text.should == ""
91
- end
92
-
93
- it "should be allowed to care about namespaces" do
94
- r = Mods::Reader.new
95
- r.namespace_aware = true
96
- r.from_url(@example_url).root.namespace.href.should == Mods::MODS_NS
97
- my_from_str_no_ns = r.from_str(@example_no_ns_str)
98
- my_from_str_no_ns.xpath('/mods:mods/mods:note', @ns_hash).text.should_not == "hi"
99
- my_from_str_wrong_ns = r.from_str(@example_wrong_ns_str)
100
- my_from_str_wrong_ns.root.namespace.href.should == 'whoops'
101
- my_from_str_wrong_ns.xpath('/mods:mods/mods:note', @ns_hash).text.should_not == "hi"
102
- my_from_str_wrong_ns.xpath('/mods/note').text.should_not == "hi"
103
- end
104
-
105
- it "should remove xsi:schemaLocation attribute from mods element if removing namespaces" do
106
- str = '<ns3:mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.loc.gov/mods/v3" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
107
- <ns3:note>be very frightened</ns3:note></ns3:mods>'
108
- ng_xml = Nokogiri::XML(str)
109
- # Nokogiri treats namespaced attributes differently in jruby than in ruby
110
- (ng_xml.root.has_attribute?('schemaLocation') || ng_xml.root.has_attribute?('xsi:schemaLocation')).should == true
111
- r = Mods::Reader.new
112
- r.namespace_aware = false
113
- r.from_nk_node(ng_xml)
114
- # the below are different depending on jruby or ruby ... oy
115
- r.mods_ng_xml.root.attributes.keys.should_not include('schemaLocation')
116
- r.mods_ng_xml.root.attributes.keys.should_not include('xsi:schemaLocation')
117
- end
118
- end
131
+ mods_ng_doc = @r.from_nk_node(@mods_node)
132
+ mods_ng_doc.xpath('/m:mods/m:titleInfo/m:title', @ns_hash).size.should == 0
133
+ mods_ng_doc.xpath('/mods/titleInfo/title').text.should == "boo"
134
+ @r.namespace_aware = true
135
+ end
136
+ end # context from_nk_node
119
137
 
120
- it "should do something useful when it gets unparseable XML" do
121
- pending "need to implement error handling for bad xml"
122
- end
123
138
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe "Mods <recordInfo> Element" do
4
4
  before(:all) do
5
5
  @mods_rec = Mods::Record.new
6
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
6
7
  end
7
8
 
8
9
  it "should translate language codes" do
@@ -14,238 +15,479 @@ describe "Mods <recordInfo> Element" do
14
15
  end
15
16
 
16
17
  context "basic <record_info> terminology pieces" do
17
- before(:all) do
18
- @rec_info = @mods_rec.from_str('<mods><recordInfo>
19
- <recordContentSource authority="marcorg">RQE</recordContentSource>
20
- <recordCreationDate encoding="marc">890517</recordCreationDate>
21
- <recordIdentifier source="SIRSI">a9079953</recordIdentifier>
22
- </recordInfo></mods>').record_info
23
- @rec_info2 = @mods_rec.from_str('<mods><recordInfo>
24
- <descriptionStandard>aacr2</descriptionStandard>
25
- <recordContentSource authority="marcorg">AU@</recordContentSource>
26
- <recordCreationDate encoding="marc">050921</recordCreationDate>
27
- <recordIdentifier source="SIRSI">a8837534</recordIdentifier>
28
- <languageOfCataloging>
29
- <languageTerm authority="iso639-2b" type="code">eng</languageTerm>
30
- </languageOfCataloging>
31
- </recordInfo></mods>').record_info
32
- @bnf = @mods_rec.from_str('<mods><recordInfo>
33
- <recordContentSource>TEI Description</recordContentSource>
34
- <recordCreationDate encoding="w3cdtf">2011-12-07</recordCreationDate>
35
- <recordIdentifier source="BNF 2166"/>
36
- <recordOrigin/>
37
- <languageOfCataloging>
38
- <languageTerm authority="iso639-2b">fra</languageTerm>
39
- </languageOfCataloging>
40
- </recordInfo></mods>').record_info
41
- @rlin = @mods_rec.from_str('<mods><recordInfo>
42
- <descriptionStandard>appm</descriptionStandard>
43
- <recordContentSource authority="marcorg">CSt</recordContentSource>
44
- <recordCreationDate encoding="marc">850416</recordCreationDate>
45
- <recordChangeDate encoding="iso8601">19991012150824.0</recordChangeDate>
46
- <recordIdentifier source="CStRLIN">a4083219</recordIdentifier>
47
- </recordInfo></mods>').record_info
48
- end
49
18
 
50
- it "should be a NodeSet" do
51
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.should be_an_instance_of(Nokogiri::XML::NodeSet) }
52
- end
53
- it "should have as many members as there are <recordInfo> elements in the xml" do
54
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.size.should == 1 }
55
- end
56
- it "should recognize language attributes on <recordInfo> element" do
57
- pending "problem with xml:lang"
58
- Mods::LANG_ATTRIBS.each { |a|
59
- @mods_rec.from_str("<mods><recordInfo #{a}='val'><recordOrigin>nowhere</recordOrigin></recordInfo></mods>")
60
- @mods_rec.record_info.send(a.to_sym).should == ['val']
61
- }
62
- end
63
- it "should recognize displayLabel attribute on <recordInfo> element" do
64
- @mods_rec.from_str("<mods><recordInfo displayLabel='val'><recordOrigin>nowhere</recordOrigin></recordInfo></mods>")
65
- @mods_rec.record_info.displayLabel.should == ['val']
66
- end
67
-
68
- context "<recordContentSource> child element" do
69
- it "should be a NodeSet" do
70
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordContentSource.should be_an_instance_of(Nokogiri::XML::NodeSet) }
71
- end
72
- it "recordContentSource NodeSet should have as many Nodes as there are <recordContentSource> elements in the xml" do
73
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordContentSource.size.should == 1 }
74
- end
75
- it "text should get element value" do
76
- @rec_info.recordContentSource.map { |n| n.text }.should == ["RQE"]
77
- @rec_info2.recordContentSource.map { |n| n.text }.should == ["AU@"]
78
- @bnf.recordContentSource.map { |n| n.text }.should == ["TEI Description"]
79
- @rlin.recordContentSource.map { |n| n.text }.should == ["CSt"]
19
+ context "WITH namespaces" do
20
+ before(:all) do
21
+ @rec_info = @mods_rec.from_str("<mods #{@ns_decl}><recordInfo>
22
+ <recordContentSource authority='marcorg'>RQE</recordContentSource>
23
+ <recordCreationDate encoding='marc'>890517</recordCreationDate>
24
+ <recordIdentifier source='SIRSI'>a9079953</recordIdentifier>
25
+ </recordInfo></mods>").record_info
26
+ @rec_info2 = @mods_rec.from_str("<mods #{@ns_decl}><recordInfo>
27
+ <descriptionStandard>aacr2</descriptionStandard>
28
+ <recordContentSource authority='marcorg'>AU@</recordContentSource>
29
+ <recordCreationDate encoding='marc'>050921</recordCreationDate>
30
+ <recordIdentifier source='SIRSI'>a8837534</recordIdentifier>
31
+ <languageOfCataloging>
32
+ <languageTerm authority='iso639-2b' type='code'>eng</languageTerm>
33
+ </languageOfCataloging>
34
+ </recordInfo></mods>").record_info
35
+ @bnf = @mods_rec.from_str("<mods #{@ns_decl}><recordInfo>
36
+ <recordContentSource>TEI Description</recordContentSource>
37
+ <recordCreationDate encoding='w3cdtf'>2011-12-07</recordCreationDate>
38
+ <recordIdentifier source='BNF 2166'/>
39
+ <recordOrigin/>
40
+ <languageOfCataloging>
41
+ <languageTerm authority='iso639-2b'>fra</languageTerm>
42
+ </languageOfCataloging>
43
+ </recordInfo></mods>").record_info
44
+ @rlin = @mods_rec.from_str("<mods #{@ns_decl}><recordInfo>
45
+ <descriptionStandard>appm</descriptionStandard>
46
+ <recordContentSource authority='marcorg'>CSt</recordContentSource>
47
+ <recordCreationDate encoding='marc'>850416</recordCreationDate>
48
+ <recordChangeDate encoding='iso8601'>19991012150824.0</recordChangeDate>
49
+ <recordIdentifier source='CStRLIN'>a4083219</recordIdentifier>
50
+ </recordInfo></mods>").record_info
80
51
  end
81
- it "should recognize authority attribute" do
82
- [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordContentSource.authority.should == ['marcorg'] }
83
- @bnf.recordContentSource.authority.size.should == 0
84
- end
85
- it "should recognize all authority attributes" do
86
- Mods::AUTHORITY_ATTRIBS.each { |a|
87
- @mods_rec.from_str("<mods><recordInfo><recordContentSource #{a}='attr_val'>zzz</recordContentSource></recordInfo></mods>")
88
- @mods_rec.record_info.recordContentSource.send(a.to_sym).should == ['attr_val']
89
- }
90
- end
91
- end # <recordContentSource>
92
52
 
93
- context "<recordCreationDate> child element" do
94
53
  it "should be a NodeSet" do
95
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordCreationDate.should be_an_instance_of(Nokogiri::XML::NodeSet) }
96
- end
97
- it "recordCreationDate NodeSet should have as many Nodes as there are <recordCreationDate> elements in the xml" do
98
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordCreationDate.size.should == 1 }
54
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.should be_an_instance_of(Nokogiri::XML::NodeSet) }
99
55
  end
100
- it "text should get element value" do
101
- @rec_info.recordCreationDate.map { |n| n.text }.should == ['890517']
102
- @rec_info2.recordCreationDate.map { |n| n.text }.should == ['050921']
103
- @bnf.recordCreationDate.map { |n| n.text }.should == ['2011-12-07']
104
- @rlin.recordCreationDate.map { |n| n.text }.should == ['850416']
56
+ it "should have as many members as there are <recordInfo> elements in the xml" do
57
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.size.should == 1 }
105
58
  end
106
- it "should recognize encoding attribute" do
107
- [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordCreationDate.encoding.should == ['marc'] }
108
- @bnf.recordCreationDate.encoding.should == ['w3cdtf']
109
- end
110
- it "should recognize all date attributes" do
111
- Mods::DATE_ATTRIBS.each { |a|
112
- @mods_rec.from_str("<mods><recordInfo><recordCreationDate #{a}='attr_val'>zzz</recordCreationDate></recordInfo></mods>")
113
- @mods_rec.record_info.recordCreationDate.send(a.to_sym).should == ['attr_val']
59
+ it "should recognize language attributes on <recordInfo> element" do
60
+ pending "problem with xml:lang"
61
+ Mods::LANG_ATTRIBS.each { |a|
62
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo #{a}='val'><recordOrigin>nowhere</recordOrigin></recordInfo></mods>")
63
+ @mods_rec.record_info.send(a.to_sym).should == ['val']
114
64
  }
115
65
  end
116
- end # <recordCreationDate>
117
-
118
- context "<recordChangeDate> child element" do
119
- it "should be a NodeSet" do
120
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordChangeDate.should be_an_instance_of(Nokogiri::XML::NodeSet) }
121
- end
122
- it "recordChangeDate NodeSet should have as many Nodes as there are <recordChangeDate> elements in the xml" do
123
- [@rec_info, @rec_info2, @bnf].each { |ri| ri.recordChangeDate.size.should == 0 }
124
- @rlin.recordChangeDate.size.should == 1
125
- end
126
- it "text should get element value" do
127
- @rlin.recordChangeDate.map { |n| n.text }.should == ['19991012150824.0']
66
+ it "should recognize displayLabel attribute on <recordInfo> element" do
67
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo displayLabel='val'><recordOrigin>nowhere</recordOrigin></recordInfo></mods>")
68
+ @mods_rec.record_info.displayLabel.should == ['val']
128
69
  end
129
- it "should recognize encoding attribute" do
130
- @rlin.recordChangeDate.encoding.should == ['iso8601']
131
- end
132
- it "should recognize all date attributes" do
133
- Mods::DATE_ATTRIBS.each { |a|
134
- @mods_rec.from_str("<mods><recordInfo><recordChangeDate #{a}='attr_val'>zzz</recordChangeDate></recordInfo></mods>")
135
- @mods_rec.record_info.recordChangeDate.send(a.to_sym).should == ['attr_val']
136
- }
137
- end
138
- end # <recordChangeDate>
139
70
 
140
- context "<recordIdentifier> child element" do
141
- it "should be a NodeSet" do
142
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordIdentifier.should be_an_instance_of(Nokogiri::XML::NodeSet) }
143
- end
144
- it "recordIdentifier NodeSet should have as many Nodes as there are <recordIdentifier> elements in the xml" do
145
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordIdentifier.size.should == 1 }
146
- end
147
- it "text should get element value" do
148
- @rec_info.recordIdentifier.map { |n| n.text }.should == ['a9079953']
149
- @rec_info2.recordIdentifier.map { |n| n.text }.should == ['a8837534']
150
- @bnf.recordIdentifier.map { |n| n.text }.should == ['']
151
- @rlin.recordIdentifier.map { |n| n.text }.should == ['a4083219']
152
- end
153
- it "should recognize source attribute" do
154
- [@rec_info, @rec_info2].each { |ri| ri.recordIdentifier.source.should == ['SIRSI'] }
155
- @bnf.recordIdentifier.source.should == ['BNF 2166']
156
- @rlin.recordIdentifier.source.should == ['CStRLIN']
157
- end
158
- it "should allow a source attribute without element content" do
159
- @bnf.recordIdentifier.source.should == ['BNF 2166']
160
- @bnf.recordIdentifier.map { |n| n.text }.should == ['']
161
- end
162
- end # <recordIdentifier>
71
+ context "<recordContentSource> child element" do
72
+ it "should be a NodeSet" do
73
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordContentSource.should be_an_instance_of(Nokogiri::XML::NodeSet) }
74
+ end
75
+ it "recordContentSource NodeSet should have as many Nodes as there are <recordContentSource> elements in the xml" do
76
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordContentSource.size.should == 1 }
77
+ end
78
+ it "text should get element value" do
79
+ @rec_info.recordContentSource.map { |n| n.text }.should == ["RQE"]
80
+ @rec_info2.recordContentSource.map { |n| n.text }.should == ["AU@"]
81
+ @bnf.recordContentSource.map { |n| n.text }.should == ["TEI Description"]
82
+ @rlin.recordContentSource.map { |n| n.text }.should == ["CSt"]
83
+ end
84
+ it "should recognize authority attribute" do
85
+ [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordContentSource.authority.should == ['marcorg'] }
86
+ @bnf.recordContentSource.authority.size.should == 0
87
+ end
88
+ it "should recognize all authority attributes" do
89
+ Mods::AUTHORITY_ATTRIBS.each { |a|
90
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><recordContentSource #{a}='attr_val'>zzz</recordContentSource></recordInfo></mods>")
91
+ @mods_rec.record_info.recordContentSource.send(a.to_sym).should == ['attr_val']
92
+ }
93
+ end
94
+ end # <recordContentSource>
163
95
 
164
- context "<recordOrigin> child element" do
165
- it "should be a NodeSet" do
166
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordOrigin.should be_an_instance_of(Nokogiri::XML::NodeSet) }
167
- end
168
- it "recordOrigin NodeSet should have as many Nodes as there are <recordOrigin> elements in the xml" do
169
- [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordOrigin.size.should == 0 }
170
- @bnf.recordOrigin.size.should == 1
171
- end
172
- it "text should get element value" do
173
- @mods_rec.from_str("<mods><recordInfo><recordOrigin>human prepared</recordOrigin></recordInfo></mods>")
174
- @mods_rec.record_info.recordOrigin.map {|n| n.text }.should == ['human prepared']
175
- @bnf.recordOrigin.map { |n| n.text }.should == ['']
96
+ context "<recordCreationDate> child element" do
97
+ it "should be a NodeSet" do
98
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordCreationDate.should be_an_instance_of(Nokogiri::XML::NodeSet) }
99
+ end
100
+ it "recordCreationDate NodeSet should have as many Nodes as there are <recordCreationDate> elements in the xml" do
101
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordCreationDate.size.should == 1 }
102
+ end
103
+ it "text should get element value" do
104
+ @rec_info.recordCreationDate.map { |n| n.text }.should == ['890517']
105
+ @rec_info2.recordCreationDate.map { |n| n.text }.should == ['050921']
106
+ @bnf.recordCreationDate.map { |n| n.text }.should == ['2011-12-07']
107
+ @rlin.recordCreationDate.map { |n| n.text }.should == ['850416']
108
+ end
109
+ it "should recognize encoding attribute" do
110
+ [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordCreationDate.encoding.should == ['marc'] }
111
+ @bnf.recordCreationDate.encoding.should == ['w3cdtf']
112
+ end
113
+ it "should recognize all date attributes" do
114
+ Mods::DATE_ATTRIBS.each { |a|
115
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><recordCreationDate #{a}='attr_val'>zzz</recordCreationDate></recordInfo></mods>")
116
+ @mods_rec.record_info.recordCreationDate.send(a.to_sym).should == ['attr_val']
117
+ }
118
+ end
119
+ end # <recordCreationDate>
120
+
121
+ context "<recordChangeDate> child element" do
122
+ it "should be a NodeSet" do
123
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordChangeDate.should be_an_instance_of(Nokogiri::XML::NodeSet) }
124
+ end
125
+ it "recordChangeDate NodeSet should have as many Nodes as there are <recordChangeDate> elements in the xml" do
126
+ [@rec_info, @rec_info2, @bnf].each { |ri| ri.recordChangeDate.size.should == 0 }
127
+ @rlin.recordChangeDate.size.should == 1
128
+ end
129
+ it "text should get element value" do
130
+ @rlin.recordChangeDate.map { |n| n.text }.should == ['19991012150824.0']
131
+ end
132
+ it "should recognize encoding attribute" do
133
+ @rlin.recordChangeDate.encoding.should == ['iso8601']
134
+ end
135
+ it "should recognize all date attributes" do
136
+ Mods::DATE_ATTRIBS.each { |a|
137
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><recordChangeDate #{a}='attr_val'>zzz</recordChangeDate></recordInfo></mods>")
138
+ @mods_rec.record_info.recordChangeDate.send(a.to_sym).should == ['attr_val']
139
+ }
140
+ end
141
+ end # <recordChangeDate>
142
+
143
+ context "<recordIdentifier> child element" do
144
+ it "should be a NodeSet" do
145
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordIdentifier.should be_an_instance_of(Nokogiri::XML::NodeSet) }
146
+ end
147
+ it "recordIdentifier NodeSet should have as many Nodes as there are <recordIdentifier> elements in the xml" do
148
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordIdentifier.size.should == 1 }
149
+ end
150
+ it "text should get element value" do
151
+ @rec_info.recordIdentifier.map { |n| n.text }.should == ['a9079953']
152
+ @rec_info2.recordIdentifier.map { |n| n.text }.should == ['a8837534']
153
+ @bnf.recordIdentifier.map { |n| n.text }.should == ['']
154
+ @rlin.recordIdentifier.map { |n| n.text }.should == ['a4083219']
155
+ end
156
+ it "should recognize source attribute" do
157
+ [@rec_info, @rec_info2].each { |ri| ri.recordIdentifier.source.should == ['SIRSI'] }
158
+ @bnf.recordIdentifier.source.should == ['BNF 2166']
159
+ @rlin.recordIdentifier.source.should == ['CStRLIN']
160
+ end
161
+ it "should allow a source attribute without element content" do
162
+ @bnf.recordIdentifier.source.should == ['BNF 2166']
163
+ @bnf.recordIdentifier.map { |n| n.text }.should == ['']
164
+ end
165
+ end # <recordIdentifier>
166
+
167
+ context "<recordOrigin> child element" do
168
+ it "should be a NodeSet" do
169
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordOrigin.should be_an_instance_of(Nokogiri::XML::NodeSet) }
170
+ end
171
+ it "recordOrigin NodeSet should have as many Nodes as there are <recordOrigin> elements in the xml" do
172
+ [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordOrigin.size.should == 0 }
173
+ @bnf.recordOrigin.size.should == 1
174
+ end
175
+ it "text should get element value" do
176
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><recordOrigin>human prepared</recordOrigin></recordInfo></mods>")
177
+ @mods_rec.record_info.recordOrigin.map {|n| n.text }.should == ['human prepared']
178
+ @bnf.recordOrigin.map { |n| n.text }.should == ['']
179
+ end
180
+ end # <recordOrigin>
181
+
182
+ context "<languageOfCataloging> child element" do
183
+ it "should be a NodeSet" do
184
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.languageOfCataloging.should be_an_instance_of(Nokogiri::XML::NodeSet) }
185
+ end
186
+ it "languageOfCataloging NodeSet should have as many Nodes as there are <languageOfCataloging> elements in the xml" do
187
+ [@rec_info2, @bnf].each { |ri| ri.languageOfCataloging.size.should == 1 }
188
+ [@rec_info, @rlin].each { |ri| ri.languageOfCataloging.size.should == 0 }
189
+ end
190
+ it "text should get element value" do
191
+ # this example is from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html
192
+ # though it doesn't match the doc at http://www.loc.gov/standards/mods/mods-outline.html#recordInfo
193
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><languageOfCataloging authority='iso639-2b'>fre</languageOfCataloging></recordInfo></mods>")
194
+ @mods_rec.record_info.languageOfCataloging.map { |n| n.text }.should == ['fre']
195
+ end
196
+ it "authority should get attribute value" do
197
+ # this example is from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html
198
+ # though it doesn't match the doc at http://www.loc.gov/standards/mods/mods-outline.html#recordInfo
199
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><languageOfCataloging authority='iso639-2b'>fre</languageOfCataloging></recordInfo></mods>")
200
+ @mods_rec.record_info.languageOfCataloging.authority.should == ['iso639-2b']
201
+ end
202
+
203
+ # from http://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging
204
+ # objectPart attribute defined for consistency with <language> . Unlikely to be used with <languageOfCataloging>
205
+ it "objectType should get attribute value" do
206
+ pending "<languageOfCataloging objectType=''> to be implemented ... maybe ..."
207
+ end
208
+
209
+ context "<languageTerm> child element" do
210
+ it "text should get element value" do
211
+ @rec_info2.languageOfCataloging.languageTerm.map { |n| n.text }.should == ['eng']
212
+ @bnf.languageOfCataloging.languageTerm.map { |n| n.text }.should == ['fra']
213
+ end
214
+ it "should recognize all authority attributes" do
215
+ Mods::AUTHORITY_ATTRIBS.each { |a|
216
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><languageOfCataloging><languageTerm #{a}='attr_val'>zzz</languageTerm></languageOfCataloging></recordInfo></mods>")
217
+ @mods_rec.record_info.languageOfCataloging.languageTerm.send(a.to_sym).should == ['attr_val']
218
+ }
219
+ end
220
+ it "should recognize the type attribute with type_at term" do
221
+ @rec_info2.languageOfCataloging.languageTerm.type_at.should == ['code']
222
+ end
223
+ end # <languageTerm>
224
+
225
+ context "<scriptTerm> child element" do
226
+ it "should do something" do
227
+ pending "<recordInfo><languageOfCataloging><scriptTerm> to be implemented"
228
+ end
229
+ end
230
+ end # <languageOfCataloging>
231
+
232
+ context "<descriptionStandard> child element" do
233
+ it "should be a NodeSet" do
234
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.descriptionStandard.should be_an_instance_of(Nokogiri::XML::NodeSet) }
235
+ end
236
+ it "descriptionStandard NodeSet should have as many Nodes as there are <descriptionStandard> elements in the xml" do
237
+ [@rec_info, @bnf].each { |ri| ri.descriptionStandard.size.should == 0 }
238
+ [@rec_info2, @rlin].each { |ri| ri.descriptionStandard.size.should == 1 }
239
+ end
240
+ it "text should get element value" do
241
+ @rec_info2.descriptionStandard.map { |n| n.text }.should == ['aacr2']
242
+ @rlin.descriptionStandard.map { |n| n.text }.should == ['appm']
243
+ @bnf.descriptionStandard.map { |n| n.text }.should == []
244
+ end
245
+ it "should recognize all authority attributes" do
246
+ Mods::AUTHORITY_ATTRIBS.each { |a|
247
+ @mods_rec.from_str("<mods #{@ns_decl}><recordInfo><descriptionStandard #{a}='attr_val'>zzz</descriptionStandard></recordInfo></mods>")
248
+ @mods_rec.record_info.descriptionStandard.send(a.to_sym).should == ['attr_val']
249
+ }
250
+ end
251
+ end # <descriptionStandard>
252
+
253
+ end # WITH namespaces
254
+
255
+ context "WITHOUT namespaces" do
256
+ before(:all) do
257
+ @rec_info = @mods_rec.from_str("<mods><recordInfo>
258
+ <recordContentSource authority='marcorg'>RQE</recordContentSource>
259
+ <recordCreationDate encoding='marc'>890517</recordCreationDate>
260
+ <recordIdentifier source='SIRSI'>a9079953</recordIdentifier>
261
+ </recordInfo></mods>", false).record_info
262
+ @rec_info2 = @mods_rec.from_str("<mods><recordInfo>
263
+ <descriptionStandard>aacr2</descriptionStandard>
264
+ <recordContentSource authority='marcorg'>AU@</recordContentSource>
265
+ <recordCreationDate encoding='marc'>050921</recordCreationDate>
266
+ <recordIdentifier source='SIRSI'>a8837534</recordIdentifier>
267
+ <languageOfCataloging>
268
+ <languageTerm authority='iso639-2b' type='code'>eng</languageTerm>
269
+ </languageOfCataloging>
270
+ </recordInfo></mods>", false).record_info
271
+ @bnf = @mods_rec.from_str("<mods><recordInfo>
272
+ <recordContentSource>TEI Description</recordContentSource>
273
+ <recordCreationDate encoding='w3cdtf'>2011-12-07</recordCreationDate>
274
+ <recordIdentifier source='BNF 2166'/>
275
+ <recordOrigin/>
276
+ <languageOfCataloging>
277
+ <languageTerm authority='iso639-2b'>fra</languageTerm>
278
+ </languageOfCataloging>
279
+ </recordInfo></mods>", false).record_info
280
+ @rlin = @mods_rec.from_str("<mods><recordInfo>
281
+ <descriptionStandard>appm</descriptionStandard>
282
+ <recordContentSource authority='marcorg'>CSt</recordContentSource>
283
+ <recordCreationDate encoding='marc'>850416</recordCreationDate>
284
+ <recordChangeDate encoding='iso8601'>19991012150824.0</recordChangeDate>
285
+ <recordIdentifier source='CStRLIN'>a4083219</recordIdentifier>
286
+ </recordInfo></mods>", false).record_info
176
287
  end
177
- end # <recordOrigin>
178
288
 
179
- context "<languageOfCataloging> child element" do
180
289
  it "should be a NodeSet" do
181
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.languageOfCataloging.should be_an_instance_of(Nokogiri::XML::NodeSet) }
290
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.should be_an_instance_of(Nokogiri::XML::NodeSet) }
182
291
  end
183
- it "languageOfCataloging NodeSet should have as many Nodes as there are <languageOfCataloging> elements in the xml" do
184
- [@rec_info2, @bnf].each { |ri| ri.languageOfCataloging.size.should == 1 }
185
- [@rec_info, @rlin].each { |ri| ri.languageOfCataloging.size.should == 0 }
292
+ it "should have as many members as there are <recordInfo> elements in the xml" do
293
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.size.should == 1 }
186
294
  end
187
- it "text should get element value" do
188
- # this example is from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html
189
- # though it doesn't match the doc at http://www.loc.gov/standards/mods/mods-outline.html#recordInfo
190
- @mods_rec.from_str("<mods><recordInfo><languageOfCataloging authority='iso639-2b'>fre</languageOfCataloging></recordInfo></mods>")
191
- @mods_rec.record_info.languageOfCataloging.map { |n| n.text }.should == ['fre']
192
- end
193
- it "authority should get attribute value" do
194
- # this example is from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html
195
- # though it doesn't match the doc at http://www.loc.gov/standards/mods/mods-outline.html#recordInfo
196
- @mods_rec.from_str("<mods><recordInfo><languageOfCataloging authority='iso639-2b'>fre</languageOfCataloging></recordInfo></mods>")
197
- @mods_rec.record_info.languageOfCataloging.authority.should == ['iso639-2b']
295
+ it "should recognize language attributes on <recordInfo> element" do
296
+ pending "problem with xml:lang"
297
+ Mods::LANG_ATTRIBS.each { |a|
298
+ @mods_rec.from_str("<mods><recordInfo #{a}='val'><recordOrigin>nowhere</recordOrigin></recordInfo></mods>", false)
299
+ @mods_rec.record_info.send(a.to_sym).should == ['val']
300
+ }
198
301
  end
199
-
200
- # from http://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging
201
- # objectPart attribute defined for consistency with <language> . Unlikely to be used with <languageOfCataloging>
202
- it "objectType should get attribute value" do
203
- pending "<languageOfCataloging objectType=''> to be implemented ... maybe ..."
302
+ it "should recognize displayLabel attribute on <recordInfo> element" do
303
+ @mods_rec.from_str("<mods><recordInfo displayLabel='val'><recordOrigin>nowhere</recordOrigin></recordInfo></mods>", false)
304
+ @mods_rec.record_info.displayLabel.should == ['val']
204
305
  end
205
-
206
- context "<languageTerm> child element" do
306
+
307
+ context "<recordContentSource> child element" do
308
+ it "should be a NodeSet" do
309
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordContentSource.should be_an_instance_of(Nokogiri::XML::NodeSet) }
310
+ end
311
+ it "recordContentSource NodeSet should have as many Nodes as there are <recordContentSource> elements in the xml" do
312
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordContentSource.size.should == 1 }
313
+ end
207
314
  it "text should get element value" do
208
- @rec_info2.languageOfCataloging.languageTerm.map { |n| n.text }.should == ['eng']
209
- @bnf.languageOfCataloging.languageTerm.map { |n| n.text }.should == ['fra']
315
+ @rec_info.recordContentSource.map { |n| n.text }.should == ["RQE"]
316
+ @rec_info2.recordContentSource.map { |n| n.text }.should == ["AU@"]
317
+ @bnf.recordContentSource.map { |n| n.text }.should == ["TEI Description"]
318
+ @rlin.recordContentSource.map { |n| n.text }.should == ["CSt"]
319
+ end
320
+ it "should recognize authority attribute" do
321
+ [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordContentSource.authority.should == ['marcorg'] }
322
+ @bnf.recordContentSource.authority.size.should == 0
210
323
  end
211
324
  it "should recognize all authority attributes" do
212
- Mods::AUTHORITY_ATTRIBS.each { |a|
213
- @mods_rec.from_str("<mods><recordInfo><languageOfCataloging><languageTerm #{a}='attr_val'>zzz</languageTerm></languageOfCataloging></recordInfo></mods>")
214
- @mods_rec.record_info.languageOfCataloging.languageTerm.send(a.to_sym).should == ['attr_val']
325
+ Mods::AUTHORITY_ATTRIBS.each { |a|
326
+ @mods_rec.from_str("<mods><recordInfo><recordContentSource #{a}='attr_val'>zzz</recordContentSource></recordInfo></mods>", false)
327
+ @mods_rec.record_info.recordContentSource.send(a.to_sym).should == ['attr_val']
215
328
  }
216
329
  end
217
- it "should recognize the type attribute with type_at term" do
218
- @rec_info2.languageOfCataloging.languageTerm.type_at.should == ['code']
330
+ end # <recordContentSource>
331
+
332
+ context "<recordCreationDate> child element" do
333
+ it "should be a NodeSet" do
334
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordCreationDate.should be_an_instance_of(Nokogiri::XML::NodeSet) }
335
+ end
336
+ it "recordCreationDate NodeSet should have as many Nodes as there are <recordCreationDate> elements in the xml" do
337
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordCreationDate.size.should == 1 }
219
338
  end
220
- end # <languageTerm>
221
-
222
- context "<scriptTerm> child element" do
223
- it "should do something" do
224
- pending "<recordInfo><languageOfCataloging><scriptTerm> to be implemented"
339
+ it "text should get element value" do
340
+ @rec_info.recordCreationDate.map { |n| n.text }.should == ['890517']
341
+ @rec_info2.recordCreationDate.map { |n| n.text }.should == ['050921']
342
+ @bnf.recordCreationDate.map { |n| n.text }.should == ['2011-12-07']
343
+ @rlin.recordCreationDate.map { |n| n.text }.should == ['850416']
225
344
  end
226
- end
227
- end # <languageOfCataloging>
345
+ it "should recognize encoding attribute" do
346
+ [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordCreationDate.encoding.should == ['marc'] }
347
+ @bnf.recordCreationDate.encoding.should == ['w3cdtf']
348
+ end
349
+ it "should recognize all date attributes" do
350
+ Mods::DATE_ATTRIBS.each { |a|
351
+ @mods_rec.from_str("<mods><recordInfo><recordCreationDate #{a}='attr_val'>zzz</recordCreationDate></recordInfo></mods>", false)
352
+ @mods_rec.record_info.recordCreationDate.send(a.to_sym).should == ['attr_val']
353
+ }
354
+ end
355
+ end # <recordCreationDate>
228
356
 
229
- context "<descriptionStandard> child element" do
230
- it "should be a NodeSet" do
231
- [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.descriptionStandard.should be_an_instance_of(Nokogiri::XML::NodeSet) }
232
- end
233
- it "descriptionStandard NodeSet should have as many Nodes as there are <descriptionStandard> elements in the xml" do
234
- [@rec_info, @bnf].each { |ri| ri.descriptionStandard.size.should == 0 }
235
- [@rec_info2, @rlin].each { |ri| ri.descriptionStandard.size.should == 1 }
236
- end
237
- it "text should get element value" do
238
- @rec_info2.descriptionStandard.map { |n| n.text }.should == ['aacr2']
239
- @rlin.descriptionStandard.map { |n| n.text }.should == ['appm']
240
- @bnf.descriptionStandard.map { |n| n.text }.should == []
241
- end
242
- it "should recognize all authority attributes" do
243
- Mods::AUTHORITY_ATTRIBS.each { |a|
244
- @mods_rec.from_str("<mods><recordInfo><descriptionStandard #{a}='attr_val'>zzz</descriptionStandard></recordInfo></mods>")
245
- @mods_rec.record_info.descriptionStandard.send(a.to_sym).should == ['attr_val']
246
- }
247
- end
248
- end # <descriptionStandard>
357
+ context "<recordChangeDate> child element" do
358
+ it "should be a NodeSet" do
359
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordChangeDate.should be_an_instance_of(Nokogiri::XML::NodeSet) }
360
+ end
361
+ it "recordChangeDate NodeSet should have as many Nodes as there are <recordChangeDate> elements in the xml" do
362
+ [@rec_info, @rec_info2, @bnf].each { |ri| ri.recordChangeDate.size.should == 0 }
363
+ @rlin.recordChangeDate.size.should == 1
364
+ end
365
+ it "text should get element value" do
366
+ @rlin.recordChangeDate.map { |n| n.text }.should == ['19991012150824.0']
367
+ end
368
+ it "should recognize encoding attribute" do
369
+ @rlin.recordChangeDate.encoding.should == ['iso8601']
370
+ end
371
+ it "should recognize all date attributes" do
372
+ Mods::DATE_ATTRIBS.each { |a|
373
+ @mods_rec.from_str("<mods><recordInfo><recordChangeDate #{a}='attr_val'>zzz</recordChangeDate></recordInfo></mods>", false)
374
+ @mods_rec.record_info.recordChangeDate.send(a.to_sym).should == ['attr_val']
375
+ }
376
+ end
377
+ end # <recordChangeDate>
378
+
379
+ context "<recordIdentifier> child element" do
380
+ it "should be a NodeSet" do
381
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordIdentifier.should be_an_instance_of(Nokogiri::XML::NodeSet) }
382
+ end
383
+ it "recordIdentifier NodeSet should have as many Nodes as there are <recordIdentifier> elements in the xml" do
384
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordIdentifier.size.should == 1 }
385
+ end
386
+ it "text should get element value" do
387
+ @rec_info.recordIdentifier.map { |n| n.text }.should == ['a9079953']
388
+ @rec_info2.recordIdentifier.map { |n| n.text }.should == ['a8837534']
389
+ @bnf.recordIdentifier.map { |n| n.text }.should == ['']
390
+ @rlin.recordIdentifier.map { |n| n.text }.should == ['a4083219']
391
+ end
392
+ it "should recognize source attribute" do
393
+ [@rec_info, @rec_info2].each { |ri| ri.recordIdentifier.source.should == ['SIRSI'] }
394
+ @bnf.recordIdentifier.source.should == ['BNF 2166']
395
+ @rlin.recordIdentifier.source.should == ['CStRLIN']
396
+ end
397
+ it "should allow a source attribute without element content" do
398
+ @bnf.recordIdentifier.source.should == ['BNF 2166']
399
+ @bnf.recordIdentifier.map { |n| n.text }.should == ['']
400
+ end
401
+ end # <recordIdentifier>
249
402
 
403
+ context "<recordOrigin> child element" do
404
+ it "should be a NodeSet" do
405
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.recordOrigin.should be_an_instance_of(Nokogiri::XML::NodeSet) }
406
+ end
407
+ it "recordOrigin NodeSet should have as many Nodes as there are <recordOrigin> elements in the xml" do
408
+ [@rec_info, @rec_info2, @rlin].each { |ri| ri.recordOrigin.size.should == 0 }
409
+ @bnf.recordOrigin.size.should == 1
410
+ end
411
+ it "text should get element value" do
412
+ @mods_rec.from_str("<mods><recordInfo><recordOrigin>human prepared</recordOrigin></recordInfo></mods>", false)
413
+ @mods_rec.record_info.recordOrigin.map {|n| n.text }.should == ['human prepared']
414
+ @bnf.recordOrigin.map { |n| n.text }.should == ['']
415
+ end
416
+ end # <recordOrigin>
417
+
418
+ context "<languageOfCataloging> child element" do
419
+ it "should be a NodeSet" do
420
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.languageOfCataloging.should be_an_instance_of(Nokogiri::XML::NodeSet) }
421
+ end
422
+ it "languageOfCataloging NodeSet should have as many Nodes as there are <languageOfCataloging> elements in the xml" do
423
+ [@rec_info2, @bnf].each { |ri| ri.languageOfCataloging.size.should == 1 }
424
+ [@rec_info, @rlin].each { |ri| ri.languageOfCataloging.size.should == 0 }
425
+ end
426
+ it "text should get element value" do
427
+ # this example is from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html
428
+ # though it doesn't match the doc at http://www.loc.gov/standards/mods/mods-outline.html#recordInfo
429
+ @mods_rec.from_str("<mods><recordInfo><languageOfCataloging authority='iso639-2b'>fre</languageOfCataloging></recordInfo></mods>", false)
430
+ @mods_rec.record_info.languageOfCataloging.map { |n| n.text }.should == ['fre']
431
+ end
432
+ it "authority should get attribute value" do
433
+ # this example is from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html
434
+ # though it doesn't match the doc at http://www.loc.gov/standards/mods/mods-outline.html#recordInfo
435
+ @mods_rec.from_str("<mods><recordInfo><languageOfCataloging authority='iso639-2b'>fre</languageOfCataloging></recordInfo></mods>", false)
436
+ @mods_rec.record_info.languageOfCataloging.authority.should == ['iso639-2b']
437
+ end
438
+
439
+ # from http://www.loc.gov/standards/mods/userguide/recordinfo.html#languageofcataloging
440
+ # objectPart attribute defined for consistency with <language> . Unlikely to be used with <languageOfCataloging>
441
+ it "objectType should get attribute value" do
442
+ pending "<languageOfCataloging objectType=''> to be implemented ... maybe ..."
443
+ end
444
+
445
+ context "<languageTerm> child element" do
446
+ it "text should get element value" do
447
+ @rec_info2.languageOfCataloging.languageTerm.map { |n| n.text }.should == ['eng']
448
+ @bnf.languageOfCataloging.languageTerm.map { |n| n.text }.should == ['fra']
449
+ end
450
+ it "should recognize all authority attributes" do
451
+ Mods::AUTHORITY_ATTRIBS.each { |a|
452
+ @mods_rec.from_str("<mods><recordInfo><languageOfCataloging><languageTerm #{a}='attr_val'>zzz</languageTerm></languageOfCataloging></recordInfo></mods>", false)
453
+ @mods_rec.record_info.languageOfCataloging.languageTerm.send(a.to_sym).should == ['attr_val']
454
+ }
455
+ end
456
+ it "should recognize the type attribute with type_at term" do
457
+ @rec_info2.languageOfCataloging.languageTerm.type_at.should == ['code']
458
+ end
459
+ end # <languageTerm>
460
+
461
+ context "<scriptTerm> child element" do
462
+ it "should do something" do
463
+ pending "<recordInfo><languageOfCataloging><scriptTerm> to be implemented"
464
+ end
465
+ end
466
+ end # <languageOfCataloging>
467
+
468
+ context "<descriptionStandard> child element" do
469
+ it "should be a NodeSet" do
470
+ [@rec_info, @rec_info2, @bnf, @rlin].each { |ri| ri.descriptionStandard.should be_an_instance_of(Nokogiri::XML::NodeSet) }
471
+ end
472
+ it "descriptionStandard NodeSet should have as many Nodes as there are <descriptionStandard> elements in the xml" do
473
+ [@rec_info, @bnf].each { |ri| ri.descriptionStandard.size.should == 0 }
474
+ [@rec_info2, @rlin].each { |ri| ri.descriptionStandard.size.should == 1 }
475
+ end
476
+ it "text should get element value" do
477
+ @rec_info2.descriptionStandard.map { |n| n.text }.should == ['aacr2']
478
+ @rlin.descriptionStandard.map { |n| n.text }.should == ['appm']
479
+ @bnf.descriptionStandard.map { |n| n.text }.should == []
480
+ end
481
+ it "should recognize all authority attributes" do
482
+ Mods::AUTHORITY_ATTRIBS.each { |a|
483
+ @mods_rec.from_str("<mods><recordInfo><descriptionStandard #{a}='attr_val'>zzz</descriptionStandard></recordInfo></mods>", false)
484
+ @mods_rec.record_info.descriptionStandard.send(a.to_sym).should == ['attr_val']
485
+ }
486
+ end
487
+ end # <descriptionStandard>
488
+
489
+ end # WITHOUT namespaces
490
+
250
491
  end # basic <record_info> terminology pieces
492
+
251
493
  end