mods_display 0.10.0 → 1.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/.rubocop_todo.yml +433 -35
  4. data/README.md +0 -95
  5. data/app/components/mods_display/field_component.html.erb +13 -0
  6. data/app/components/mods_display/field_component.rb +27 -0
  7. data/app/components/mods_display/list_field_component.html.erb +11 -0
  8. data/app/components/mods_display/list_field_component.rb +10 -0
  9. data/app/components/mods_display/record_component.html.erb +5 -0
  10. data/app/components/mods_display/record_component.rb +39 -0
  11. data/app/helpers/mods_display/record_helper.rb +106 -0
  12. data/app/models/mods_display/record.rb +26 -0
  13. data/config/locales/en.yml +1 -1
  14. data/config.ru +9 -0
  15. data/lib/mods_display/engine.rb +13 -0
  16. data/lib/mods_display/fields/access_condition.rb +4 -0
  17. data/lib/mods_display/fields/contents.rb +14 -15
  18. data/lib/mods_display/fields/field.rb +13 -149
  19. data/lib/mods_display/fields/genre.rb +4 -0
  20. data/lib/mods_display/fields/imprint.rb +52 -3
  21. data/lib/mods_display/fields/name.rb +11 -20
  22. data/lib/mods_display/fields/nested_related_item.rb +11 -20
  23. data/lib/mods_display/fields/note.rb +4 -0
  24. data/lib/mods_display/fields/related_item.rb +4 -0
  25. data/lib/mods_display/fields/resource_type.rb +1 -1
  26. data/lib/mods_display/fields/sub_title.rb +3 -3
  27. data/lib/mods_display/fields/subject.rb +13 -39
  28. data/lib/mods_display/fields/title.rb +4 -0
  29. data/lib/mods_display/fields/values.rb +4 -4
  30. data/lib/mods_display/html.rb +55 -106
  31. data/lib/mods_display/version.rb +1 -1
  32. data/lib/mods_display.rb +2 -17
  33. data/mods_display.gemspec +15 -9
  34. metadata +45 -105
  35. data/.github/workflows/ruby.yml +0 -24
  36. data/.gitignore +0 -21
  37. data/lib/mods_display/configuration/access_condition.rb +0 -21
  38. data/lib/mods_display/configuration/base.rb +0 -34
  39. data/lib/mods_display/configuration/genre.rb +0 -9
  40. data/lib/mods_display/configuration/imprint.rb +0 -13
  41. data/lib/mods_display/configuration/name.rb +0 -9
  42. data/lib/mods_display/configuration/note.rb +0 -9
  43. data/lib/mods_display/configuration/related_item.rb +0 -9
  44. data/lib/mods_display/configuration/subject.rb +0 -13
  45. data/lib/mods_display/configuration/title.rb +0 -9
  46. data/lib/mods_display/configuration.rb +0 -93
  47. data/lib/mods_display/controller_extension.rb +0 -32
  48. data/lib/mods_display/helpers/record_helper.rb +0 -131
  49. data/lib/mods_display/model_extension.rb +0 -22
  50. data/lib/mods_display/railtie.rb +0 -10
  51. data/spec/configuration/access_condition_spec.rb +0 -10
  52. data/spec/configuration/base_spec.rb +0 -39
  53. data/spec/fake_app.rb +0 -18
  54. data/spec/fields/abstract_spec.rb +0 -39
  55. data/spec/fields/access_condition_spec.rb +0 -107
  56. data/spec/fields/audience_spec.rb +0 -24
  57. data/spec/fields/cartographics_spec.rb +0 -38
  58. data/spec/fields/collection_spec.rb +0 -77
  59. data/spec/fields/contact_spec.rb +0 -23
  60. data/spec/fields/contents_spec.rb +0 -39
  61. data/spec/fields/description_spec.rb +0 -55
  62. data/spec/fields/extent_spec.rb +0 -31
  63. data/spec/fields/form_spec.rb +0 -49
  64. data/spec/fields/genre_spec.rb +0 -34
  65. data/spec/fields/geo_spec.rb +0 -40
  66. data/spec/fields/identifier_spec.rb +0 -61
  67. data/spec/fields/imprint_spec.rb +0 -289
  68. data/spec/fields/language_spec.rb +0 -51
  69. data/spec/fields/location_spec.rb +0 -81
  70. data/spec/fields/name_spec.rb +0 -166
  71. data/spec/fields/nested_related_item_spec.rb +0 -89
  72. data/spec/fields/note_spec.rb +0 -72
  73. data/spec/fields/related_item_spec.rb +0 -72
  74. data/spec/fields/resource_type_spec.rb +0 -34
  75. data/spec/fields/sub_title_spec.rb +0 -20
  76. data/spec/fields/subject_spec.rb +0 -113
  77. data/spec/fields/title_spec.rb +0 -82
  78. data/spec/fixtures/access_condition_fixtures.rb +0 -58
  79. data/spec/fixtures/cartographics_fixtures.rb +0 -52
  80. data/spec/fixtures/imprint_fixtures.rb +0 -349
  81. data/spec/fixtures/name_fixtures.rb +0 -398
  82. data/spec/fixtures/nested_realted_items_fixtures.rb +0 -64
  83. data/spec/fixtures/related_item_fixtures.rb +0 -107
  84. data/spec/fixtures/subjects_fixtures.rb +0 -115
  85. data/spec/fixtures/title_fixtures.rb +0 -115
  86. data/spec/helpers/record_helper_spec.rb +0 -241
  87. data/spec/integration/configuration_spec.rb +0 -57
  88. data/spec/integration/html_spec.rb +0 -87
  89. data/spec/integration/installation_spec.rb +0 -26
  90. data/spec/spec_helper.rb +0 -46
  91. data/spec/test_fr.yml +0 -3
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_id(mods_record)
4
- ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Note do
8
- before(:all) do
9
- @id = Stanford::Mods::Record.new.from_str('<mods><identifier>12345</identifier></mods>', false).identifier
10
- @display_label = Stanford::Mods::Record.new.from_str(
11
- "<mods><identifier displayLabel='Special Label'>54321</identifier></mods>", false
12
- ).identifier
13
- @issue_label = Stanford::Mods::Record.new.from_str(
14
- "<mods><identifier type='issue number'>Issue 1</identifier></mods>", false
15
- ).identifier
16
- @type_label = Stanford::Mods::Record.new.from_str(
17
- "<mods><identifier type='Some other Type'>98765</identifier></mods>", false
18
- ).identifier
19
- @complex_label = Stanford::Mods::Record.new.from_str(
20
- "<mods>
21
- <identifier>12345</identifier>
22
- <identifier>54321</identifier>
23
- <identifier type='issue number'>12345</identifier>
24
- <identifier>98765</identifier>
25
- </mods>", false
26
- ).identifier
27
- end
28
- describe 'label' do
29
- it 'should have a default label' do
30
- expect(mods_display_id(@id).fields.first.label).to eq('Identifier:')
31
- end
32
- it 'should use the displayLabel attribute when one is available' do
33
- expect(mods_display_id(@display_label).fields.first.label).to eq('Special Label:')
34
- end
35
- it 'should use get a label from a list of translations' do
36
- expect(mods_display_id(@issue_label).fields.first.label).to eq('Issue number:')
37
- end
38
- it 'should use use the raw type attribute if one is present' do
39
- expect(mods_display_id(@type_label).fields.first.label).to eq('Some other Type:')
40
- end
41
- end
42
-
43
- describe 'fields' do
44
- it 'should handle matching adjacent labels' do
45
- fields = mods_display_id(@complex_label).fields
46
- expect(fields.length).to eq(3)
47
-
48
- expect(fields.first.label).to eq('Identifier:')
49
- expect(fields.first.values.length).to eq(2)
50
- expect(fields.first.values).to eq(%w(12345 54321))
51
-
52
- expect(fields[1].label).to eq('Issue number:')
53
- expect(fields[1].values.length).to eq(1)
54
- expect(fields[1].values).to eq(['12345'])
55
-
56
- expect(fields.last.label).to eq('Identifier:')
57
- expect(fields.last.values.length).to eq(1)
58
- expect(fields.last.values).to eq(['98765'])
59
- end
60
- end
61
- end
@@ -1,289 +0,0 @@
1
- require 'spec_helper'
2
- require 'fixtures/imprint_fixtures'
3
-
4
- include ImprintFixtures
5
-
6
- def mods_display_imprint(mods_record)
7
- ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Imprint.new, double('controller'))
8
- end
9
-
10
- def mods_display_format_date_imprint(mods_record)
11
- ModsDisplay::Imprint.new(
12
- mods_record,
13
- ModsDisplay::Configuration::Imprint.new do
14
- full_date_format('(%Y) %B, %d')
15
- short_date_format('%B (%Y)')
16
- end,
17
- double('controller')
18
- )
19
- end
20
-
21
- describe ModsDisplay::Imprint do
22
- before(:all) do
23
- @imprint = Stanford::Mods::Record.new.from_str(imprint_mods, false).origin_info
24
- @no_edition = Stanford::Mods::Record.new.from_str(no_edition_mods, false).origin_info
25
- @edition_and_date = Stanford::Mods::Record.new.from_str(origin_info_mods, false).origin_info
26
- @mixed = Stanford::Mods::Record.new.from_str(mixed_mods, false).origin_info
27
- @display_form = Stanford::Mods::Record.new.from_str(display_form, false).origin_info
28
- @display_form_with_label = Stanford::Mods::Record.new.from_str(display_form, false).origin_info
29
- @display_label = Stanford::Mods::Record.new.from_str(display_label, false).origin_info
30
- @date_range = Stanford::Mods::Record.new.from_str(date_range, false).origin_info
31
- @open_date_range = Stanford::Mods::Record.new.from_str(open_date_range, false).origin_info
32
- @encoded_date_range = Stanford::Mods::Record.new.from_str(encoded_date_range, false).origin_info
33
- @dup_qualified_date = Stanford::Mods::Record.new.from_str(dup_qualified_date, false).origin_info
34
- @dup_unencoded_date = Stanford::Mods::Record.new.from_str(dup_unencoded_date, false).origin_info
35
- @dup_copyright_date = Stanford::Mods::Record.new.from_str(dup_copyright_date, false).origin_info
36
- @dup_date = Stanford::Mods::Record.new.from_str(dup_date, false).origin_info
37
- @approximate_date = Stanford::Mods::Record.new.from_str(approximate_date, false).origin_info
38
- @questionable_date = Stanford::Mods::Record.new.from_str(questionable_date, false).origin_info
39
- @inferred_date = Stanford::Mods::Record.new.from_str(inferred_date, false).origin_info
40
- @three_imprint_dates = Stanford::Mods::Record.new.from_str(three_imprint_dates, false).origin_info
41
- @xx_country_code = Stanford::Mods::Record.new.from_str(xx_country_code, false).origin_info
42
- @qualified_imprint_date = Stanford::Mods::Record.new.from_str(qualified_imprint_date, false).origin_info
43
- @imprint_date_range = Stanford::Mods::Record.new.from_str(imprint_date_range, false).origin_info
44
- @encoded_place = Stanford::Mods::Record.new.from_str(encoded_place, false).origin_info
45
- @encoded_dates = Stanford::Mods::Record.new.from_str(encoded_dates, false).origin_info
46
- @iso8601_encoded_dates = Stanford::Mods::Record.new.from_str(iso8601_encoded_dates, false).origin_info
47
- @bad_dates = Stanford::Mods::Record.new.from_str(bad_dates, false).origin_info
48
- @invalid_dates = Stanford::Mods::Record.new.from_str(invalid_dates, false).origin_info
49
- @punctuation_imprint = Stanford::Mods::Record.new.from_str(punctuation_imprint_fixture, false).origin_info
50
- @bc_ad_dates = Stanford::Mods::Record.new.from_str(bc_ad_imprint_date_fixture, false).origin_info
51
- end
52
-
53
- describe 'labels' do
54
- it 'should get the Imprint label by default' do
55
- expect(mods_display_imprint(@imprint).fields.first.label).to eq('Imprint:')
56
- end
57
- it 'should get the label from non-imprint origin info fields' do
58
- fields = mods_display_imprint(@edition_and_date).fields
59
- expect(fields.first.label).to eq('Date valid:')
60
- expect(fields.last.label).to eq('Issuance:')
61
- end
62
- it 'should get multiple labels when we have mixed content' do
63
- expect(mods_display_imprint(@mixed).fields.map(&:label)).to eq(['Imprint:', 'Date captured:', 'Issuance:'])
64
- end
65
- it 'should use the displayLabel when available' do
66
- expect(mods_display_imprint(@display_label).fields.map(&:label)).to eq(['TheLabel:', 'IssuanceLabel:'])
67
- end
68
- end
69
-
70
- describe 'fields' do
71
- it 'should return various parts of the imprint' do
72
- expect(mods_display_imprint(@imprint).fields.map(&:values).join(' ')).to eq(
73
- 'An edition - A Place : A Publisher, An Issue Date, Another Date'
74
- )
75
- end
76
- it 'should handle the punctuation when the edition is missing' do
77
- values = mods_display_imprint(@no_edition).fields.map(&:values).join(' ')
78
- expect(values.strip).not_to match(/^-/)
79
- expect(values).to match(/^A Place/)
80
- end
81
- it 'should get the text for non-imprint origin info fields' do
82
- fields = mods_display_imprint(@edition_and_date).fields
83
- expect(fields.first.values).to eq(['A Valid Date'])
84
- expect(fields.last.values).to eq(['The Issuance'])
85
- end
86
- it 'should handle mixed mods properly' do
87
- values = mods_display_imprint(@mixed).fields
88
- expect(values.length).to eq(3)
89
- expect(values.map(&:values)).to include(['A Place : A Publisher'])
90
- expect(values.map(&:values)).to include(['The Issuance'])
91
- expect(values.map(&:values)).to include(['The Capture Date'])
92
- end
93
- end
94
- describe 'date processing' do
95
- describe 'ranges' do
96
- it "should join start and end point ranges with a '-'" do
97
- fields = mods_display_imprint(@date_range).fields
98
- expect(fields.length).to eq(1)
99
- expect(fields.first.values).to eq(['1820-1825'])
100
- end
101
- it 'should handle open ranges properly' do
102
- fields = mods_display_imprint(@open_date_range).fields
103
- expect(fields.length).to eq(1)
104
- expect(fields.first.values).to eq(['1820-'])
105
- end
106
- it 'should handle when there are more than 3 of the same date w/i a range' do
107
- fields = mods_display_imprint(@three_imprint_dates).fields
108
- expect(fields.length).to eq(1)
109
- expect(fields.first.values).to eq(['[1820-1825?]'])
110
- end
111
- it 'should apply the qualifier decoration in the imprints' do
112
- fields = mods_display_imprint(@qualified_imprint_date).fields
113
- expect(fields.length).to eq(1)
114
- expect(fields.first.values).to eq(['[1820?]'])
115
- end
116
- it 'should handle date ranges in imprints' do
117
- fields = mods_display_imprint(@imprint_date_range).fields
118
- expect(fields.length).to eq(1)
119
- expect(fields.first.values).to eq(['1820-1825'])
120
- end
121
- it 'should handle encoded dates properly' do
122
- fields = mods_display_imprint(@encoded_date_range).fields
123
- expect(fields.length).to eq 1
124
- expect(fields.first.values).to eq ['February 01, 2008-December 02, 2009']
125
- end
126
-
127
- it 'should handle B.C. and A.D. dates appropriately' do
128
- fields = mods_display_imprint(@bc_ad_dates).fields
129
- expect(fields.length).to eq 1
130
- expect(fields.first.values).to eq ['14 B.C.-44 A.D.']
131
- end
132
- end
133
- describe 'duplication' do
134
- it 'should only return the qualified date when present' do
135
- fields = mods_display_imprint(@dup_qualified_date).fields
136
- expect(fields.length).to eq(1)
137
- expect(fields.first.values).to eq(['[1820?]'])
138
- end
139
- it 'should use the non-encoded date when prsent' do
140
- fields = mods_display_imprint(@dup_unencoded_date).fields
141
- expect(fields.length).to eq(1)
142
- expect(fields.first.values).to eq(['[ca. 1820]'])
143
- end
144
- it 'should handle copyright dates correctly' do
145
- fields = mods_display_imprint(@dup_copyright_date).fields
146
- expect(fields.length).to eq(1)
147
- expect(fields.first.values).to eq(['c1820'])
148
- end
149
- it 'should only return one when no attributes are present' do
150
- fields = mods_display_imprint(@dup_date).fields
151
- expect(fields.length).to eq(1)
152
- expect(fields.first.values).to eq(['1820'])
153
- end
154
- end
155
- describe 'qualifier decoration' do
156
- it "should prepend a 'c' to approximate dates" do
157
- fields = mods_display_imprint(@approximate_date).fields
158
- expect(fields.length).to eq(1)
159
- expect(fields.first.values).to eq(['[ca. 1820]'])
160
- end
161
- it "should append a '?' to a questionable dates and wrap them in square-brackets" do
162
- fields = mods_display_imprint(@questionable_date).fields
163
- expect(fields.length).to eq(1)
164
- expect(fields.first.values).to eq(['[1820?]'])
165
- end
166
- it 'should wrap inferred dates in square-brackets' do
167
- fields = mods_display_imprint(@inferred_date).fields
168
- expect(fields.length).to eq(1)
169
- expect(fields.first.values).to eq(['[1820]'])
170
- end
171
- end
172
- describe 'encoded dates' do
173
- describe 'W3CDTF' do
174
- it 'should handle single year dates properly' do
175
- fields = mods_display_imprint(@encoded_dates).fields
176
- expect(fields.length).to eq(4)
177
- expect(fields.find do |field|
178
- field.label == 'Imprint:'
179
- end.values).to eq(['2013'])
180
- end
181
- it 'should handle month+year dates properly' do
182
- fields = mods_display_imprint(@encoded_dates).fields
183
- expect(fields.length).to eq(4)
184
- expect(fields.find do |field|
185
- field.label == 'Date captured:'
186
- end.values).to eq(['July 2013'])
187
- end
188
- it 'should handle full dates properly' do
189
- fields = mods_display_imprint(@encoded_dates).fields
190
- expect(fields.length).to eq(4)
191
- expect(fields.find do |field|
192
- field.label == 'Date created:'
193
- end.values).to eq(['July 10, 2013'])
194
- end
195
- it "should not try to handle dates we can't parse" do
196
- fields = mods_display_imprint(@encoded_dates).fields
197
- expect(fields.length).to eq(4)
198
- expect(fields.find do |field|
199
- field.label == 'Date modified:'
200
- end.values).to eq(['Jul. 22, 2013'])
201
- end
202
- it 'should accept date configurations' do
203
- fields = mods_display_format_date_imprint(@encoded_dates).fields
204
- expect(fields.length).to eq(4)
205
- expect(fields.find do |field|
206
- field.label == 'Date created:'
207
- end.values).to eq(['(2013) July, 10'])
208
- expect(fields.find do |field|
209
- field.label == 'Date captured:'
210
- end.values).to eq(['July (2013)'])
211
- end
212
- end
213
-
214
- describe 'iso8601' do
215
- it 'handles full dates properly' do
216
- fields = mods_display_imprint(@iso8601_encoded_dates).fields
217
- expect(fields.length).to eq(2)
218
- expect(fields.find do |field|
219
- field.label == 'Date created:'
220
- end.values).to eq(['November 14, 2013'])
221
- end
222
- it "should not try to handle dates we can't parse" do
223
- fields = mods_display_imprint(@iso8601_encoded_dates).fields
224
- expect(fields.length).to eq(2)
225
- expect(fields.find do |field|
226
- field.label == 'Date modified:'
227
- end.values).to eq(['Jul. 22, 2013'])
228
- end
229
- end
230
- end
231
- describe 'bad dates' do
232
- it 'should ignore date values' do
233
- fields = mods_display_imprint(@bad_dates).fields
234
- expect(fields.length).to eq(2)
235
- fields.each do |field|
236
- expect(field.values.join).not_to include '9999'
237
- end
238
- end
239
- it 'should handle invalid dates by returning the original value' do
240
- fields = mods_display_imprint(@invalid_dates).fields
241
- expect(fields.length).to eq(2)
242
- expect(fields.last.values).to eq(['1920-09-00'])
243
- end
244
- end
245
- end
246
-
247
- describe 'punctuation' do
248
- it 'should not duplicate punctuation' do
249
- fields = mods_display_imprint(@punctuation_imprint).fields
250
- expect(fields.length).to eq 1
251
- expect(fields.first.values).to eq ['San Francisco : Chronicle Books, 2015.']
252
- end
253
- end
254
-
255
- describe 'place processing' do
256
- it 'should exclude encoded places' do
257
- fields = mods_display_imprint(@encoded_place).fields
258
- expect(fields.length).to eq(1)
259
- expect(fields.first.values).to eq(['[Amsterdam]', '[United States]', 'Netherlands'])
260
- end
261
- it "should translate encoded place if there isn't a text (or non-typed) value available" do
262
- fields = mods_display_imprint(@encoded_place).fields
263
- expect(fields.length).to eq(1)
264
- expect(fields.first.values).to include 'Netherlands'
265
- end
266
- it "should ignore 'xx' country codes" do
267
- fields = mods_display_imprint(@xx_country_code).fields
268
- expect(fields.length).to eq(1)
269
- expect(fields.first.values).to eq(['1994'])
270
- end
271
- end
272
- describe 'to_html' do
273
- it 'should return the display form if one is available' do
274
- html = mods_display_imprint(@display_form).to_html
275
- expect(html.scan(/<dd>/).length).to eq(2)
276
- expect(html.scan(%r{<dd>The Display Form</dd>}).length).to eq(2)
277
- end
278
- it "should return the displayLabel when present if we're using the displayForm" do
279
- expect(mods_display_imprint(@display_form_with_label).to_html).to match(%r{<dt title='TheLabel'>TheLabel:</dt>})
280
- end
281
- it 'should have individual dt/dd pairs for mixed content' do
282
- html = mods_display_imprint(@mixed).to_html
283
- expect(html.scan(%r{<dt title='Imprint'>Imprint:</dt>}).length).to eq(1)
284
- expect(html.scan(%r{<dt title='Issuance'>Issuance:</dt>}).length).to eq(1)
285
- expect(html.scan(%r{<dt title='Date captured'>Date captured:</dt>}).length).to eq(1)
286
- expect(html.scan(/<dd>/).length).to eq(3)
287
- end
288
- end
289
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_language(mods_record)
4
- ModsDisplay::Language.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Language do
8
- before(:all) do
9
- @language = Stanford::Mods::Record.new.from_str(
10
- "<mods><language><languageTerm type='code'>eng</languageTerm></language></mods>", false
11
- ).language
12
- @display_label = Stanford::Mods::Record.new.from_str(
13
- "<mods><language displayLabel='Lang'><languageTerm type='code'>eng</languageTerm></language></mods>", false
14
- ).language
15
- @no_lang = Stanford::Mods::Record.new.from_str(
16
- "<mods><language displayLabel='Lang'><languageTerm type='code'>zzzxxx</languageTerm></language></mods>", false
17
- ).language
18
- @mixed = Stanford::Mods::Record.new.from_str(
19
- "<mods>
20
- <language><languageTerm type='text'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language>
21
- </mods>", false
22
- ).language
23
- @multi = Stanford::Mods::Record.new.from_str(
24
- "<mods>
25
- <language><languageTerm type='code'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language>
26
- </mods>", false
27
- ).language
28
- @display_form = Stanford::Mods::Record.new.from_str(
29
- '<mods><language><languageTerm>zzzxxx</languageTerm><displayForm>Klingon</displayForm></language></mods>', false
30
- ).language
31
- end
32
- describe 'fields' do
33
- it 'should return an array with a label/values object' do
34
- values = mods_display_language(@display_label).fields
35
- expect(values.length).to eq(1)
36
- expect(values.first).to be_a ModsDisplay::Values
37
- expect(values.first.label).to eq('Lang:')
38
- expect(values.first.values).to eq(['English'])
39
- end
40
- it "should not return any non type='code' languageTerms from the XML" do
41
- values = mods_display_language(@mixed).fields
42
- expect(values.length).to eq(1)
43
- expect(values.first.values).to eq(['English'])
44
- end
45
- it 'should handle multiple languages correctly' do
46
- values = mods_display_language(@multi).fields
47
- expect(values.length).to eq(1)
48
- expect(values.first.values).to eq(%w(German English))
49
- end
50
- end
51
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ModsDisplay::Location do
4
- let(:location_mods) do
5
- <<-XML
6
- <mods>
7
- <location>
8
- <shelfLocator>On Shelf A</shelfLocator>
9
- </location>
10
- </mods>
11
- XML
12
- end
13
-
14
- let(:url_mods) do
15
- <<-XML
16
- <mods>
17
- <location>
18
- <url displayLabel='Stanford University Library'>http://library.stanford.edu</url>
19
- </location>
20
- <location displayLabel='PURL'>
21
- <url>http://purl.stanford.edu</url>
22
- </location>
23
- </mods>
24
- XML
25
- end
26
-
27
- let(:repository_mods) do
28
- <<-XML
29
- <mods>
30
- <location>
31
- <physicalLocation type='repository'>Location Field</physicalLocation>
32
- </location>
33
- </mods>
34
- XML
35
- end
36
-
37
- let(:location) do
38
- mods = Stanford::Mods::Record.new.from_str(location_mods, false).location
39
- described_class.new(mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
40
- end
41
-
42
- let(:urls) do
43
- mods = Stanford::Mods::Record.new.from_str(url_mods, false).location
44
- described_class.new(mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
45
- end
46
-
47
- let(:repository_label) do
48
- mods = Stanford::Mods::Record.new.from_str(repository_mods, false).location
49
- described_class.new(mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
50
- end
51
-
52
- describe 'label' do
53
- it 'should have a default label' do
54
- expect(location.first.label).to eq 'Location:'
55
- end
56
-
57
- it 'should handle the URL labels correctly' do
58
- expect(urls.map(&:label)).to eq ['Location:', 'PURL:']
59
- end
60
-
61
- it 'should use get a label from a list of translations' do
62
- expect(repository_label.first.label).to eq 'Repository:'
63
- end
64
- end
65
-
66
- describe 'fields' do
67
- describe 'URLs' do
68
- it 'should link and use the displayLabel as text' do
69
- expect(urls.length).to eq(2)
70
- field = urls.find { |f| f.label == 'Location:' }
71
- expect(field.values).to eq(["<a href='http://library.stanford.edu'>Stanford University Library</a>"])
72
- end
73
-
74
- it 'should link the URL itself in the absence of a displayLabel on the url element' do
75
- expect(urls.length).to eq(2)
76
- field = urls.find { |f| f.label == 'PURL:' }
77
- expect(field.values).to eq(["<a href='http://purl.stanford.edu'>http://purl.stanford.edu</a>"])
78
- end
79
- end
80
- end
81
- end
@@ -1,166 +0,0 @@
1
- require 'spec_helper'
2
- require 'fixtures/name_fixtures'
3
- include NameFixtures
4
-
5
- def mods_display_name_link(mods_record)
6
- config = ModsDisplay::Configuration::Base.new do
7
- link :link_method, '%value%'
8
- end
9
- ModsDisplay::Name.new(mods_record, config, TestController.new)
10
- end
11
-
12
- def mods_display_name(mods_record)
13
- ModsDisplay::Name.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
14
- end
15
-
16
- describe ModsDisplay::Language do
17
- include NameFixtures
18
- before(:all) do
19
- @name = Stanford::Mods::Record.new.from_str(simple_name_fixture, false).plain_name
20
- @blank_name = Stanford::Mods::Record.new.from_str(blank_name_fixture, false).plain_name
21
- @primary_name = Stanford::Mods::Record.new.from_str(primary_name_fixture, false).plain_name
22
- @primary_name_solo = Stanford::Mods::Record.new.from_str(primary_name_solo_fixture, false).plain_name
23
- @contributor = Stanford::Mods::Record.new.from_str(contributor_fixture, false).plain_name
24
- @encoded_role = Stanford::Mods::Record.new.from_str(encoded_role_fixture, false).plain_name
25
- @mixed_role = Stanford::Mods::Record.new.from_str(mixed_role_fixture, false).plain_name
26
- @numeral_toa = Stanford::Mods::Record.new.from_str(numural_toa_fixture, false).plain_name
27
- @simple_toa = Stanford::Mods::Record.new.from_str(simple_toa_fixture, false).plain_name
28
- @display_form = Stanford::Mods::Record.new.from_str(display_form_name_fixture, false).plain_name
29
- @collapse_label = Stanford::Mods::Record.new.from_str(collapse_label_name_fixture, false).plain_name
30
- @complex_labels = Stanford::Mods::Record.new.from_str(complex_name_label_fixture, false).plain_name
31
- @complex_roles = Stanford::Mods::Record.new.from_str(complex_role_name_fixture, false).plain_name
32
- @name_with_role = Stanford::Mods::Record.new.from_str(name_with_role_fixture, false).plain_name
33
- @multiple_roles = Stanford::Mods::Record.new.from_str(multiple_roles_fixture, false).plain_name
34
- @author_role = Stanford::Mods::Record.new.from_str(author_role_fixture, false).plain_name
35
- @many_roles_and_names = Stanford::Mods::Record.new.from_str(many_roles_and_names_fixture, false).plain_name
36
- @names_with_code_and_text_roles = Stanford::Mods::Record.new.from_str(names_with_code_and_text_roles_fixture, false).plain_name
37
- end
38
- let(:default_label) { 'Associated with:' }
39
-
40
- describe 'label' do
41
- it 'should default Author/Creator when no role is available' do
42
- expect(mods_display_name(@name).fields.first.label).to eq(default_label)
43
- end
44
- it "should label as role for primary authors with a role" do
45
- expect(mods_display_name(@primary_name).fields.first.label).to eq('Lithographer:')
46
- end
47
- it "should label 'Author/Creator' for non-role primary authors" do
48
- expect(mods_display_name(@primary_name_solo).fields.first.label).to eq(default_label)
49
- end
50
- it 'should apply role labeling with text' do
51
- expect(mods_display_name(@contributor).fields.first.label).to eq('Lithographer:')
52
- end
53
- it 'should apply role labeling with code' do
54
- expect(mods_display_name(@author_role).fields.first.label).to eq('Author:')
55
- end
56
- end
57
-
58
- describe 'fields' do
59
- it 'should use the display form when available' do
60
- fields = mods_display_name(@display_form).fields
61
- expect(fields.length).to eq(1)
62
- expect(fields.first.values.length).to eq(1)
63
- expect(fields.first.values.first).to be_a(ModsDisplay::Name::Person)
64
- expect(fields.first.values.first.name).to eq('Mr. John Doe')
65
- end
66
- it 'should not add blank names' do
67
- expect(mods_display_name(@blank_name).fields).to eq([])
68
- end
69
- it 'should not delimit given name and termsOfAddress (that begin w/ roman numerals) with a comma' do
70
- fields = mods_display_name(@numeral_toa).fields
71
- expect(fields.length).to eq(1)
72
- expect(fields.first.values.length).to eq(1)
73
- expect(fields.first.values.first.to_s).not_to match(/Given Name, XVII/)
74
- expect(fields.first.values.first.to_s).to match(/Given Name XVII/)
75
- end
76
- it 'should delimit given name and termsOfAddress (that DO NOT begin w/ roman numerals) with a comma' do
77
- fields = mods_display_name(@simple_toa).fields
78
- expect(fields.length).to eq(1)
79
- expect(fields.first.values.length).to eq(1)
80
- expect(fields.first.values.first.to_s).to match(/Given Name, Ier, empereur/)
81
- expect(fields.first.values.first.to_s).not_to match(/Given Name Ier, empereur/)
82
- end
83
- it 'should collapse adjacent matching labels' do
84
- fields = mods_display_name(@collapse_label).fields
85
- expect(fields.length).to eq(1)
86
- expect(fields.first.label).to eq(default_label)
87
- fields.first.values.each do |val|
88
- expect(['John Doe', 'Jane Doe']).to include val.to_s
89
- end
90
- end
91
- it 'should perseve order and separation of non-adjesent matching labels' do
92
- fields = mods_display_name(@complex_labels).fields
93
-
94
- expect(fields.length).to eq(2)
95
- expect(fields.first.label).to eq(default_label)
96
- expect(fields.first.values.length).to eq(3)
97
- expect(fields.first.values.map(&:to_s)).to include 'John Doe', 'Jane Dough', 'John Dough'
98
-
99
- expect(fields[1].label).to eq('Lithographer:')
100
- expect(fields[1].values.length).to eq(1)
101
- expect(fields[1].values.first.name).to eq('Jane Doe')
102
- end
103
- describe 'roles' do
104
- it 'should get the role when present' do
105
- fields = mods_display_name(@name_with_role).fields
106
- expect(fields.length).to eq(1)
107
- expect(fields.first.label).to eq('Depicted:')
108
- expect(fields.first.values.length).to eq(1)
109
- expect(fields.first.values.first).to be_a(ModsDisplay::Name::Person)
110
- end
111
- it 'should decode encoded roleTerms when no text (or non-typed) roleTerm is available' do
112
- fields = mods_display_name(@encoded_role).fields
113
- expect(fields.length).to eq(1)
114
- expect(fields.first.label).to eq('Lithographer:')
115
- expect(fields.first.values.length).to eq(1)
116
- expect(fields.first.values.first.to_s).to eq('John Doe')
117
- end
118
- it "should get the type='text' role before an untyped role" do
119
- fields = mods_display_name(@mixed_role).fields
120
- expect(fields.length).to eq(2)
121
- expect(fields.first.label).to eq 'Publisher:'
122
- expect(fields.last.label).to eq 'Engraver:'
123
- expect(fields.first.values.length).to eq(1)
124
- expect(fields.last.values.length).to eq(1)
125
- expect(fields.first.values.first.name).to eq fields.last.values.first.name
126
- end
127
- it 'should be handled correctly when there are more than one' do
128
- fields = mods_display_name(@multiple_roles).fields
129
- expect(fields.length).to eq 2
130
- expect(fields.first.label).to eq 'Depicted:'
131
- expect(fields.last.label).to eq 'Artist:'
132
- expect(fields.first.values.length).to eq(1)
133
- expect(fields.last.values.length).to eq(1)
134
- expect(fields.first.values.first.name).to eq fields.last.values.first.name
135
- end
136
- it 'should handle code and text roleTerms together correctly' do
137
- fields = mods_display_name(@complex_roles).fields
138
- expect(fields.length).to eq 2
139
- expect(fields.first.label).to eq 'Depicted:'
140
- expect(fields.last.label).to eq 'Depositor:'
141
- expect(fields.first.values.first.name).to eq fields.last.values.first.name
142
- end
143
- it 'should handle consolidation of many roles and names' do
144
- fields = mods_display_name(@many_roles_and_names).fields
145
- expect(fields.length).to eq 6
146
- expect(fields.map(&:label)).to eq %w[Associated\ with: Surveyor: Cartographer: Editor: Electrotyper: Lithographer:]
147
- end
148
- it 'should handle consolidation of names with both code and text roleTerms' do
149
- fields = mods_display_name(@names_with_code_and_text_roles).fields
150
- expect(fields.length).to eq 3
151
- expect(fields.map(&:label)).to eq %w[Author: Printer: Donor:]
152
- end
153
- end
154
- end
155
-
156
- describe 'to_html' do
157
- it 'should add the role to the name in parens' do
158
- html = mods_display_name(@name_with_role).to_html
159
- expect(html).to match(%r{<dd>John Doe</dd>})
160
- end
161
- it 'should link the name and not the role if requested' do
162
- html = mods_display_name_link(@name_with_role).to_html
163
- expect(html).to match(%r{<dd><a href='.*\?John Doe'>John Doe</a></dd>})
164
- end
165
- end
166
- end