stanford-mods 0.0.23 → 0.0.24

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.
@@ -1,384 +1,395 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "Searchworks mixin for Stanford::Mods::Record" do
4
+ describe "Searchworks Subject fields from Searchworks mixin for Stanford::Mods::Record" do
5
5
 
6
6
  before(:all) do
7
7
  @smods_rec = Stanford::Mods::Record.new
8
8
  @ns_decl = "xmlns='#{Mods::MODS_NS}'"
9
+ @genre = 'genre top level'
10
+ @cart_coord = '6 00 S, 71 30 E'
11
+ @s_genre = 'genre in subject'
12
+ @geo = 'Somewhere'
13
+ @geo_code = 'us'
14
+ @hier_geo_country = 'France'
15
+ @s_name = 'name in subject'
16
+ @occupation = 'worker bee'
17
+ @temporal = 'temporal'
18
+ @s_title = 'title in subject'
19
+ @topic = 'topic'
20
+ @subject_mods = "<mods #{@ns_decl}>
21
+ <genre>#{@genre}</genre>
22
+ <subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
23
+ <subject><genre>#{@s_genre}</genre></subject>
24
+ <subject><geographic>#{@geo}</geographic></subject>
25
+ <subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
26
+ <subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
27
+ <subject><name><namePart>#{@s_name}</namePart></name></subject>
28
+ <subject><occupation>#{@occupation}</occupation></subject>
29
+ <subject><temporal>#{@temporal}</temporal></subject>
30
+ <subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
31
+ <subject><topic>#{@topic}</topic></subject>
32
+ </mods>"
33
+ @smods_rec = Stanford::Mods::Record.new
34
+ @smods_rec.from_str(@subject_mods)
35
+ @ng_mods = Nokogiri::XML(@subject_mods)
36
+ m_no_subject = "<mods #{@ns_decl}><note>notit</note></mods>"
37
+ @ng_mods_no_subject = Nokogiri::XML(m_no_subject)
9
38
  end
10
39
 
