mods_display 0.3.3 → 0.3.4
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.
- 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,35 +1,51 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_language(mods_record)
|
4
|
-
ModsDisplay::Language.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Language.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Language do
|
8
8
|
before(:all) do
|
9
|
-
@language = Stanford::Mods::Record.new.from_str(
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
|
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
|
15
31
|
end
|
16
|
-
describe
|
17
|
-
it
|
32
|
+
describe 'fields' do
|
33
|
+
it 'should return an array with a label/values object' do
|
18
34
|
values = mods_display_language(@display_label).fields
|
19
|
-
values.length.
|
20
|
-
values.first.
|
21
|
-
values.first.label.
|
22
|
-
values.first.values.
|
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'])
|
23
39
|
end
|
24
40
|
it "should not return any non type='code' languageTerms from the XML" do
|
25
41
|
values = mods_display_language(@mixed).fields
|
26
|
-
values.length.
|
27
|
-
values.first.values.
|
42
|
+
expect(values.length).to eq(1)
|
43
|
+
expect(values.first.values).to eq(['English'])
|
28
44
|
end
|
29
|
-
it
|
45
|
+
it 'should handle multiple languages correctly' do
|
30
46
|
values = mods_display_language(@multi).fields
|
31
|
-
values.length.
|
32
|
-
values.first.values.
|
47
|
+
expect(values.length).to eq(1)
|
48
|
+
expect(values.first.values).to eq(%w(German English))
|
33
49
|
end
|
34
50
|
end
|
35
|
-
end
|
51
|
+
end
|
@@ -1,44 +1,60 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_location(mods_record)
|
4
|
-
ModsDisplay::Location.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Location.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Note do
|
8
8
|
before(:all) do
|
9
|
-
@location = Stanford::Mods::Record.new.from_str(
|
10
|
-
|
11
|
-
|
12
|
-
@
|
9
|
+
@location = Stanford::Mods::Record.new.from_str(
|
10
|
+
'<mods><location><physicalLocation>The Location</physicalLocation></location></mods>', false
|
11
|
+
).location
|
12
|
+
@urls = Stanford::Mods::Record.new.from_str(
|
13
|
+
"<mods>
|
14
|
+
<location>
|
15
|
+
<url displayLabel='Stanford University Library'>http://library.stanford.edu</url>
|
16
|
+
</location>
|
17
|
+
<location displayLabel='PURL'>
|
18
|
+
<url>http://purl.stanford.edu</url>
|
19
|
+
</location>
|
20
|
+
</mods>",
|
21
|
+
false
|
22
|
+
).location
|
23
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
24
|
+
"<mods><location displayLabel='Special Label'><shelfLocation>On Shelf A</shelfLocation></location></mods>", false
|
25
|
+
).location
|
26
|
+
@repository_label = Stanford::Mods::Record.new.from_str(
|
27
|
+
"<mods><location><physicalLocation type='repository'>Location Field</physicalLocation></location></mods>", false
|
28
|
+
).location
|
13
29
|
end
|
14
|
-
describe
|
15
|
-
it
|
16
|
-
mods_display_location(@location).fields.first.label.
|
30
|
+
describe 'label' do
|
31
|
+
it 'should have a default label' do
|
32
|
+
expect(mods_display_location(@location).fields.first.label).to eq('Location:')
|
17
33
|
end
|
18
|
-
it
|
19
|
-
mods_display_location(@display_label).fields.first.label.
|
34
|
+
it 'should use the displayLabel attribute when one is available' do
|
35
|
+
expect(mods_display_location(@display_label).fields.first.label).to eq('Special Label:')
|
20
36
|
end
|
21
|
-
it
|
22
|
-
mods_display_location(@urls).fields.map
|
37
|
+
it 'should handle the URL labels correctly' do
|
38
|
+
expect(mods_display_location(@urls).fields.map(&:label)).to eq(['Location:', 'PURL:'])
|
23
39
|
end
|
24
|
-
it
|
25
|
-
mods_display_location(@repository_label).fields.first.label.
|
40
|
+
it 'should use get a label from a list of translations' do
|
41
|
+
expect(mods_display_location(@repository_label).fields.first.label).to eq('Repository:')
|
26
42
|
end
|
27
|
-
end
|
28
|
-
describe
|
29
|
-
describe
|
30
|
-
it
|
43
|
+
end
|
44
|
+
describe 'fields' do
|
45
|
+
describe 'URLs' do
|
46
|
+
it 'should link and use the displayLabel as text' do
|
31
47
|
fields = mods_display_location(@urls).fields
|
32
|
-
fields.length.
|
33
|
-
field = fields.find{|f| f.label ==
|
34
|
-
field.values.
|
48
|
+
expect(fields.length).to eq(2)
|
49
|
+
field = fields.find { |f| f.label == 'Location:' }
|
50
|
+
expect(field.values).to eq(["<a href='http://library.stanford.edu'>Stanford University Library</a>"])
|
35
51
|
end
|
36
|
-
it
|
52
|
+
it 'should link the URL itself in the absence of a displayLabel on the url element' do
|
37
53
|
fields = mods_display_location(@urls).fields
|
38
|
-
fields.length.
|
39
|
-
field = fields.find{|f| f.label ==
|
40
|
-
field.values.
|
54
|
+
expect(fields.length).to eq(2)
|
55
|
+
field = fields.find { |f| f.label == 'PURL:' }
|
56
|
+
expect(field.values).to eq(["<a href='http://purl.stanford.edu'>http://purl.stanford.edu</a>"])
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|
44
|
-
end
|
60
|
+
end
|
data/spec/fields/name_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/name_fixtures'
|
3
3
|
include NameFixtures
|
4
4
|
|
5
5
|
def mods_display_name_link(mods_record)
|
@@ -10,140 +10,140 @@ def mods_display_name_link(mods_record)
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def mods_display_name(mods_record)
|
13
|
-
ModsDisplay::Name.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
13
|
+
ModsDisplay::Name.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
14
14
|
end
|
15
15
|
|
16
16
|
describe ModsDisplay::Language do
|
17
|
+
include NameFixtures
|
17
18
|
before(:all) do
|
18
|
-
@name = Stanford::Mods::Record.new.from_str(
|
19
|
-
@blank_name = Stanford::Mods::Record.new.from_str(
|
20
|
-
@primary_name = Stanford::Mods::Record.new.from_str(
|
21
|
-
@contributor = Stanford::Mods::Record.new.from_str(
|
22
|
-
@encoded_role = Stanford::Mods::Record.new.from_str(
|
23
|
-
@mixed_role = Stanford::Mods::Record.new.from_str(
|
24
|
-
@numeral_toa = Stanford::Mods::Record.new.from_str(
|
25
|
-
@simple_toa = Stanford::Mods::Record.new.from_str(
|
26
|
-
@display_form = Stanford::Mods::Record.new.from_str(
|
27
|
-
@collapse_label = Stanford::Mods::Record.new.from_str(
|
28
|
-
@complex_labels = Stanford::Mods::Record.new.from_str(
|
29
|
-
@complex_roles = Stanford::Mods::Record.new.from_str(
|
30
|
-
@name_with_role = Stanford::Mods::Record.new.from_str(
|
31
|
-
@multiple_roles = Stanford::Mods::Record.new.from_str(
|
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
|
+
@contributor = Stanford::Mods::Record.new.from_str(contributor_fixture, false).plain_name
|
23
|
+
@encoded_role = Stanford::Mods::Record.new.from_str(encoded_role_fixture, false).plain_name
|
24
|
+
@mixed_role = Stanford::Mods::Record.new.from_str(mixed_role_fixture, false).plain_name
|
25
|
+
@numeral_toa = Stanford::Mods::Record.new.from_str(numural_toa_fixture, false).plain_name
|
26
|
+
@simple_toa = Stanford::Mods::Record.new.from_str(simple_toa_fixture, false).plain_name
|
27
|
+
@display_form = Stanford::Mods::Record.new.from_str(display_form_name_fixture, false).plain_name
|
28
|
+
@collapse_label = Stanford::Mods::Record.new.from_str(collapse_label_name_fixture, false).plain_name
|
29
|
+
@complex_labels = Stanford::Mods::Record.new.from_str(complex_name_label_fixture, false).plain_name
|
30
|
+
@complex_roles = Stanford::Mods::Record.new.from_str(complex_role_name_fixture, false).plain_name
|
31
|
+
@name_with_role = Stanford::Mods::Record.new.from_str(name_with_role_fixture, false).plain_name
|
32
|
+
@multiple_roles = Stanford::Mods::Record.new.from_str(multiple_roles_fixture, false).plain_name
|
32
33
|
end
|
33
|
-
describe
|
34
|
-
it
|
35
|
-
mods_display_name(@name).fields.first.label.
|
34
|
+
describe 'label' do
|
35
|
+
it 'should default Author/Creator when no role is available' do
|
36
|
+
expect(mods_display_name(@name).fields.first.label).to eq('Author/Creator:')
|
36
37
|
end
|
37
38
|
it "should label 'Author/Creator' for primary authors" do
|
38
|
-
mods_display_name(@primary_name).fields.first.label.
|
39
|
+
expect(mods_display_name(@primary_name).fields.first.label).to eq('Author/Creator:')
|
39
40
|
end
|
40
|
-
it
|
41
|
-
mods_display_name(@contributor).fields.first.label.
|
41
|
+
it 'should apply contributor labeling to all non blank/author/creator roles' do
|
42
|
+
expect(mods_display_name(@contributor).fields.first.label).to eq('Contributor:')
|
42
43
|
end
|
43
44
|
end
|
44
|
-
|
45
|
-
describe
|
46
|
-
it
|
45
|
+
|
46
|
+
describe 'fields' do
|
47
|
+
it 'should use the display form when available' do
|
47
48
|
fields = mods_display_name(@display_form).fields
|
48
|
-
fields.length.
|
49
|
-
fields.first.values.length.
|
50
|
-
fields.first.values.first.
|
51
|
-
fields.first.values.first.name.
|
49
|
+
expect(fields.length).to eq(1)
|
50
|
+
expect(fields.first.values.length).to eq(1)
|
51
|
+
expect(fields.first.values.first).to be_a(ModsDisplay::Name::Person)
|
52
|
+
expect(fields.first.values.first.name).to eq('Mr. John Doe')
|
52
53
|
end
|
53
|
-
it
|
54
|
-
mods_display_name(@blank_name).fields.
|
54
|
+
it 'should not add blank names' do
|
55
|
+
expect(mods_display_name(@blank_name).fields).to eq([])
|
55
56
|
end
|
56
|
-
it
|
57
|
+
it 'should not delimit given name and termsOfAddress (that begin w/ roman numerals) with a comma' do
|
57
58
|
fields = mods_display_name(@numeral_toa).fields
|
58
|
-
fields.length.
|
59
|
-
fields.first.values.length.
|
60
|
-
fields.first.values.first.to_s.
|
61
|
-
fields.first.values.first.to_s.
|
59
|
+
expect(fields.length).to eq(1)
|
60
|
+
expect(fields.first.values.length).to eq(1)
|
61
|
+
expect(fields.first.values.first.to_s).not_to match(/Given Name, XVII/)
|
62
|
+
expect(fields.first.values.first.to_s).to match(/Given Name XVII/)
|
62
63
|
end
|
63
|
-
it
|
64
|
+
it 'should delimit given name and termsOfAddress (that DO NOT begin w/ roman numerals) with a comma' do
|
64
65
|
fields = mods_display_name(@simple_toa).fields
|
65
|
-
fields.length.
|
66
|
-
fields.first.values.length.
|
67
|
-
fields.first.values.first.to_s.
|
68
|
-
fields.first.values.first.to_s.
|
66
|
+
expect(fields.length).to eq(1)
|
67
|
+
expect(fields.first.values.length).to eq(1)
|
68
|
+
expect(fields.first.values.first.to_s).to match(/Given Name, Ier, empereur/)
|
69
|
+
expect(fields.first.values.first.to_s).not_to match(/Given Name Ier, empereur/)
|
69
70
|
end
|
70
|
-
it
|
71
|
+
it 'should collapse adjacent matching labels' do
|
71
72
|
fields = mods_display_name(@collapse_label).fields
|
72
|
-
fields.length.
|
73
|
-
fields.first.label.
|
73
|
+
expect(fields.length).to eq(1)
|
74
|
+
expect(fields.first.label).to eq('Author/Creator:')
|
74
75
|
fields.first.values.each do |val|
|
75
|
-
[
|
76
|
+
expect(['John Doe', 'Jane Doe']).to include val.to_s
|
76
77
|
end
|
77
78
|
end
|
78
|
-
it
|
79
|
+
it 'should perseve order and separation of non-adjesent matching labels' do
|
79
80
|
fields = mods_display_name(@complex_labels).fields
|
80
81
|
|
81
|
-
fields.length.
|
82
|
-
fields.first.label.
|
83
|
-
fields.first.values.length.
|
84
|
-
fields.first.values.first.to_s.
|
85
|
-
|
86
|
-
fields[1].label.
|
87
|
-
fields[1].values.length.
|
88
|
-
fields[1].values.first.name.
|
89
|
-
fields[1].values.first.roles.
|
82
|
+
expect(fields.length).to eq(3)
|
83
|
+
expect(fields.first.label).to eq('Author/Creator:')
|
84
|
+
expect(fields.first.values.length).to eq(1)
|
85
|
+
expect(fields.first.values.first.to_s).to eq('John Doe')
|
86
|
+
|
87
|
+
expect(fields[1].label).to eq('Contributor:')
|
88
|
+
expect(fields[1].values.length).to eq(1)
|
89
|
+
expect(fields[1].values.first.name).to eq('Jane Doe')
|
90
|
+
expect(fields[1].values.first.roles).to eq(['lithographer'])
|
90
91
|
|
91
|
-
fields.last.label.
|
92
|
-
fields.last.values.length.
|
92
|
+
expect(fields.last.label).to eq('Author/Creator:')
|
93
|
+
expect(fields.last.values.length).to eq(2)
|
93
94
|
fields.last.values.each do |val|
|
94
|
-
[
|
95
|
+
expect(['Jane Dough', 'John Dough']).to include val.to_s
|
95
96
|
end
|
96
97
|
end
|
97
|
-
describe
|
98
|
-
it
|
98
|
+
describe 'roles' do
|
99
|
+
it 'should get the role when present' do
|
99
100
|
fields = mods_display_name(@name_with_role).fields
|
100
|
-
fields.length.
|
101
|
-
fields.first.values.length.
|
102
|
-
fields.first.values.first.
|
103
|
-
fields.first.values.first.roles.
|
101
|
+
expect(fields.length).to eq(1)
|
102
|
+
expect(fields.first.values.length).to eq(1)
|
103
|
+
expect(fields.first.values.first).to be_a(ModsDisplay::Name::Person)
|
104
|
+
expect(fields.first.values.first.roles).to eq(['Depicted'])
|
104
105
|
end
|
105
|
-
it
|
106
|
+
it 'should decode encoded roleTerms when no text (or non-typed) roleTerm is available' do
|
106
107
|
fields = mods_display_name(@encoded_role).fields
|
107
|
-
fields.length.
|
108
|
-
fields.first.values.length.
|
109
|
-
fields.first.values.first.to_s.
|
108
|
+
expect(fields.length).to eq(1)
|
109
|
+
expect(fields.first.values.length).to eq(1)
|
110
|
+
expect(fields.first.values.first.to_s).to eq('John Doe (Lithographer)')
|
110
111
|
end
|
111
112
|
it "should get the type='text' role before an untyped role" do
|
112
113
|
fields = mods_display_name(@mixed_role).fields
|
113
|
-
fields.length.
|
114
|
-
fields.first.values.length.
|
115
|
-
fields.first.values.first.roles.
|
114
|
+
expect(fields.length).to eq(1)
|
115
|
+
expect(fields.first.values.length).to eq(1)
|
116
|
+
expect(fields.first.values.first.roles).to eq(['engraver'])
|
116
117
|
end
|
117
|
-
it
|
118
|
+
it 'should be handled correctly when there are more than one' do
|
118
119
|
fields = mods_display_name(@multiple_roles).fields
|
119
|
-
fields.length.
|
120
|
-
fields.first.values.length.
|
121
|
-
fields.first.values.first.roles.
|
120
|
+
expect(fields.length).to eq(1)
|
121
|
+
expect(fields.first.values.length).to eq(1)
|
122
|
+
expect(fields.first.values.first.roles).to eq(%w(Depicted Artist))
|
122
123
|
end
|
123
|
-
it
|
124
|
+
it 'should handle code and text roleTerms together correctly' do
|
124
125
|
fields = mods_display_name(@complex_roles).fields
|
125
|
-
fields.length.
|
126
|
-
fields.first.values.length.
|
127
|
-
fields.first.values.first.roles.
|
126
|
+
expect(fields.length).to eq(1)
|
127
|
+
expect(fields.first.values.length).to eq(1)
|
128
|
+
expect(fields.first.values.first.roles).to eq(['Depicted'])
|
128
129
|
end
|
129
|
-
it
|
130
|
+
it 'should comma seperate multiple roles' do
|
130
131
|
fields = mods_display_name(@multiple_roles).fields
|
131
|
-
fields.length.
|
132
|
-
fields.first.values.length.
|
133
|
-
fields.first.values.first.to_s.
|
132
|
+
expect(fields.length).to eq(1)
|
133
|
+
expect(fields.first.values.length).to eq(1)
|
134
|
+
expect(fields.first.values.first.to_s).to eq('John Doe (Depicted, Artist)')
|
134
135
|
end
|
135
136
|
end
|
136
137
|
end
|
137
|
-
|
138
|
-
describe
|
139
|
-
it
|
138
|
+
|
139
|
+
describe 'to_html' do
|
140
|
+
it 'should add the role to the name in parens' do
|
140
141
|
html = mods_display_name(@name_with_role).to_html
|
141
|
-
html.
|
142
|
+
expect(html).to match(%r{<dd>John Doe \(Depicted\)</dd>})
|
142
143
|
end
|
143
|
-
it
|
144
|
+
it 'should linke the name and not the role if requested' do
|
144
145
|
html = mods_display_name_link(@name_with_role).to_html
|
145
|
-
html.
|
146
|
+
expect(html).to match(%r{<dd><a href='.*\?John Doe'>John Doe</a> \(Depicted\)</dd>})
|
146
147
|
end
|
147
148
|
end
|
148
|
-
|
149
|
-
end
|
149
|
+
end
|
data/spec/fields/note_spec.rb
CHANGED
@@ -1,59 +1,72 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_note(mods_record)
|
4
|
-
ModsDisplay::Note.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Note.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Note do
|
8
8
|
before(:all) do
|
9
|
-
@note = Stanford::Mods::Record.new.from_str(
|
10
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
|
9
|
+
@note = Stanford::Mods::Record.new.from_str('<mods><note>Note Field</note></mods>', false).note
|
10
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
11
|
+
"<mods><note displayLabel='Special Label'>Note Field</note></mods>", false
|
12
|
+
).note
|
13
|
+
@sor_label = Stanford::Mods::Record.new.from_str(
|
14
|
+
"<mods><note type='statement of responsibility'>Note Field</note></mods>", false
|
15
|
+
).note
|
16
|
+
@contact_note = Stanford::Mods::Record.new.from_str(
|
17
|
+
"<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false
|
18
|
+
).note
|
19
|
+
@type_label = Stanford::Mods::Record.new.from_str(
|
20
|
+
"<mods><note type='some other Type'>Note Field</note></mods>", false
|
21
|
+
).note
|
22
|
+
@complex_label = Stanford::Mods::Record.new.from_str(
|
23
|
+
"<mods>
|
24
|
+
<note>Note Field</note><note>2nd Note Field</note>
|
25
|
+
<note type='statement of responsibility'>SoR</note>
|
26
|
+
<note>Another Note</note>
|
27
|
+
</mods>", false
|
28
|
+
).note
|
15
29
|
end
|
16
|
-
describe
|
17
|
-
it
|
18
|
-
mods_display_note(@note).fields.first.label.
|
30
|
+
describe 'label' do
|
31
|
+
it 'should have a default label' do
|
32
|
+
expect(mods_display_note(@note).fields.first.label).to eq('Note:')
|
19
33
|
end
|
20
|
-
it
|
21
|
-
mods_display_note(@display_label).fields.first.label.
|
34
|
+
it 'should use the displayLabel attribute when one is available' do
|
35
|
+
expect(mods_display_note(@display_label).fields.first.label).to eq('Special Label:')
|
22
36
|
end
|
23
|
-
it
|
24
|
-
mods_display_note(@sor_label).fields.first.label.
|
37
|
+
it 'should use get a label from a list of translations' do
|
38
|
+
expect(mods_display_note(@sor_label).fields.first.label).to eq('Statement of responsibility:')
|
25
39
|
end
|
26
|
-
it
|
27
|
-
mods_display_note(@type_label).fields.first.label.
|
40
|
+
it 'should use use the capitalized type attribute if one is present' do
|
41
|
+
expect(mods_display_note(@type_label).fields.first.label).to eq('Some other type:')
|
28
42
|
end
|
29
43
|
end
|
30
|
-
|
31
|
-
describe
|
32
|
-
it
|
44
|
+
|
45
|
+
describe 'fields' do
|
46
|
+
it 'should handle single values' do
|
33
47
|
fields = mods_display_note(@note).fields
|
34
|
-
fields.length.
|
35
|
-
fields.first.values.
|
48
|
+
expect(fields.length).to eq(1)
|
49
|
+
expect(fields.first.values).to eq(['Note Field'])
|
36
50
|
end
|
37
|
-
it
|
51
|
+
it 'should handle complex grouping' do
|
38
52
|
fields = mods_display_note(@complex_label).fields
|
39
|
-
fields.length.
|
40
|
-
fields.first.label.
|
41
|
-
fields.first.values.length
|
42
|
-
fields.first.values.
|
43
|
-
|
44
|
-
fields[1].label
|
45
|
-
fields[1].values.length
|
46
|
-
fields[1].values.
|
47
|
-
|
48
|
-
fields.last.label.
|
49
|
-
fields.last.values.length
|
50
|
-
fields.last.values.
|
53
|
+
expect(fields.length).to eq(3)
|
54
|
+
expect(fields.first.label).to eq('Note:')
|
55
|
+
expect(fields.first.values.length).to eq 2
|
56
|
+
expect(fields.first.values).to eq(['Note Field', '2nd Note Field'])
|
57
|
+
|
58
|
+
expect(fields[1].label).to eq 'Statement of responsibility:'
|
59
|
+
expect(fields[1].values.length).to eq 1
|
60
|
+
expect(fields[1].values).to eq(['SoR'])
|
61
|
+
|
62
|
+
expect(fields.last.label).to eq('Note:')
|
63
|
+
expect(fields.last.values.length).to eq 1
|
64
|
+
expect(fields.last.values).to eq(['Another Note'])
|
51
65
|
end
|
52
|
-
it
|
66
|
+
it 'should not include any contact fields' do
|
53
67
|
fields = mods_display_note(@contact_note).fields
|
54
|
-
fields.length.
|
55
|
-
fields.first.values.
|
68
|
+
expect(fields.length).to eq(1)
|
69
|
+
expect(fields.first.values).to eq(['Note Field'])
|
56
70
|
end
|
57
71
|
end
|
58
|
-
|
59
|
-
end
|
72
|
+
end
|