mods_display 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +60 -0
- data/.travis.yml +2 -2
- data/Rakefile +10 -2
- data/lib/mods_display.rb +42 -42
- data/lib/mods_display/configuration.rb +69 -67
- data/lib/mods_display/configuration/access_condition.rb +17 -13
- data/lib/mods_display/configuration/base.rb +27 -24
- data/lib/mods_display/configuration/format.rb +8 -4
- data/lib/mods_display/configuration/genre.rb +8 -4
- data/lib/mods_display/configuration/imprint.rb +12 -7
- data/lib/mods_display/configuration/name.rb +8 -4
- data/lib/mods_display/configuration/note.rb +8 -4
- data/lib/mods_display/configuration/related_item.rb +8 -4
- data/lib/mods_display/configuration/subject.rb +11 -9
- data/lib/mods_display/configuration/title.rb +8 -4
- data/lib/mods_display/controller_extension.rb +24 -24
- data/lib/mods_display/country_codes.rb +385 -384
- data/lib/mods_display/fields/abstract.rb +7 -6
- data/lib/mods_display/fields/access_condition.rb +55 -55
- data/lib/mods_display/fields/audience.rb +7 -6
- data/lib/mods_display/fields/cartographics.rb +15 -14
- data/lib/mods_display/fields/collection.rb +32 -17
- data/lib/mods_display/fields/contact.rb +15 -13
- data/lib/mods_display/fields/contents.rb +7 -6
- data/lib/mods_display/fields/description.rb +21 -21
- data/lib/mods_display/fields/field.rb +164 -109
- data/lib/mods_display/fields/format.rb +36 -33
- data/lib/mods_display/fields/genre.rb +12 -11
- data/lib/mods_display/fields/identifier.rb +34 -34
- data/lib/mods_display/fields/imprint.rb +258 -214
- data/lib/mods_display/fields/language.rb +18 -16
- data/lib/mods_display/fields/location.rb +27 -26
- data/lib/mods_display/fields/name.rb +113 -118
- data/lib/mods_display/fields/note.rb +33 -34
- data/lib/mods_display/fields/related_item.rb +64 -66
- data/lib/mods_display/fields/resource_type.rb +13 -11
- data/lib/mods_display/fields/sub_title.rb +6 -4
- data/lib/mods_display/fields/subject.rb +92 -90
- data/lib/mods_display/fields/title.rb +54 -49
- data/lib/mods_display/fields/values.rb +7 -8
- data/lib/mods_display/html.rb +117 -96
- data/lib/mods_display/model_extension.rb +17 -16
- data/lib/mods_display/relator_codes.rb +269 -267
- data/lib/mods_display/version.rb +1 -1
- data/mods_display.gemspec +13 -12
- data/spec/configuration/access_condition_spec.rb +5 -5
- data/spec/configuration/base_spec.rb +24 -24
- data/spec/fields/abstract_spec.rb +24 -14
- data/spec/fields/access_condition_spec.rb +80 -55
- data/spec/fields/audience_spec.rb +15 -12
- data/spec/fields/cartographics_spec.rb +17 -18
- data/spec/fields/collection_spec.rb +65 -19
- data/spec/fields/contact_spec.rb +11 -9
- data/spec/fields/contents_spec.rb +15 -12
- data/spec/fields/description_spec.rb +40 -22
- data/spec/fields/format_spec.rb +28 -18
- data/spec/fields/genre_spec.rb +18 -16
- data/spec/fields/identifier_spec.rb +46 -34
- data/spec/fields/imprint_spec.rb +151 -125
- data/spec/fields/language_spec.rb +36 -20
- data/spec/fields/location_spec.rb +43 -27
- data/spec/fields/name_spec.rb +92 -92
- data/spec/fields/note_spec.rb +53 -40
- data/spec/fields/related_item_spec.rb +42 -40
- data/spec/fields/resource_type_spec.rb +20 -14
- data/spec/fields/sub_title_spec.rb +11 -9
- data/spec/fields/subject_spec.rb +61 -56
- data/spec/fields/title_spec.rb +53 -40
- data/spec/fixtures/access_condition_fixtures.rb +50 -0
- data/spec/fixtures/cartographics_fixtures.rb +1 -1
- data/spec/fixtures/imprint_fixtures.rb +49 -1
- data/spec/fixtures/name_fixtures.rb +195 -2
- data/spec/fixtures/related_item_fixtures.rb +107 -0
- data/spec/fixtures/subjects_fixtures.rb +15 -2
- data/spec/fixtures/title_fixtures.rb +101 -0
- data/spec/integration/configuration_spec.rb +23 -20
- data/spec/integration/html_spec.rb +40 -29
- data/spec/integration/installation_spec.rb +14 -14
- data/spec/spec_helper.rb +5 -8
- metadata +25 -3
@@ -1,63 +1,65 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_item(mods_record)
|
4
|
-
ModsDisplay::RelatedItem.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::RelatedItem.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::RelatedItem do
|
8
|
+
include RelatedItemFixtures
|
9
|
+
|
8
10
|
before(:all) do
|
9
|
-
@item = Stanford::Mods::Record.new.from_str(
|
10
|
-
@linked_item = Stanford::Mods::Record.new.from_str(
|
11
|
-
@collection = Stanford::Mods::Record.new.from_str(
|
12
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
13
|
-
@location = Stanford::Mods::Record.new.from_str(
|
14
|
-
@reference = Stanford::Mods::Record.new.from_str(
|
15
|
-
@blank_item = Stanford::Mods::Record.new.from_str(
|
16
|
-
@multi_items = Stanford::Mods::Record.new.from_str(
|
11
|
+
@item = Stanford::Mods::Record.new.from_str(basic_related_item_fixture, false).related_item
|
12
|
+
@linked_item = Stanford::Mods::Record.new.from_str(linked_related_item_fixture, false).related_item
|
13
|
+
@collection = Stanford::Mods::Record.new.from_str(related_item_collection_fixture, false).related_item
|
14
|
+
@display_label = Stanford::Mods::Record.new.from_str(related_item_display_label_fixture, false).related_item
|
15
|
+
@location = Stanford::Mods::Record.new.from_str(related_item_location_fixture, false).related_item
|
16
|
+
@reference = Stanford::Mods::Record.new.from_str(related_item_reference_fixture, false).related_item
|
17
|
+
@blank_item = Stanford::Mods::Record.new.from_str(blank_related_item_fixture, false).related_item
|
18
|
+
@multi_items = Stanford::Mods::Record.new.from_str(multi_related_item_fixture, false).related_item
|
17
19
|
end
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
mods_display_item(@item).fields.first.label.
|
20
|
+
describe 'label' do
|
21
|
+
it 'should default to Related Item' do
|
22
|
+
expect(mods_display_item(@item).fields.first.label).to eq('Related item:')
|
21
23
|
end
|
22
|
-
it
|
23
|
-
mods_display_item(@location).fields.first.label.
|
24
|
+
it 'should get the location label' do
|
25
|
+
expect(mods_display_item(@location).fields.first.label).to eq('Location:')
|
24
26
|
end
|
25
|
-
it
|
26
|
-
mods_display_item(@reference).fields.first.label.
|
27
|
+
it 'should get the reference label' do
|
28
|
+
expect(mods_display_item(@reference).fields.first.label).to eq('Referenced by:')
|
27
29
|
end
|
28
|
-
it
|
29
|
-
mods_display_item(@display_label).fields.first.label.
|
30
|
+
it 'should get the displayLabel if available' do
|
31
|
+
expect(mods_display_item(@display_label).fields.first.label).to eq('Special Item:')
|
30
32
|
end
|
31
33
|
end
|
32
|
-
describe
|
33
|
-
it
|
34
|
+
describe 'fields' do
|
35
|
+
it 'should get a location if it is available' do
|
34
36
|
fields = mods_display_item(@item).fields
|
35
|
-
fields.length.
|
36
|
-
fields.first.values.
|
37
|
+
expect(fields.length).to eq(1)
|
38
|
+
expect(fields.first.values).to eq(['A Related Item'])
|
37
39
|
end
|
38
|
-
it
|
40
|
+
it 'should return a link if there is a location/url present' do
|
39
41
|
fields = mods_display_item(@linked_item).fields
|
40
|
-
fields.length.
|
41
|
-
fields.first.values.
|
42
|
+
expect(fields.length).to eq(1)
|
43
|
+
expect(fields.first.values).to eq(["<a href='http://library.stanford.edu/'>A Related Item</a>"])
|
42
44
|
end
|
43
|
-
it
|
44
|
-
mods_display_item(@collection).fields.
|
45
|
+
it 'should not return any fields if the described related item is a collection' do
|
46
|
+
expect(mods_display_item(@collection).fields).to eq([])
|
45
47
|
end
|
46
|
-
it
|
47
|
-
mods_display_item(@blank_item).fields.
|
48
|
+
it 'should not return empty links when there is no title or link' do
|
49
|
+
expect(mods_display_item(@blank_item).fields).to eq([])
|
48
50
|
end
|
49
|
-
it
|
51
|
+
it 'should concat the isReferencedBy related item title with other metadata' do
|
50
52
|
fields = mods_display_item(@reference).fields
|
51
|
-
fields.length.
|
52
|
-
fields.first.values.
|
53
|
+
expect(fields.length).to eq(1)
|
54
|
+
expect(fields.first.values).to eq(['The title DATE 124'])
|
53
55
|
end
|
54
|
-
it
|
56
|
+
it 'should collapse labels down into the same record' do
|
55
57
|
fields = mods_display_item(@multi_items).fields
|
56
|
-
fields.length.
|
57
|
-
fields.first.label.
|
58
|
-
fields.first.values.length.
|
59
|
-
fields.first.values.first.
|
60
|
-
fields.first.values.last.
|
58
|
+
expect(fields.length).to eq(1)
|
59
|
+
expect(fields.first.label).to eq('Related item:')
|
60
|
+
expect(fields.first.values.length).to eq(2)
|
61
|
+
expect(fields.first.values.first).to(match(%r{<a href=.*>Library</a>}))
|
62
|
+
expect(fields.first.values.last).to(match(%r{<a href=.*>SDR</a>}))
|
61
63
|
end
|
62
64
|
end
|
63
|
-
end
|
65
|
+
end
|
@@ -1,28 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_resource_type(mods_record)
|
4
|
-
ModsDisplay::ResourceType.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::ResourceType.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::ResourceType do
|
8
8
|
before(:all) do
|
9
|
-
@type = Stanford::Mods::Record.new.from_str(
|
10
|
-
|
11
|
-
|
9
|
+
@type = Stanford::Mods::Record.new.from_str(
|
10
|
+
'<mods><typeOfResource>Resource Type</typeOfResource></mods>', false
|
11
|
+
).typeOfResource
|
12
|
+
@downcase = Stanford::Mods::Record.new.from_str(
|
13
|
+
'<mods><typeOfResource>resource type</typeOfResource></mods>', false
|
14
|
+
).typeOfResource
|
15
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
16
|
+
"<mods><typeOfResource displayLabel='Special label'>Resource Type</typeOfResource></mods>", false
|
17
|
+
).typeOfResource
|
12
18
|
end
|
13
19
|
it "should default to a label of 'Type of resource'" do
|
14
20
|
fields = mods_display_resource_type(@type).fields
|
15
|
-
fields.length.
|
16
|
-
fields.first.label.
|
21
|
+
expect(fields.length).to eq(1)
|
22
|
+
expect(fields.first.label).to eq('Type of resource:')
|
17
23
|
end
|
18
|
-
it
|
24
|
+
it 'should use the displayLabel attribute when present' do
|
19
25
|
fields = mods_display_resource_type(@display_label).fields
|
20
|
-
fields.length.
|
21
|
-
fields.first.label.
|
26
|
+
expect(fields.length).to eq(1)
|
27
|
+
expect(fields.first.label).to eq('Special label:')
|
22
28
|
end
|
23
|
-
it
|
29
|
+
it 'should capitalize the first letter of the values' do
|
24
30
|
fields = mods_display_resource_type(@downcase).fields
|
25
|
-
fields.length.
|
26
|
-
fields.first.values.
|
31
|
+
expect(fields.length).to eq(1)
|
32
|
+
expect(fields.first.values).to eq(['Resource type'])
|
27
33
|
end
|
28
|
-
end
|
34
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_sub_title(mods_record)
|
4
|
-
ModsDisplay::SubTitle.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::SubTitle.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::SubTitle do
|
8
8
|
before(:all) do
|
9
|
-
@title = Stanford::Mods::Record.new.from_str(
|
9
|
+
@title = Stanford::Mods::Record.new.from_str(
|
10
|
+
'<mods><titleInfo><title>Main Title</title></titleInfo><titleInfo><title>Sub Title</title></titleInfo></mods>',
|
11
|
+
false
|
12
|
+
).title_info
|
10
13
|
end
|
11
|
-
it
|
14
|
+
it 'omit the main title and only return sub titles' do
|
12
15
|
fields = mods_display_sub_title(@title).fields
|
13
|
-
fields.length.
|
14
|
-
fields.first.label.
|
15
|
-
fields.first.values.
|
16
|
-
|
16
|
+
expect(fields.length).to eq(1)
|
17
|
+
expect(fields.first.label).to eq('Title:')
|
18
|
+
expect(fields.first.values).to eq(['Sub Title'])
|
17
19
|
end
|
18
|
-
end
|
20
|
+
end
|
data/spec/fields/subject_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/subjects_fixtures'
|
3
3
|
include SubjectsFixtures
|
4
4
|
|
5
5
|
def mods_display_subject(mods_record)
|
6
6
|
config = ModsDisplay::Configuration::Subject.new do
|
7
|
-
link :link_method,
|
7
|
+
link :link_method, '%value%'
|
8
8
|
end
|
9
9
|
ModsDisplay::Subject.new(mods_record, config, TestController.new)
|
10
10
|
end
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
def mods_display_hierarchical_subject(mods_record)
|
13
13
|
config = ModsDisplay::Configuration::Subject.new do
|
14
14
|
hierarchical_link true
|
15
|
-
link :link_method,
|
15
|
+
link :link_method, '%value%'
|
16
16
|
end
|
17
17
|
ModsDisplay::Subject.new(mods_record, config, TestController.new)
|
18
18
|
end
|
@@ -24,86 +24,91 @@ describe ModsDisplay::Subject do
|
|
24
24
|
@emdash_subject = Stanford::Mods::Record.new.from_str(emdash_subjects, false).subject
|
25
25
|
@geo_subject = Stanford::Mods::Record.new.from_str(hierarchical_geo_subjects, false).subject
|
26
26
|
@name_subject = Stanford::Mods::Record.new.from_str(name_subjects, false).subject
|
27
|
+
@blank_name_subject = Stanford::Mods::Record.new.from_str(blank_name_subject, false).subject
|
27
28
|
@complex_subject = Stanford::Mods::Record.new.from_str(complex_subjects, false).subject
|
28
29
|
@display_label = Stanford::Mods::Record.new.from_str(display_label_subjects, false).subject
|
29
30
|
end
|
30
|
-
describe
|
31
|
-
it
|
31
|
+
describe 'fields' do
|
32
|
+
it 'should split individual child elments of subject into separate parts' do
|
32
33
|
fields = mods_display_subject(@subject).fields
|
33
|
-
fields.length.
|
34
|
-
fields.first.values.
|
34
|
+
expect(fields.length).to eq(1)
|
35
|
+
expect(fields.first.values).to eq([['Jazz', 'Japan', 'History and criticism']])
|
35
36
|
end
|
36
|
-
it
|
37
|
+
it 'should split horizontalized subjects split with an emdash into separate parts' do
|
37
38
|
fields = mods_display_subject(@emdash_subject).fields
|
38
|
-
fields.length.
|
39
|
-
fields.first.values.
|
39
|
+
expect(fields.length).to eq(1)
|
40
|
+
expect(fields.first.values).to eq([['Jazz', 'Japan', 'History and criticism']])
|
40
41
|
end
|
41
|
-
it
|
42
|
+
it 'should handle hierarchicalGeogaphic subjects properly' do
|
42
43
|
fields = mods_display_subject(@geo_subject).fields
|
43
|
-
fields.length.
|
44
|
-
fields.first.values.
|
44
|
+
expect(fields.length).to eq(1)
|
45
|
+
expect(fields.first.values).to eq([['United States', 'California', 'Stanford']])
|
45
46
|
end
|
46
|
-
it
|
47
|
+
it 'should handle display labels properly' do
|
47
48
|
fields = mods_display_subject(@display_label).fields
|
48
|
-
fields.length.
|
49
|
-
fields.first.label.
|
50
|
-
fields.first.values.
|
51
|
-
fields[1].label.
|
52
|
-
fields[1].values.
|
53
|
-
fields.last.label.
|
54
|
-
fields.last.values.
|
49
|
+
expect(fields.length).to eq(3)
|
50
|
+
expect(fields.first.label).to eq('Subject:')
|
51
|
+
expect(fields.first.values).to eq([['A Subject', 'Another Subject'], ['B Subject', 'Another B Subject']])
|
52
|
+
expect(fields[1].label).to eq('Subject Heading:')
|
53
|
+
expect(fields[1].values).to eq([['Jazz', 'Japan', 'History and criticism']])
|
54
|
+
expect(fields.last.label).to eq('Subject:')
|
55
|
+
expect(fields.last.values).to eq([['Bay Area', 'Stanford']])
|
55
56
|
end
|
56
|
-
it
|
57
|
-
mods_display_subject(@blank_subject).fields.
|
57
|
+
it 'should handle blank subjects properly' do
|
58
|
+
expect(mods_display_subject(@blank_subject).fields).to eq([])
|
59
|
+
end
|
60
|
+
it 'should handle blank name subjects properly' do
|
61
|
+
expect(mods_display_subject(@blank_name_subject).fields).to eq([])
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
|
-
describe
|
62
|
-
it
|
65
|
+
describe 'name subjects' do
|
66
|
+
it 'should handle name subjects properly' do
|
63
67
|
fields = mods_display_subject(@name_subject).fields
|
64
|
-
fields.length.
|
65
|
-
fields.first.values.first.first.
|
66
|
-
fields.first.values.first.first.name.
|
67
|
-
fields.first.values.first.first.roles.
|
68
|
+
expect(fields.length).to eq(1)
|
69
|
+
expect(fields.first.values.first.first).to be_a(ModsDisplay::Name::Person)
|
70
|
+
expect(fields.first.values.first.first.name).to eq('John Doe')
|
71
|
+
expect(fields.first.values.first.first.roles).to eq(['Depicted'])
|
68
72
|
end
|
69
|
-
it
|
73
|
+
it 'should link the name (and not the role) correctly' do
|
70
74
|
html = mods_display_subject(@name_subject).to_html
|
71
|
-
html.
|
72
|
-
html.
|
75
|
+
expect(html).to match(%r{<a href='.*\?John Doe'>John Doe</a> \(Depicted\)})
|
76
|
+
expect(html).to match(%r{<a href='.*\?Anonymous People'>Anonymous People</a>})
|
73
77
|
end
|
74
|
-
it
|
78
|
+
it 'should linke the name (and not the role) correctly when linking hierarchicaly' do
|
75
79
|
html = mods_display_hierarchical_subject(@name_subject).to_html
|
76
|
-
html.
|
77
|
-
html.
|
80
|
+
expect(html).to match(%r{<a href='.*\?John Doe'>John Doe</a> \(Depicted\)})
|
81
|
+
expect(html).to match(%r{<a href='.*\?John Doe Anonymous People'>Anonymous People</a>})
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
81
|
-
describe
|
82
|
-
it
|
85
|
+
describe 'to_html' do
|
86
|
+
it 'should link the values when requested' do
|
83
87
|
html = mods_display_subject(@subject).to_html
|
84
|
-
html.
|
85
|
-
html.
|
86
|
-
html.
|
88
|
+
expect(html).to match(%r{<a href='http://library.stanford.edu\?Jazz'>Jazz</a>})
|
89
|
+
expect(html).to match(%r{<a href='http://library.stanford.edu\?Japan'>Japan</a>})
|
90
|
+
expect(html).to match(%r{<a href='http://library.stanford.edu\?History and criticism'>History and criticism</a>})
|
87
91
|
end
|
88
|
-
it
|
92
|
+
it 'does something' do
|
89
93
|
html = mods_display_hierarchical_subject(@subject).to_html
|
90
|
-
html.
|
91
|
-
html.
|
92
|
-
html.
|
94
|
+
expect(html).to match(%r{<a href='http://library.stanford.edu\?Jazz'>Jazz</a>})
|
95
|
+
expect(html).to match(%r{<a href='http://library.stanford.edu\?Jazz Japan'>Japan</a>})
|
96
|
+
expect(html).to match(
|
97
|
+
%r{<a href='http://library.stanford.edu\?Jazz Japan History and criticism'>History and criticism</a>}
|
98
|
+
)
|
93
99
|
end
|
94
|
-
it
|
100
|
+
it 'should collapse fields into the same label' do
|
95
101
|
html = mods_display_subject(@complex_subject).to_html
|
96
|
-
html.scan(
|
97
|
-
html.scan(/<dd>/).length.
|
98
|
-
html.scan(
|
99
|
-
html.scan(/ > /).length.
|
102
|
+
expect(html.scan(%r{<dt title='Subject'>Subject:</dt>}).length).to eq(1)
|
103
|
+
expect(html.scan(/<dd>/).length).to eq(1)
|
104
|
+
expect(html.scan(%r{<br/>}).length).to eq(1)
|
105
|
+
expect(html.scan(/ > /).length).to eq(3)
|
100
106
|
end
|
101
|
-
it
|
107
|
+
it 'should handle complex display labels' do
|
102
108
|
html = mods_display_subject(@display_label).to_html
|
103
|
-
html.scan(
|
104
|
-
html.scan(
|
105
|
-
html.scan(/<dd>/).length.
|
109
|
+
expect(html.scan(%r{<dt title='Subject'>Subject:</dt>}).length).to eq 2
|
110
|
+
expect(html.scan(%r{<dt title='Subject Heading'>Subject Heading:</dt>}).length).to eq 1
|
111
|
+
expect(html.scan(/<dd>/).length).to eq(3)
|
106
112
|
end
|
107
113
|
end
|
108
|
-
|
109
|
-
end
|
114
|
+
end
|
data/spec/fields/title_spec.rb
CHANGED
@@ -1,61 +1,74 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_title(mods_record)
|
4
|
-
ModsDisplay::Title.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Title.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Title do
|
8
|
+
include TitleFixtures
|
8
9
|
before(:all) do
|
9
|
-
@title = Stanford::Mods::Record.new.from_str(
|
10
|
-
@title_parts = Stanford::Mods::Record.new.from_str(
|
11
|
-
@reverse_title_parts = Stanford::Mods::Record.new.from_str(
|
12
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
13
|
-
@display_form = Stanford::Mods::Record.new.from_str(
|
14
|
-
@multi_label = Stanford::Mods::Record.new.from_str(
|
15
|
-
@alt_title = Stanford::Mods::Record.new.from_str(
|
10
|
+
@title = Stanford::Mods::Record.new.from_str(simple_title_fixture, false).title_info
|
11
|
+
@title_parts = Stanford::Mods::Record.new.from_str(title_parts_fixture, false).title_info
|
12
|
+
@reverse_title_parts = Stanford::Mods::Record.new.from_str(reverse_title_parts_fixture, false).title_info
|
13
|
+
@display_label = Stanford::Mods::Record.new.from_str(display_label_fixture, false).title_info
|
14
|
+
@display_form = Stanford::Mods::Record.new.from_str(display_form_fixture, false).title_info
|
15
|
+
@multi_label = Stanford::Mods::Record.new.from_str(multi_label_fixture, false).title_info
|
16
|
+
@alt_title = Stanford::Mods::Record.new.from_str(alt_title_fixture, false).title_info
|
17
|
+
@title_punctuation = Stanford::Mods::Record.new.from_str(title_puncutation_fixture, false).title_info
|
16
18
|
end
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
mods_display_title(@title).fields.first.label.
|
19
|
+
describe 'labels' do
|
20
|
+
it 'should return a default label of Title if nothing else is available' do
|
21
|
+
expect(mods_display_title(@title).fields.first.label).to eq('Title:')
|
20
22
|
end
|
21
|
-
it
|
22
|
-
mods_display_title(@alt_title).fields.first.label.
|
23
|
+
it 'should return an appropriate label from the type attribute' do
|
24
|
+
expect(mods_display_title(@alt_title).fields.first.label).to eq('Alternative title:')
|
23
25
|
end
|
24
|
-
it
|
25
|
-
mods_display_title(@display_label).fields.first.label.
|
26
|
+
it 'should return the label held in the displayLabel attribute of the titleInfo element when available' do
|
27
|
+
expect(mods_display_title(@display_label).fields.first.label).to eq('MyTitle:')
|
26
28
|
end
|
27
|
-
it
|
29
|
+
it 'should collapse adjacent identical labels' do
|
28
30
|
fields = mods_display_title(@multi_label).fields
|
29
|
-
fields.length.
|
30
|
-
fields[0].label.
|
31
|
-
fields[1].label.
|
32
|
-
fields[2].label.
|
33
|
-
fields[3].label.
|
34
|
-
fields[3].values.
|
31
|
+
expect(fields.length).to eq(4)
|
32
|
+
expect(fields[0].label).to eq('Title:')
|
33
|
+
expect(fields[1].label).to eq('Alternative title:')
|
34
|
+
expect(fields[2].label).to eq('Uniform title:')
|
35
|
+
expect(fields[3].label).to eq('Alternative title:')
|
36
|
+
expect(fields[3].values).to eq(['Another Alt Title', 'Yet Another Alt Title'])
|
35
37
|
end
|
36
38
|
end
|
37
|
-
describe
|
38
|
-
it
|
39
|
+
describe 'fields' do
|
40
|
+
it 'should return an array of label/value objects' do
|
39
41
|
values = mods_display_title(@display_label).fields
|
40
|
-
values.length.
|
41
|
-
values.first.
|
42
|
-
values.first.label.
|
43
|
-
values.first.values.
|
42
|
+
expect(values.length).to eq(1)
|
43
|
+
expect(values.first).to be_a ModsDisplay::Values
|
44
|
+
expect(values.first.label).to eq('MyTitle:')
|
45
|
+
expect(values.first.values).to eq(['Title'])
|
44
46
|
end
|
45
47
|
end
|
46
|
-
describe
|
47
|
-
it
|
48
|
-
mods_display_title(@title_parts).fields.first.values.
|
48
|
+
describe 'text' do
|
49
|
+
it 'should construct all the elements in titleInfo' do
|
50
|
+
expect(mods_display_title(@title_parts).fields.first.values).to include 'The Title : For. Something. Part 62'
|
49
51
|
end
|
50
|
-
|
51
|
-
|
52
|
+
|
53
|
+
it 'should use the correct delimiter in the case that a partNumber comes before a partName' do
|
54
|
+
expect(mods_display_title(@reverse_title_parts).fields.first.values).to include(
|
55
|
+
'The Title : For. Part 62, Something'
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should use the displayForm when available' do
|
60
|
+
expect(mods_display_title(@display_form).fields.first.values).to include 'The Title of This Item'
|
52
61
|
end
|
53
|
-
|
54
|
-
|
62
|
+
|
63
|
+
it 'should return the basic text held in a sub element of titleInfo' do
|
64
|
+
expect(mods_display_title(@title).fields.first.values).to include 'Title'
|
55
65
|
end
|
56
|
-
|
57
|
-
|
66
|
+
|
67
|
+
it 'should not duplicate delimiter punctuation' do
|
68
|
+
values = mods_display_title(@title_punctuation).fields.first.values
|
69
|
+
expect(values.length).to eq 1
|
70
|
+
expect(values.first).not_to include '..'
|
71
|
+
expect(values.first).to eq 'A title that ends in punctuation. 2015'
|
58
72
|
end
|
59
73
|
end
|
60
|
-
|
61
|
-
end
|
74
|
+
end
|