11
- context "sw subject methods" do
12
- before(:all) do
13
- @genre = 'genre top level'
14
- @cart_coord = '6 00 S, 71 30 E'
15
- @s_genre = 'genre in subject'
16
- @geo = 'Somewhere'
17
- @geo_code = 'us'
18
- @hier_geo_country = 'France'
19
- @s_name = 'name in subject'
20
- @occupation = 'worker bee'
21
- @temporal = 'temporal'
22
- @s_title = 'title in subject'
23
- @topic = 'topic'
24
- m = "<mods #{@ns_decl}>
25
- <genre>#{@genre}</genre>
26
- <subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
27
- <subject><genre>#{@s_genre}</genre></subject>
28
- <subject><geographic>#{@geo}</geographic></subject>
29
- <subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
30
- <subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
31
- <subject><name><namePart>#{@s_name}</namePart></name></subject>
32
- <subject><occupation>#{@occupation}</occupation></subject>
33
- <subject><temporal>#{@temporal}</temporal></subject>
34
- <subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
35
- <subject><topic>#{@topic}</topic></subject>
36
- </mods>"
37
- @smods_rec.from_str m
38
- @sw_geographic_search = @smods_rec.sw_geographic_search
39
- @sw_subject_titles = @smods_rec.sw_subject_titles
40
- @sw_subject_names = @smods_rec.sw_subject_names
41
- end
42
-
43
- context "sw_subject_names" do
44
- it "should contain <subject><name><namePart> values" do
45
- @sw_subject_names.should include(@s_name)
46
- end
47
- it "should not contain non-name subject subelements" do
48
- @sw_subject_names.should_not include(@cart_coord)
49
- @sw_subject_names.should_not include(@s_genre)
50
- @sw_subject_names.should_not include(@geo)
51
- @sw_subject_names.should_not include(@geo_code)
52
- @sw_subject_names.should_not include(@hier_geo_country)
53
- @sw_subject_names.should_not include(@occupation)
54
- @sw_subject_names.should_not include(@temporal)
55
- @sw_subject_names.should_not include(@topic)
56
- @sw_subject_names.should_not include(@s_title)
57
- end
58
- it "should not contain subject/name/role" do
59
- m = "<mods #{@ns_decl}>
60
- <subject><name type='personal'>
61
- <namePart>Alterman, Eric</namePart>
62
- <displayForm>Eric Alterman</displayForm>
63
- <role>
64
- <roleTerm type='text'>creator</roleTerm>
65
- <roleTerm type='code'>cre</roleTerm>
66
- </role>
67
- </name></subject></mods>"
68
- @smods_rec.from_str m
69
- @smods_rec.sw_subject_names.find { |sn| sn =~ /cre/ }.should == nil
70
- end
71
- it "should not contain subject/name/affiliation" do
72
- m = "<mods #{@ns_decl}>
73
- <subject><name type='personal'>
74
- <namePart type='termsOfAddress'>Dr.</namePart>
75
- <namePart>Brown, B. F.</namePart>
76
- <affiliation>Chemistry Dept., American University</affiliation>
77
- </name></subject></mods>"
78
- @smods_rec.from_str m
79
- @smods_rec.sw_subject_names.find { |sn| sn =~ /Chemistry/ }.should == nil
80
- end
81
- it "should not contain subject/name/description" do
82
- m = "<mods #{@ns_decl}>
83
- <subject><name type='personal'>
84
- <namePart>Abrams, Michael</namePart>
85
- <description>American artist, 20th c.</description>
86
- </name></subject></mods>"
87
- @smods_rec.from_str m
88
- @smods_rec.sw_subject_names.find { |sn| sn =~ /artist/ }.should == nil
89
- end
90
- it "should not include top level name element" do
91
- m = "<mods #{@ns_decl}>
92
- <name type='personal'>
93
- <namePart>Abrams, Michael</namePart>
94
- <description>American artist, 20th c.</description>
95
- </name></mods>"
96
- @smods_rec.from_str m
97
- @smods_rec.sw_subject_names.should == []
98
- end
99
- it "should have one value for each name element" do
100
- m = "<mods #{@ns_decl}>
101
- <subject>
102
- <name><namePart>first</namePart></name>
103
- <name><namePart>second</namePart></name>
104
- </subject>
105
- <subject>
106
- <name><namePart>third</namePart></name>
107
- </subject>
108
- </mods>"
109
- @smods_rec.from_str m
110
- @smods_rec.sw_subject_names.should == ['first', 'second', 'third']
111
- end
112
- it "should be an empty Array if there are no values in the mods" do
113
- m = "<mods #{@ns_decl}><note>notit</note></mods>"
114
- @smods_rec.from_str m
115
- @smods_rec.sw_subject_names.should == []
116
- end
117
- it "should be an empty Array if there are empty values in the mods" do
118
- m = "<mods #{@ns_decl}><subject><name><namePart/></name></subject><note>notit</note></mods>"
119
- @smods_rec.from_str m
120
- @smods_rec.sw_subject_names.should == []
121
- end
122
- context "combining subelements" do
123
- before(:all) do
124
- m = "<mods #{@ns_decl}>
125
- <subject>
126
- <name>
127
- <namePart>first</namePart>
128
- <namePart>second</namePart>
129
- </name>
130
- </subject>
131
- </mods>"
132
- @smods_rec.from_str m
133
- end
134
- it "uses a ', ' as the separator by default" do
135
- @smods_rec.sw_subject_names.should == ['first, second']
136
- end
137
- it "honors any string value passed in for the separator" do
138
- @smods_rec.sw_subject_names(' --').should == ['first --second']
139
- end
40
+ context "search fields" do
41
+ context "topic_search" do
42
+ it "should be nil if there are no values in the MODS" do
43
+ m = "<mods #{@ns_decl}></mods>"
44
+ @smods_rec = Stanford::Mods::Record.new
45
+ @smods_rec.from_str(m)
46
+ @smods_rec.topic_search.should == nil
140
47
  end
141
- end # sw_subject_names
142
-
143
- context "sw_subject_titles" do
144
- it "should contain <subject><titleInfo> subelement values" do
145
- @sw_subject_titles.should include(@s_title)
146
- end
147
- it "should not contain non-name subject subelements" do
148
- @sw_subject_titles.should_not include(@cart_coord)
149
- @sw_subject_titles.should_not include(@s_genre)
150
- @sw_subject_titles.should_not include(@geo)
151
- @sw_subject_titles.should_not include(@geo_code)
152
- @sw_subject_titles.should_not include(@hier_geo_country)
153
- @sw_subject_titles.should_not include(@s_name)
154
- @sw_subject_titles.should_not include(@occupation)
155
- @sw_subject_titles.should_not include(@temporal)
156
- @sw_subject_titles.should_not include(@topic)
157
- end
158
- it "should not include top level titleInfo element" do
159
- m = "<mods #{@ns_decl}><titleInfo><title>Oklahoma</title></titleInfo></mods>"
160
- @smods_rec.from_str m
161
- @smods_rec.sw_subject_titles.should == []
162
- end
163
- it "should have one value for each titleInfo element" do
164
- m = "<mods #{@ns_decl}>
165
- <subject>
166
- <titleInfo><title>first</title></titleInfo>
167
- <titleInfo><title>second</title></titleInfo>
168
- </subject>
169
- <subject>
170
- <titleInfo><title>third</title></titleInfo>
171
- </subject>
172
- </mods>"
173
- @smods_rec.from_str m
174
- @smods_rec.sw_subject_titles.should == ['first', 'second', 'third']
175
- end
176
- it "should be an empty Array if there are no values in the mods" do
177
- m = "<mods #{@ns_decl}><note>notit</note></mods>"
178
- @smods_rec.from_str m
179
- @smods_rec.sw_subject_titles.should == []
180
- end
181
- it "should be an empty Array if there are empty values in the mods" do
182
- m = "<mods #{@ns_decl}><subject><titleInfo><title/></titleInfo></subject><note>notit</note></mods>"
183
- @smods_rec.from_str m
184
- @smods_rec.sw_subject_titles.should == []
185
- end
186
- context "combining subelements" do
187
- before(:all) do
48
+ it "should contain subject <topic> subelement data" do
49
+ @smods_rec.topic_search.should include(@topic)
50
+ end
51
+ it "should contain top level <genre> element data" do
52
+ @smods_rec.topic_search.should include(@genre)
53
+ end
54
+ it "should not contain other subject element data" do
55
+ @smods_rec.topic_search.should_not include(@cart_coord)
56
+ @smods_rec.topic_search.should_not include(@s_genre)
57
+ @smods_rec.topic_search.should_not include(@geo)
58
+ @smods_rec.topic_search.should_not include(@geo_code)
59
+ @smods_rec.topic_search.should_not include(@hier_geo_country)
60
+ @smods_rec.topic_search.should_not include(@s_name)
61
+ @smods_rec.topic_search.should_not include(@occupation)
62
+ @smods_rec.topic_search.should_not include(@temporal)
63
+ @smods_rec.topic_search.should_not include(@s_title)
64
+ end
65
+ it "should not be nil if there are only subject/topic elements (no <genre>)" do
66
+ m = "<mods #{@ns_decl}><subject><topic>#{@topic}</topic></subject></mods>"
67
+ @smods_rec = Stanford::Mods::Record.new
68
+ @smods_rec.from_str(m)
69
+ @smods_rec.topic_search.should == [@topic]
70
+ end
71
+ it "should not be nil if there are only <genre> elements (no subject/topic elements)" do
72
+ m = "<mods #{@ns_decl}><genre>#{@genre}</genre></mods>"
73
+ @smods_rec = Stanford::Mods::Record.new
74
+ @smods_rec.from_str(m)
75
+ @smods_rec.topic_search.should == [@genre]
76
+ end
77
+ context "topic subelement" do
78
+ it "should have a separate value for each topic element" do
188
79
  m = "<mods #{@ns_decl}>
189
- <subject>
190
- <titleInfo>
191
- <title>first</title>
192
- <subTitle>second</subTitle>
193
- </titleInfo>
194
- </subject>
195
- </mods>"
196
- @smods_rec.from_str m
197
- end
198
- it "uses a ' ' as the separator by default" do
199
- @smods_rec.sw_subject_titles.should == ['first second']
200
- end
201
- it "honors any string value passed in for the separator" do
202
- @smods_rec.sw_subject_titles(' --').should == ['first --second']
80
+ <subject>
81
+ <topic>first</topic>
82
+ <topic>second</topic>
83
+ </subject>
84
+ <subject><topic>third</topic></subject>
85
+ </mods>"
86
+ @smods_rec = Stanford::Mods::Record.new
87
+ @smods_rec.from_str(m)
88
+ @smods_rec.topic_search.should == ['first', 'second', 'third']
203
89
  end
204
- it "includes all subelements in the order of occurrence" do
205
- m = "<mods #{@ns_decl}>
206
- <subject>
207
- <titleInfo>
208
- <partName>1</partName>
209
- <nonSort>2</nonSort>
210
- <partNumber>3</partNumber>
211
- <title>4</title>
212
- <subTitle>5</subTitle>
213
- </titleInfo>
214
- </subject>
215
- </mods>"
216
- @smods_rec.from_str m
217
- @smods_rec.sw_subject_titles.should == ['1 2 3 4 5']
90
+ it "should be nil if there are only empty values in the MODS" do
91
+ m = "<mods #{@ns_decl}><subject><topic/></subject><note>notit</note></mods>"
92
+ @smods_rec = Stanford::Mods::Record.new
93
+ @smods_rec.from_str(m)
94
+ @smods_rec.topic_search.should == nil
218
95
  end
219
96
  end
220
- end # sw_subject_titles
221
-
222
-
223
- context "sw_geographic_search" do
224
- it "should contain subject <geographic> subelement data" do
225
- @sw_geographic_search.should include(@geo)
97
+ end # topic_search
98
+
99
+ context "geographic_search" do
100
+ it "should call sw_geographic_search (from stanford-mods gem)" do
101
+ m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
102
+ @smods_rec = Stanford::Mods::Record.new
103
+ @smods_rec.from_str(m)
104
+ @smods_rec.should_receive(:sw_geographic_search)
105
+ @smods_rec.geographic_search
226
106
  end
227
- it "should contain subject <hierarchicalGeographic> subelement data" do
228
- @sw_geographic_search.should include(@hier_geo_country)
107
+ it "should log an info message when it encounters a geographicCode encoding it doesn't translate" do
108
+ m = "<mods #{@ns_decl}><subject><geographicCode authority='iso3166'>ca</geographicCode></subject></mods>"
109
+ @smods_rec = Stanford::Mods::Record.new
110
+ @smods_rec.from_str(m)
111
+ @smods_rec.sw_logger.should_receive(:info).with(/#{@fake_druid} has subject geographicCode element with untranslated encoding \(iso3166\): <geographicCode authority=.*>ca<\/geographicCode>/)
112
+ @smods_rec.geographic_search
229
113
  end
230
- it "should contain translation of <geographicCode> subelement data with translated authorities" do
231
- m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
232
- @smods_rec.from_str m
233
- @smods_rec.sw_geographic_search.should include('Estonia')
114
+ end # geographic_search
115
+
116
+ context "subject_other_search" do
117
+ it "should call sw_subject_names (from stanford-mods gem)" do
118
+ smods_rec = Stanford::Mods::Record.new
119
+ smods_rec.from_str(@subject_mods)
120
+ smods_rec.should_receive(:sw_subject_names)
121
+ smods_rec.subject_other_search
122
+ end
123
+ it "should call sw_subject_titles (from stanford-mods gem)" do
124
+ @smods_rec.should_receive(:sw_subject_titles)
125
+ @smods_rec.subject_other_search
126
+ end
127
+ it "should be nil if there are no values in the MODS" do
128
+ m = "<mods #{@ns_decl}></mods>"
129
+ @smods_rec = Stanford::Mods::Record.new
130
+ @smods_rec.from_str(m)
131
+ @smods_rec.subject_other_search.should == nil
132
+ end
133
+ it "should contain subject <name> SUBelement data" do
134
+ @smods_rec.subject_other_search.should include(@s_name)
135
+ end
136
+ it "should contain subject <occupation> subelement data" do
137
+ @smods_rec.subject_other_search.should include(@occupation)
138
+ end
139
+ it "should contain subject <titleInfo> SUBelement data" do
140
+ @smods_rec = Stanford::Mods::Record.new
141
+ @smods_rec.from_str(@subject_mods)
142
+ @smods_rec.subject_other_search.should include(@s_title)
234
143
  end
235
144
  it "should not contain other subject element data" do
236
- @sw_geographic_search.should_not include(@genre)
237
- @sw_geographic_search.should_not include(@cart_coord)
238
- @sw_geographic_search.should_not include(@s_genre)
239
- @sw_geographic_search.should_not include(@s_name)
240
- @sw_geographic_search.should_not include(@occupation)
241
- @sw_geographic_search.should_not include(@temporal)
242
- @sw_geographic_search.should_not include(@topic)
243
- @sw_geographic_search.should_not include(@s_title)
244
- end
245
- it "should be [] if there are no values in the MODS" do
246
- m = "<mods #{@ns_decl}><note>notit</note></mods>"
247
- @smods_rec.from_str m
248
- @smods_rec.sw_geographic_search.should == []
249
- end
250
- it "should not be empty Array if there are only subject/geographic elements" do
251
- m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
252
- @smods_rec.from_str m
253
- @smods_rec.sw_geographic_search.should == [@geo]
145
+ @smods_rec.subject_other_search.should_not include(@genre)
146
+ @smods_rec.subject_other_search.should_not include(@cart_coord)
147
+ @smods_rec.subject_other_search.should_not include(@s_genre)
148
+ @smods_rec.subject_other_search.should_not include(@geo)
149
+ @smods_rec.subject_other_search.should_not include(@geo_code)
150
+ @smods_rec.subject_other_search.should_not include(@hier_geo_country)
151
+ @smods_rec.subject_other_search.should_not include(@temporal)
152
+ @smods_rec.subject_other_search.should_not include(@topic)
254
153
  end
255
- it "should not be empty Array if there are only subject/hierarchicalGeographic" do
256
- m = "<mods #{@ns_decl}><subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject></mods>"
257
- @smods_rec.from_str m
258
- @smods_rec.sw_geographic_search.should == [@hier_geo_country]
154
+ it "should not be nil if there are only subject/name elements" do
155
+ m = "<mods #{@ns_decl}><subject><name><namePart>#{@s_name}</namePart></name></subject></mods>"
156
+ @smods_rec = Stanford::Mods::Record.new
157
+ @smods_rec.from_str(m)
158
+ @smods_rec.subject_other_search.should == [@s_name]
259
159
  end
260
- it "should not be empty Array if there are only subject/geographicCode elements" do
261
- m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
262
- @smods_rec.from_str m
263
- @smods_rec.sw_geographic_search.should == ['Estonia']
160
+ it "should not be nil if there are only subject/occupation elements" do
161
+ m = "<mods #{@ns_decl}><subject><occupation>#{@occupation}</occupation></subject></mods>"
162
+ @smods_rec = Stanford::Mods::Record.new
163
+ @smods_rec.from_str(m)
164
+ @smods_rec.subject_other_search.should == [@occupation]
264
165
  end
265
- context "geographic subelement" do
266
- it "should have a separate value for each geographic element" do
267
- m = "<mods #{@ns_decl}>
268
- <subject>
269
- <geographic>Mississippi</geographic>
270
- <geographic>Tippah County</geographic>
271
- </subject>
272
- <subject><geographic>Washington (D.C.)</geographic></subject>
273
- </mods>"
274
- @smods_rec.from_str m
275
- @smods_rec.sw_geographic_search.should == ['Mississippi', 'Tippah County', 'Washington (D.C.)']
276
- end
277
- it "should be empty Array if there are only empty values in the MODS" do
278
- m = "<mods #{@ns_decl}><subject><geographic/></subject><note>notit</note></mods>"
279
- @smods_rec.from_str m
280
- @smods_rec.sw_geographic_search.should == []
281
- end
166
+ it "should not be nil if there are only subject/titleInfo elements" do
167
+ m = "<mods #{@ns_decl}><subject><titleInfo><title>#{@s_title}</title></titleInfo></subject></mods>"
168
+ @smods_rec = Stanford::Mods::Record.new
169
+ @smods_rec.from_str(m)
170
+ @smods_rec.subject_other_search.should == [@s_title]
282
171
  end
283
- context "hierarchicalGeographic subelement" do
284
- it "should have a separate value for each hierarchicalGeographic element" do
172
+ context "occupation subelement" do
173
+ it "should have a separate value for each occupation element" do
285
174
  m = "<mods #{@ns_decl}>
286
- <subject>
287
- <hierarchicalGeographic><area>first</area></hierarchicalGeographic>
288
- <hierarchicalGeographic><area>second</area></hierarchicalGeographic>
289
- </subject>
290
- <subject><hierarchicalGeographic><area>third</area></hierarchicalGeographic></subject>
291
- </mods>"
292
- @smods_rec.from_str m
293
- @smods_rec.sw_geographic_search.should == ['first', 'second', 'third']
294
- end
295
- it "should be empty Array if there are only empty values in the MODS" do
296
- m = "<mods #{@ns_decl}><subject><hierarchicalGeographic/></subject><note>notit</note></mods>"
297
- @smods_rec.from_str m
298
- @smods_rec.sw_geographic_search.should == []
175
+ <subject>
176
+ <occupation>first</occupation>
177
+ <occupation>second</occupation>
178
+ </subject>
179
+ <subject><occupation>third</occupation></subject>
180
+ </mods>"
181
+ @smods_rec = Stanford::Mods::Record.new
182
+ @smods_rec.from_str(m)
183
+ @smods_rec.subject_other_search.should == ['first', 'second', 'third']
299
184
  end
300
- context "combining subelements" do
301
- before(:all) do
302
- m = "<mods #{@ns_decl}>
303
- <subject>
304
- <hierarchicalGeographic>
305
- <country>Canada</country>
306
- <province>British Columbia</province>
307
- <city>Vancouver</city>
308
- </hierarchicalGeographic>
309
- </subject></mods>"
310
- @smods_rec.from_str m
311
- end
312
- it "uses a space as the separator by default" do
313
- @smods_rec.sw_geographic_search.should == ['Canada British Columbia Vancouver']
314
- end
315
- it "honors any string value passed in for the separator" do
316
- @smods_rec.sw_geographic_search(' --').should == ['Canada --British Columbia --Vancouver']
317
- end
185
+ it "should be nil if there are only empty values in the MODS" do
186
+ m = "<mods #{@ns_decl}><subject><occupation/></subject><note>notit</note></mods>"
187
+ @smods_rec = Stanford::Mods::Record.new
188
+ @smods_rec.from_str(m)
189
+ @smods_rec.subject_other_search.should == nil
318
190
  end
319
- end # hierarchicalGeographic
320
- context "geographicCode subelement" do
321
- before(:all) do
191
+ end
192
+ end # subject_other_search
193
+
194
+ context "subject_other_subvy_search" do
195
+ it "should be nil if there are no values in the MODS" do
196
+ @smods_rec = Stanford::Mods::Record.new
197
+ @smods_rec.from_str(@ng_mods_no_subject.to_s)
198
+ @smods_rec.subject_other_subvy_search.should == nil
199
+ end
200
+ it "should contain subject <temporal> subelement data" do
201
+ @smods_rec.subject_other_subvy_search.should include(@temporal)
202
+ end
203
+ it "should contain subject <genre> SUBelement data" do
204
+ @smods_rec.subject_other_subvy_search.should include(@s_genre)
205
+ end
206
+ it "should not contain other subject element data" do
207
+ @smods_rec.subject_other_subvy_search.should_not include(@genre)
208
+ @smods_rec.subject_other_subvy_search.should_not include(@cart_coord)
209
+ @smods_rec.subject_other_subvy_search.should_not include(@geo)
210
+ @smods_rec.subject_other_subvy_search.should_not include(@geo_code)
211
+ @smods_rec.subject_other_subvy_search.should_not include(@hier_geo_country)
212
+ @smods_rec.subject_other_subvy_search.should_not include(@s_name)
213
+ @smods_rec.subject_other_subvy_search.should_not include(@occupation)
214
+ @smods_rec.subject_other_subvy_search.should_not include(@topic)
215
+ @smods_rec.subject_other_subvy_search.should_not include(@s_title)
216
+ end
217
+ it "should not be nil if there are only subject/temporal elements (no subject/genre)" do
218
+ m = "<mods #{@ns_decl}><subject><temporal>#{@temporal}</temporal></subject></mods>"
219
+ @smods_rec = Stanford::Mods::Record.new
220
+ @smods_rec.from_str(m)
221
+ @smods_rec.subject_other_subvy_search.should == [@temporal]
222
+ end
223
+ it "should not be nil if there are only subject/genre elements (no subject/temporal)" do
224
+ m = "<mods #{@ns_decl}><subject><genre>#{@s_genre}</genre></subject></mods>"
225
+ @smods_rec = Stanford::Mods::Record.new
226
+ @smods_rec.from_str(m)
227
+ @smods_rec.subject_other_subvy_search.should == [@s_genre]
228
+ end
229
+ context "temporal subelement" do
230
+ it "should have a separate value for each temporal element" do
322
231
  m = "<mods #{@ns_decl}>
323
- <subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
324
- <subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
325
- <subject><geographicCode authority='marccountry'>mg</geographicCode></subject>
326
- <subject><geographicCode authority='iso3166'>us</geographicCode></subject>
232
+ <subject>
233
+ <temporal>1890-1910</temporal>
234
+ <temporal>20th century</temporal>
235
+ </subject>
236
+ <subject><temporal>another</temporal></subject>
327
237
  </mods>"
328
- @smods_rec.from_str m
329
- @geo_search_from_codes = @smods_rec.sw_geographic_search
330
- end
331
- it "should not add untranslated values" do
332
- @geo_search_from_codes.should_not include('n-us-md')
333
- @geo_search_from_codes.should_not include('e-er')
334
- @geo_search_from_codes.should_not include('mg')
335
- @geo_search_from_codes.should_not include('us')
336
- end
337
- it "should translate marcgac codes" do
338
- @geo_search_from_codes.should include('Estonia')
238
+ @smods_rec = Stanford::Mods::Record.new
239
+ @smods_rec.from_str(m)
240
+ @smods_rec.subject_other_subvy_search.should == ['1890-1910', '20th century', 'another']
339
241
  end
340
- it "should translate marccountry codes" do
341
- @geo_search_from_codes.should include('Madagascar')
242
+ it "should log an info message when it encounters an encoding it doesn't translate" do
243
+ m = "<mods #{@ns_decl}><subject><temporal encoding='iso8601'>197505</temporal></subject></mods>"
244
+ @smods_rec = Stanford::Mods::Record.new
245
+ @smods_rec.from_str(m)
246
+ @smods_rec.sw_logger.should_receive(:info).with(/#{@fake_druid} has subject temporal element with untranslated encoding: <temporal encoding=.*>197505<\/temporal>/)
247
+ @smods_rec.subject_other_subvy_search
342
248
  end
343
- it "should not translate other codes" do
344
- @geo_search_from_codes.should_not include('United States')
249
+ it "should be nil if there are only empty values in the MODS" do
250
+ m = "<mods #{@ns_decl}><subject><temporal/></subject><note>notit</note></mods>"
251
+ @smods_rec = Stanford::Mods::Record.new
252
+ @smods_rec.from_str(m)
253
+ @smods_rec.subject_other_subvy_search.should == nil
345
254
  end
346
- it "should have a separate value for each geographicCode element" do
347
- m = "<mods #{@ns_decl}>
348
- <subject>
349
- <geographicCode authority='marcgac'>e-er</geographicCode>
350
- <geographicCode authority='marccountry'>mg</geographicCode>
351
- </subject>
352
- <subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
353
- </mods>"
354
- @smods_rec.from_str m
355
- @smods_rec.sw_geographic_search.should == ['Estonia', 'Madagascar', 'Maryland']
356
- end
357
- it "should be empty Array if there are only empty values in the MODS" do
358
- m = "<mods #{@ns_decl}><subject><geographicCode/></subject><note>notit</note></mods>"
359
- @smods_rec.from_str m
360
- @smods_rec.sw_geographic_search.should == []
361
- end
362
- it "should add the translated value if it wasn't present already" do
255
+ end
256
+ context "genre subelement" do
257
+ it "should have a separate value for each genre element" do
363
258
  m = "<mods #{@ns_decl}>
364
- <subject><geographic>Somewhere</geographic></subject>
365
- <subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
259
+ <subject>
260
+ <genre>first</genre>
261
+ <genre>second</genre>
262
+ </subject>
263
+ <subject><genre>third</genre></subject>
366
264
  </mods>"
367
- @smods_rec.from_str m
368
- @smods_rec.sw_geographic_search.size.should == 2
369
- @smods_rec.sw_geographic_search.should include('Estonia')
265
+ @smods_rec = Stanford::Mods::Record.new
266
+ @smods_rec.from_str(m)
267
+ @smods_rec.subject_other_subvy_search.should == ['first', 'second', 'third']
370
268
  end
371
- it "should not add the translated value if it was already present" do
372
- m = "<mods #{@ns_decl}>
373
- <subject><geographic>Estonia</geographic></subject>
374
- <subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
375
- </mods>"
376
- @smods_rec.from_str m
377
- @smods_rec.sw_geographic_search.size.should == 1
378
- @smods_rec.sw_geographic_search.should == ['Estonia']
269
+ it "should be nil if there are only empty values in the MODS" do
270
+ m = "<mods #{@ns_decl}><subject><genre/></subject><note>notit</note></mods>"
271
+ @smods_rec = Stanford::Mods::Record.new
272
+ @smods_rec.from_str(m)
273
+ @smods_rec.subject_other_subvy_search.should == nil
379
274
  end
380
275
  end
381
- end # sw_geographic_search
382
- end # context sw subject methods
276
+ end # subject_other_subvy_search
277
+
278
+ context "subject_all_search" do
279
+ it "should be nil if there are no values in the MODS" do
280
+ @smods_rec = Stanford::Mods::Record.new
281
+ @smods_rec.from_str(@ng_mods_no_subject.to_s)
282
+ @smods_rec.subject_all_search.should == nil
283
+ end
284
+ it "should contain top level <genre> element data" do
285
+ @smods_rec.subject_all_search.should include(@genre)
286
+ end
287
+ it "should not contain cartographic sub element" do
288
+ @smods_rec.subject_all_search.should_not include(@cart_coord)
289
+ end
290
+ it "should not include codes from hierarchicalGeographic sub element" do
291
+ @smods_rec.subject_all_search.should_not include(@geo_code)
292
+ end
293
+ it "should contain all other subject subelement data" do
294
+ @smods_rec = Stanford::Mods::Record.new
295
+ @smods_rec.from_str(@subject_mods)
296
+ @smods_rec.subject_all_search.should include(@s_genre)
297
+ @smods_rec.subject_all_search.should include(@geo)
298
+ @smods_rec.subject_all_search.should include(@hier_geo_country)
299
+ @smods_rec.subject_all_search.should include(@s_name)
300
+ @smods_rec.subject_all_search.should include(@occupation)
301
+ @smods_rec.subject_all_search.should include(@temporal)
302
+ @smods_rec.subject_all_search.should include(@s_title)
303
+ @smods_rec.subject_all_search.should include(@topic)
304
+ end
305
+ end # subject_all_search
306
+
307
+ end # search fields
308
+
309
+ context "facet fields" do
310
+
311
+ context "topic_facet" do
312
+ it "should include topic subelement" do
313
+ @smods_rec.topic_facet.should include(@topic)
314
+ end
315
+ it "should include sw_subject_names" do
316
+ @smods_rec.topic_facet.should include(@s_name)
317
+ end
318
+ it "should include sw_subject_titles" do
319
+ @smods_rec.topic_facet.should include(@s_title)
320
+ end
321
+ it "should include occupation subelement" do
322
+ @smods_rec.topic_facet.should include(@occupation)
323
+ end
324
+ it "should have the trailing punctuation removed" do
325
+ m = "<mods #{@ns_decl}><subject>
326
+ <topic>comma,</topic>
327
+ <occupation>semicolon;</occupation>
328
+ <titleInfo><title>backslash \\</title></titleInfo>
329
+ <name><namePart>internal, punct;uation</namePart></name>
330
+ </subject></mods>"
331
+ @smods_rec = Stanford::Mods::Record.new
332
+ @smods_rec.from_str(m)
333
+ @smods_rec.topic_facet.should include('comma')
334
+ @smods_rec.topic_facet.should include('semicolon')
335
+ @smods_rec.topic_facet.should include('backslash')
336
+ @smods_rec.topic_facet.should include('internal, punct;uation')
337
+ end
338
+ it "should be nil if there are no values" do
339
+ @smods_rec = Stanford::Mods::Record.new
340
+ @smods_rec.from_str(@ng_mods_no_subject.to_s)
341
+ @smods_rec.topic_facet.should == nil
342
+ end
343
+ end
344
+
345
+ context "geographic_facet" do
346
+ it "should call geographic_search" do
347
+ @smods_rec.should_receive(:geographic_search)
348
+ @smods_rec.geographic_facet
349
+ end
350
+ it "should be like geographic_search with the trailing punctuation (and preceding spaces) removed" do
351
+ m = "<mods #{@ns_decl}><subject>
352
+ <geographic>comma,</geographic>
353
+ <geographic>semicolon;</geographic>
354
+ <geographic>backslash \\</geographic>
355
+ <geographic>internal, punct;uation</geographic>
356
+ </subject></mods>"
357
+ @smods_rec = Stanford::Mods::Record.new
358
+ @smods_rec.from_str(m)
359
+ @smods_rec.geographic_facet.should include('comma')
360
+ @smods_rec.geographic_facet.should include('semicolon')
361
+ @smods_rec.geographic_facet.should include('backslash')
362
+ @smods_rec.geographic_facet.should include('internal, punct;uation')
363
+ end
364
+ it "should be nil if there are no values" do
365
+ @smods_rec = Stanford::Mods::Record.new
366
+ @smods_rec.from_str(@ng_mods_no_subject.to_s)
367
+ @smods_rec. geographic_facet.should == nil
368
+ end
369
+ end
370
+
371
+ context "era_facet" do
372
+ it "should be temporal subelement with the trailing punctuation removed" do
373
+ m = "<mods #{@ns_decl}><subject>
374
+ <temporal>comma,</temporal>
375
+ <temporal>semicolon;</temporal>
376
+ <temporal>backslash \\</temporal>
377
+ <temporal>internal, punct;uation</temporal>
378
+ </subject></mods>"
379
+ @smods_rec = Stanford::Mods::Record.new
380
+ @smods_rec.from_str(m)
381
+ @smods_rec.era_facet.should include('comma')
382
+ @smods_rec.era_facet.should include('semicolon')
383
+ @smods_rec.era_facet.should include('backslash')
384
+ @smods_rec.era_facet.should include('internal, punct;uation')
385
+ end
386
+ it "should be nil if there are no values" do
387
+ @smods_rec = Stanford::Mods::Record.new
388
+ @smods_rec.from_str(@ng_mods_no_subject.to_s)
389
+ @smods_rec.era_facet.should == nil
390
+ end
391
+ end
392
+
393
+ end # facet fields
383
394
 
384
395
  end